to aaa
; This example truely covers the surface of a sphere with each
; vertex of each polygon exactly on the surface with no overlaping
; polygons and letting logo do all the trig involved.
;
; Place yourself in the center of a sphere and imagine you have
; a laser gun that can cut or mark the surface. Now you basically
; Shoot a dot on the surface (call that point A), then move your
; aim 5 degrees (:step) down, shoot another dot (call that point B).
; Now aim 5 degrees to the right, Shoot another dot (call that point
C).
; Now aim 5 degrees up, shoot another dot. Now connect the 4 dots
; with a string and you have your polygon. Get the idea.
;
; This example did not run quite right on the beta (you'll see a few
; errors). The reason is the top and bottom of each slices' polygon
; is a triangle but we still shot 4 dots to produce it. That means
; 2 dots hit the same target (this is when we are shooting at the
poles
; of the sphere). I added smarts to the mswlogo to eliminate
sequential
; duplicate vertices (with in the first 3 vertices).
;
; The first 3 vertices are critical to MSWLogo because they are used
; to calculate the orientation of the polygon.
;
; Polygon restrictions:
;
; 1: A polygons first 3 vertices must form a triangle.
; 2: A polygon must be convex.
; 3: A polygon must be planar (no up,down,rr,lr between)
; polystart/polyend.
;
; All these properties occur very naturally in Logo.
;
; Notes on 1: the triangle can be extremely shallow
;
; This is legal
;
; polystart
; make "savepos posxyz
; fd 100
; rt 0.00000001
; fd 100
; setpos :saveposxyz
; polyend
; This is legal
;
; This is NOT legal (even though it produces a convex polygon)
;
; polystart
; make "savepos posxyz
; fd 50
; fd 50
; rt 90
; fd 100
; setpos :saveposxyz
; polyend
;
; I could make MSWLogo smart enough to hangle that last case
; but in general it occurs very infrequently and you'll pay
; a performance price for it.
;
; This is legal
;
; polystart
; make "savepos posxyz
; fd 100
; rt 90
; fd 100
; rt 90
; fd 50
; fd 50
; setpos :saveposxyz
; polyend
;
; It's only the first 3 vertices that are critical
;
; Notes on 2: What does convex mean
;
; Pick any 2 coordinate within the poly and connect
; them with a line. If that line can go outside the
; polygon then it's not convex.
;
; Triangles, Squares, Circles etc. are convex.
; The letter "E" as a polygon is not convex.
;
; This is legal
;
; repeat 4 [fd 100 rt 90]
;
; This is NOT legal
;
; repeat 4 [fd 50 rt 90 repeat 3 [fd 25 lt 90] rt 180 fd 50 rt 90]
;
; Notes on 3: What does planar mean
;
; The polygon must be flat
;
; This is legal
;
; repeat 4 [fd 100 rt 90]
;
; This is NOT legal
;
; repeat 4 [fd 50 rr 90 rt 90 repeat 3 [fd 25 lt 90] rt 180 lr 90 fd
50 rt 90]
;
; Notes on 2 and 3:
;
; You can fix all the illegal cases I mentioned by breaking
; the object up into simpler polygons that meet the rules.
;
perspective
cs
setsc [0 0 0]
clearpalette
ask -3 [setxyz 207 243 97]
ht
pu
; Time drawing
localmake "start timemilli
; This is the color of the OBJECT not the color you'll see
; This example had too many colors for gif to give it justice
; Remember 1 blue ([0 0 128]) object may generate 100's of shades
; of blue. This example looks fine 16bit or 24bit color.
; repeat 6 [fd 100 Sphere 50 10 item repcount [[128 0 0] [0 128 0] [0
0 128] [128 128 0] [0 128 128] [128 0 128]] bk 100 rt 360/6]
; This example looks fine in 8bit color (which gifs inherintly are)
; because they are all blue spheres
repeat 6 [fd 100 Sphere 50 10 [0 0 128] bk 100 rt 360/6]
; Display elapsed drawing
(print "Define (timemilli - :start) / 1000)
; Time shading
make "start timemilli
polyview
; Display elapsed shading
(print "Render (timemilli - :start) / 1000)
stop
repeat 100 [ask -3 [setxyz random 300 random 300 random 300 show
posxyz]]
pd
end
to GetPoint :rad
fd :rad
localmake "pos posxyz
bk :rad
output :pos
end
to Slice :rad :step
; Draw an "orange" slice (just the outside surface)
up 90
localmake "i 0
repeat 360/:step ~
[
down :i
localmake "PointA GetPoint :rad
down :step
localmake "PointB GetPoint :rad
up :step
up :i
rt :step
down :i
localmake "PointD GetPoint :rad
down :step
localmake "PointC GetPoint :rad
up :step
up :i
lt :step
localmake "PointE posxyz
setposxyz :PointA
pd
polystart
setposxyz :PointB
setposxyz :PointC
setposxyz :PointD
setposxyz :PointA
polyend
pu
setposxyz :PointE
make "i :i + :step
]
down 90
end
to Sphere :rad :step :color
setpc :color
; Cover the surface of the sphere with polygons
repeat 180/:step [Slice :rad :step rr :step]
rr 180
end
--
===============================================================
George Mills (mills@softronix.com)
http://www.softronix.com/
The www page contains some very powerful educational software.
Our single most important investment is our kids.
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