[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> RE: Icosahedron



Now that I've sorted the problem with slowdraw I've done a second version 
with better colours and lighting. I've also done a stellated icosahedron 
(see attached gif).

Tom Lynn

to aaa
 ; Draws a icosahedron and a stellated icosahedron.
 ;
 ; Two basic movement primitives are defined.
 ; ne (next edge) moves to the next edge clockwise on the current face.
 ; nr (next-right) moves to the next face to the right.
 ; repeat 5 [nr] returns to the original position.
 ;
 ; The turtle draws five bars of four triangles around the icosahedron.

 ico 150
 wait 100
 spico 150
end

to drawit
 ; Define some constants
 localmake "phi (1 + sqrt 5) / 2
 localmake "beta arcsin (:phi / sqrt 3)
 localmake "alpha 180-2*:beta
  ; 180-angle between unconnected vertices of two hinged faces
 localmake "spikesidelength :size*1
 ; Change factor for different spikiness
 localmake "spikeheight sqrt (:spikesidelength*:spikesidelength-:size*:size/3)
 localmake "spikeupangle arctan (2*(sqrt 3)*:spikeheight/:size)
 localmake "spikepointangle 2*arcsin (:size/(2*:spikesidelength))

 cs
 perspective
 ask -1 [setposxyz [-280 -500 700]]

 localmake "col 7

 setsc [0 0 0] ; Set screen to black
 setlight [0 0.15]
  ; Set ambient and diffuse lighting
 ask -3 [setposxyz [0 -300 500]]
  ; Set lightsource position (arrived at by trial and error)

 ht
 repeat 5 [fourtri]
 polyview
 wait 50

 ; Show sample lighting
 ; repeat 36 [ask -3 [setxyz 200 - random 400 200 - random 400 200 - random
 ; 400 show posxyz] wait 60]

 ; Now fly around
 repeat 72 [ask -1 [fd :size down 5]]

end

to fourtri
 make "col :col + 1
 if :col = 9 [make "col :col + 1] ; Skip two colours
 if :col = 12 [make "col :col + 1]
 setpc :col
 ifelse :stellated=0 [tri tri ne tri tri] [spike spike ne spike spike]
 repeat 2 [nr nr ne]
 nr
end

to ico :size
 localmake "stellated 0
 drawit
end

to ne
 pu fd :size rt 120
end

to nr
 pu rt 60 fd :size lt 120 rr :alpha
end

to spico :size
 localmake "stellated 1
 drawit
end

to spike
 repeat 3 [spikeface]
 nr
end

to spikeface
 pu lt 30 up :spikeupangle rt :spikepointangle/2
 pd polystart
  fd :spikesidelength rt 180-:spikepointangle
  fd :spikesidelength rt 90+:spikepointangle/2
  fd :size rt 90
 polyend
 pu down :spikeupangle rt 30 fd :size rt 120
end

to tri
 pd polystart repeat 3 [fd :size rt 120] polyend
 nr
end
The following section of this message contains a file attachment
prepared for transmission using the Internet MIME message format.
If you are using Pegasus Mail, or any another MIME-compliant system,
you should be able to save it or view it from within your mailer.
If you cannot, please ask your system administrator for assistance.

   ---- File information -----------
     File:  spico.gif
     Date:  22 Jul 1998, 18:03
     Size:  11542 bytes.
     Type:  GIF-image

spico.gif



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home