Courses/CS 461/Winter 2006/Joey Leung/Week 1
From CSWiki
< Courses | CS 461 | Winter 2006 | Joey Leung
Contents |
[edit] Model 1 (Modified 3D Surface)
Because I do not know the Netlogo language too well, I am not ready to make a model of my own, so what I did was to Modified the 3D Surface model from the models library. In this model, I redesigned the shape, and I added the display-color slide bar and the speed slide bar.
globals [ time ]
turtles-own [ x-cor y-cor z-cor ]
to setup
ca
set time 0
set-default-shape turtles "circle"
cct number [
;; randomly distribute the turtles over the xy plane
set x-cor random-float 120 - 70
set z-cor random-float 50 - 10
set y-cor 00
move
render
]
end
to go
set time time + speed
ask turtles [
move
render
]
end
to move ; turtle procedure
set y-cor ( 5 * cos ( 5 * ( time + x-cor ) ) )
+ ( 5 * cos ( 5 * ( time + z-cor ) ) )
end
to render ; turtle procedure
; convert 3-space coordinates to screen coordinates
setxy (x-cor + ( z-cor / 2 )) (y-cor + ( z-cor / 2 ))
; make lightness/darkness proportional to height, for added 3D effect
set color scale-color display-color y-cor -12 10
end
[edit] Model 1 (Modified 3D Solids)
In this model, I was trying to create a smaller sphere inside the big sphere and create all the adjusting features of its own. However, I did not get it to work.
turtles-own
[x-pos y-pos z-pos p theta phi temp-alpha temp-beta temp-gamma]
to cartset [x y z]
set p sqrt((x ^ 2) + (y ^ 2) + (z ^ 2))
set phi (atan sqrt((x ^ 2) + (y ^ 2)) z)
set theta (atan y x)
end
to go
ask turtles
[
set theta ((theta + theta-velocity) mod 360)
render-turtle
]
end
breeds [sphere ball]
to setup
ca
create-custom-ball 500
[
set color yellow
set p 20
set theta random-float 360
set phi random-float 180
render-turtle
]
create-custom-sphere num-turtles
[
set p shape-size
set theta random-float 360
set phi random-float 180
render-turtle
]
end
to render-turtle
calculate-turtle-position
set-turtle-position
end
to calculate-turtle-position
set y-pos (p * (sin phi) * (sin theta))
set x-pos (p * (sin phi) * (cos theta))
set z-pos (p * (cos phi))
end
to set-turtle-position
ifelse (view = "side") ; sideview
[setxy x-pos z-pos
set color scale-color display-color y-pos (- shape-size) shape-size
]
[ifelse (view = "top") ; topview
[setxy x-pos y-pos
set color scale-color display-color z-pos (- shape-size) shape-size
]
[setxy (p * (sin phi) * (cos theta)) ; bottomview
(- (p * (sin phi) * (sin theta)))
set color scale-color display-color (- z-pos) (- shape-size) shape-size
]
]
end
[edit] Comments
So far the Netlogo system seems pretty interesting and the language seems easy to understand. The Primitives Dictionary is very helpful in explaining the commands.

