Shape Animation Example
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This code example shows how to use shapes to create animations. In this example, there is a walking person and growing flowers.
HOW IT WORKS
A counter is used to increment the shape to be used in each animation.
For the person, each progressive frame of the person walking has a different shape. There are 9 shapes total. Each progressive shape is numbered as person#, where the # is one higher then the shape that came before. After final numbered shape (person9), the shapes repeat from the start (person_1) and continue to cycle through the remaining shapes. The person is moved forward a small bit with each new shape, to give the illusion of walking.
For the flowers, each progressive frame of their growth shows the development of the flower from a small seedling to a fully grown flower. Each frame has a new shape. Each progressive shape is numbered as flower#, where the # is one higher then the shape that came before. After final numbered shape (flower16), the shapes stop incrementing and the flower is shown as fully grown.
NETLOGO FEATURES
The model has a frame rate setting of 15 frames per second, for smooth animation that isn't too fast. The speed can be further adjusted by the user using the speed slider.
Comments and Questions
breed [ flowers flower ] breed [ people person ] ;; putting people last ensures people appear ;; in front of flowers in the view people-own [frame] ;; ranges from 1 to 9 flowers-own [age] ;; ranges from 1 to 16 ;; ;; SETUP PROCEDURES ;; to setup ;; executed when we press the SETUP button clear-all ;; clear all patches and turtles create-people 1 [ set heading 90 ;; i.e. to the right set frame 1 set shape "person-1" ] reset-ticks end ;; ;; GO PROCEDURES ;; to go animate tick end to animate move-person ask flowers [ age-flower ] if random 100 < 20 [ make-flower ] end to move-person ask people [ set shape (word "person-" frame) forward 1 / 20 ;; The shapes editor has a grid divided into 20 squares, which when ;; drawing made for useful points to reference the leg and shoe, to ;; make it look like the foot would be moving one square backward ;; when in contact with the ground (relative to the person), but ;; with a relative velocity of 0, when moving forward 1/20th of ;; a patch each frame set frame frame + 1 if frame > 9 [ set frame 1 ] ;; go back to beginning of cycle of animation frames ] end to age-flower ;; flower procedure set age (age + 1) ;; age is used to keep track of how old the flower is ;; each older plant is a little bit taller with a little bit ;; larger leaves and flower. if (age >= 16) [ set age 16 ] ;; we only have 16 frames of animation, so stop age at 16 set shape (word "flower-" age) end to make-flower ;; if every patch has a flower on it, then kill all of them off ;; and start over if all? patches [any? flowers-here] [ ask flowers [ die ] ] ;; now that we're sure we have room, actually make a new flower ask one-of patches with [not any? flowers-here] [ sprout 1 [ set breed flowers set shape "flower-1" set age 0 set color one-of [magenta sky yellow] ] ] end ; Public Domain: ; To the extent possible under law, Uri Wilensky has waived all ; copyright and related or neighboring rights to this model.
There are 10 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Shape Animation Example.png | preview | Preview for 'Shape Animation Example' | over 12 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.