Skip to main content
Commonmark migration
Source Link

#Logo, 199 bytes

Logo, 199 bytes

#Logo, 200 bytes#

Logo, 200 bytes

#Logo, 199 bytes

#Logo, 200 bytes#

Logo, 199 bytes

Logo, 200 bytes

added 1467 characters in body
Source Link
Level River St
  • 26.7k
  • 4
  • 37
  • 105

#Logo, 199 bytes

TO p:d:n:s
rt :n*45 for[i 1 :n/8][pu setxy :d*:i 0 pd repeat 2[for[k 1 :s*2+2][fd 40 rt (360-720*(:k>:s))/:s] rt 720/:s]]END
TO q:j
apply "p item :j [[70 9 3][56 23 4][70 16 3][105 26 5][40 42 3]]END

Reading this back I see my original version did not comply with the spec as written (take a numerical argument and draw one shape) but rather as interpreted by some of the other answers (draw all shapes.) The new version fixes this. It expects to be called as for example q 5. cs should be done before to clear the screen and point the turtle north.

q calls the main function p with 3 arguments. The syntax for this is pretty bloated, so to beat my previous score I had to shave off bytes elsewhere.

the new version of p takes 3 arguments. There is no need for x and y because we only plot one net, but d the pitch between subunits remains. s is still the number of sides per polygon, and n now encodes for two different things> n/8 is the number of subunits to be plotted, and n*45 is an angle through which the turtle must be turned before starting (taking advantage of the natural mod 360 for rotations.)

Improved looping accomplishes drawing s lines with righthand rotation and s+2 lines with lefthand rotation in a single loop.

the calormen interpreter seems to be less tolerant of missing whitespace now than at the time of my first post, but the code runs fine on http://turtleacademy.com/playground/en

#Logo, 200 bytes#

#Logo, 200 bytes#

#Logo, 199 bytes

TO p:d:n:s
rt :n*45 for[i 1 :n/8][pu setxy :d*:i 0 pd repeat 2[for[k 1 :s*2+2][fd 40 rt (360-720*(:k>:s))/:s] rt 720/:s]]END
TO q:j
apply "p item :j [[70 9 3][56 23 4][70 16 3][105 26 5][40 42 3]]END

Reading this back I see my original version did not comply with the spec as written (take a numerical argument and draw one shape) but rather as interpreted by some of the other answers (draw all shapes.) The new version fixes this. It expects to be called as for example q 5. cs should be done before to clear the screen and point the turtle north.

q calls the main function p with 3 arguments. The syntax for this is pretty bloated, so to beat my previous score I had to shave off bytes elsewhere.

the new version of p takes 3 arguments. There is no need for x and y because we only plot one net, but d the pitch between subunits remains. s is still the number of sides per polygon, and n now encodes for two different things> n/8 is the number of subunits to be plotted, and n*45 is an angle through which the turtle must be turned before starting (taking advantage of the natural mod 360 for rotations.)

Improved looping accomplishes drawing s lines with righthand rotation and s+2 lines with lefthand rotation in a single loop.

the calormen interpreter seems to be less tolerant of missing whitespace now than at the time of my first post, but the code runs fine on http://turtleacademy.com/playground/en

#Logo, 200 bytes#

Source Link
Level River St
  • 26.7k
  • 4
  • 37
  • 105

#Logo, 200 bytes#

TO p:x:y:d:n:s
for[i 1:n][pu setxy:x:y-:d*:i if:i<>6[pd]repeat 2[repeat:s[fd 40 rt 360/:s]repeat:s+2[fd 40 lt 360/:s]rt 720/:s]]END
p 0 200 40 7 3
p 70 0 80 2 3
p -200 200 105 3 5
rt 45
p 90 90 56 2 4

Interpreter at http://www.calormen.com/jslogo/# It is assumed the turtle is pointing North before the program is run. Use the cs command to clear the screen, point the turtle north, and place it at the origin in the centre of the screen.

enter image description here

The basic unit of all the above nets is a pair of back to back polygons. These are arranged in 2 staggered rows, making a subunit of 4 polygons which can be translated vertically to make all the nets (except the octahedron, which hitches a ride on the drawing of the icosahedron and tetrahedron). The subunit forms 1 tetrahedron net, 1/5 of the icosahedron net, 1/3 of the dodecahedron net and 2/3 of the cube net (two subunits are drawn, with the middle two squares overlapping.)

Ungolfed code

TO p :x :y :d :n :s                 ;x,y=starting point d=negative vertical offset for each iteration n=#of iterations s=# of sides on polygon
  for[i 1 :n][                      ;iterate n times 
    pu                              ;pen up
    setxy :x :y- :d* :i             ;move pen to start of iteration
    if :i<>6[pd]                    ;pen down (supressed for i=6 to enable part of octahedron to be drawn with icosahedron)
    repeat 2[                       ;draw lower row of 2 polygons, then upper row of 2 polygons
      repeat :s[fd 40 rt 360/ :s]   ;starting at lower left of polygon facing up, draw righthand polygon
      repeat :s+2[fd 40 lt 360/ :s] ;starting at lower right of polygon facing up, draw lefthand polygon, duplicating last two sides
      rt 720/ :s                    ;return turtle to upwards facing in order to draw second row
    ]
  ]
END
cs
p 0 200 40 7 3                      ;draw icosahedron and left side of octahedron (6th iteration is suppressed)
p 70 0 80 2 3                       ;draw right side of octahedron, and tetrahedron
p -200 200 105 3 5                  ;draw dodecahedron
rt 45                               ;turn turtle in preparation for drawing cube
p 90 90 56 2 4                      ;draw cube