Bouncing Balls Example 3D

Bouncing Balls Example 3D preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

code example 

Tagged by Reuven M. Lerner almost 12 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 3D 4.1pre7 • Viewed 867 times • Downloaded 63 times • Run 0 times
Download the 'Bouncing Balls Example 3D' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

This is an example that displays many of the capabilities of NetLogo 3D.

HOW TO USE IT

The SETUP button creates BALL-COUNT balls poised above the "floor" of the world. GO releases the balls and "gravity" pulls them down. The balls will bounce until they lose momentum. If the COLOR-SPEED? switch is on the color of the ball will be scaled the speed it is moving. If the TAILS? switch is on the balls will leave a trace of the path they have taken.

Comments and Questions

Click to Run Model

breed [ balls ball ]

balls-own [ z-vel x-vel y-vel ]
turtles-own [ col ]

to setup
  ca
  ask patches with [ pzcor = -7 ]
    [ set pcolor random-float 2 + 35 ]
  set-default-shape turtles "circle"
  create-balls ball-count
  [
    set zcor 5
    set z-vel random-float 2 - 1
    set x-vel random-float 2 - 1
    set y-vel random-float 2 - 1
    set col color
    if tails?
    [ pd ]
  ]
end 

to go
  ask balls
  [
    let x xcor
    let y ycor
    let z zcor

    let speed sqrt( x-vel * x-vel + y-vel * y-vel + z-vel * z-vel )
    ifelse tails?
    [ pd ]
    [ pu ]

    set z-vel z-vel + -0.05
    ifelse (( z-vel > 0 ) and (( zcor + z-vel ) > 9 )) or
           (( z-vel < 0 ) and (( zcor + z-vel ) < -6 ))
    [ set z-vel z-vel * -0.8
      set y-vel y-vel * 0.95
      set x-vel x-vel * 0.95 ]
    [ set z zcor + z-vel ]

    ifelse (( x-vel > 0 ) and (( xcor + x-vel ) > 9 )) or
           (( x-vel < 0 ) and (( xcor + x-vel ) < -9 ))
    [ set x-vel x-vel * -0.8
      set y-vel y-vel * 0.95
      set z-vel z-vel * 0.95 ]
    [ set x xcor + x-vel ]

    ifelse (( y-vel > 0 ) and (( ycor + y-vel ) > 9 )) or
           (( y-vel < 0 ) and (( ycor + y-vel ) < -9 ))
    [ set y-vel y-vel * -0.8
      set x-vel x-vel * 0.95
      set z-vel z-vel * 0.95 ]
    [ set y ycor + y-vel ]

    setxyz x y z

    if color-speed?
      [ set color scale-color col speed -.5 1.5 ]
  ]
  tick
end 


; Copyright 2005 Uri Wilensky. This code may be freely copied, distributed,
; altered, or otherwise used by anyone for any legal purpose.

There are 3 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Bouncing Balls Example 3D Download this version

Attached files

File Type Description Last updated
Bouncing Balls Example 3D.png preview Preview for 'Bouncing Balls Example 3D' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.