/* draw angle tick-marks around a square */ s : float(%pi/180)$ /* 1 degree as radians */ tanTable : makelist(tan(s*h), h, 0, 45)$ /* 0..45 */ s : 50$ /* half-length of square */ lx : makelist(s - 6 + signum(remainder(h, 10))*2 + signum(remainder(h, 5))*2, h, 0, 45)$ pB : makelist([lx[h], lx[h]*tanTable[h]], h, length(lx))$ /* [x, y] */ pE : makelist([s, s*h], h, tanTable)$ /* also 46 elements */ len : length(pB) - 1$ pB : append(pB, makelist(reverse(pB[h]), h, len, 1, -1))$ /* 45 degrees */ pE : append(pE, makelist(reverse(pE[h]), h, len, 1, -1))$ /* 46..90 */ /* define symbols which accept numbers only */ matchdeclare([xxxx, yyyy], atom)$ /* make rules transposing co-ordinates */ defrule(r1, [xxxx, yyyy], [-yyyy, xxxx])$ /* rotate 90 degrees */ defrule(r2, [xxxx, yyyy], [-xxxx, -yyyy])$ /* rotate 180 degrees */ /* create a tick for other points of the square */ len : length(pB)$ pB : append(pB, makelist(r1(pB[h]), h, 2, len))$ /* 90..180 */ pE : append(pE, makelist(r1(pE[h]), h, 2, len))$ len : length(pB) - 1$ pB : append(pB, makelist(r2(pB[h]), h, 2, len))$ /* 180..359 */ pE : append(pE, makelist(r2(pE[h]), h, 2, len))$ /* write angle value for largest tick-marks */ cT : makelist([s - 9, (s - 9)*tanTable[h]], h, 1, 46, 10)$ /* 0,10..30,40 */ len : length(cT)$ cT : append(cT, makelist(reverse(cT[h]), h, len, 1, -1))$ /* 50,60,70,80 */ len : length(cT)$ cT : append(cT, makelist(r1(cT[h]), h, 2, len))$ /* 90 degrees */ len : length(cT) - 1$ cT : append(cT, makelist(r2(cT[h]), h, 2, len))$ /* 180 degrees */ kill(xxxx, yyyy)$ /* not needed */ load('draw)$ draw2d(dimensions=[s*2.2, s*2.2], background_color = black, points_joined = true, point_type = dot, color = green, map(points, makelist([pB[h], pE[h]], h, length(pB))), points_joined = false, point_type = filled_circle, color = grey, point_size = 3, points([[0, 0]]), /* centre of square */ color = blue, map(label, makelist([printf(false, "~d", (h - 1) * 10), cT[h][1], cT[h][2]], h, length(cT))) );