# # This demo also shows an example of some of the physical simulation # features of breve. It features a ball rolling down a set of stairs # over and over, changing the starting conditions each time. # @use Mobile. @use PhysicalControl. @use Stationary. Controller Gravity. PhysicalControl : Gravity { + variables: theBall (object). theSquare (object). + to init: # This demo is actually so fast that we're going to intentionally # slow it down by setting the integration step to be very very small. # This will also increase the accuracy of the simulation. self set-integration-step to .00005. # create a bunch of steps. new Step create at (-.5, 0, 0) size (1.0, .22, 1). new Step create at (.2, -.2, 0) size (.2, .22, 1). new Step create at (.4, -.4, 0) size (.2, .22, 1.5). new Step create at (.6, -.6, 0) size (.2, .22, 2). new Step create at (.8, -.8, 0) size (.2, .22, 2.5). new Step create at (1.0, -1.0, 0) size (.2, .22, 5). new Step create at (2.0, -1.2, 0) size (2, .22, 5). new Step create at (3.0, -1.2, 0) size (.2, .4, 5). new Step create at (1.5, -1.2, 2.5) size (3, .5, .1). # and some balls. 8 new Balls. 3 new Squares. self point-camera at (1.0, -.8, -.6) from (3.5, 1.1, 5.0). # self enable-shadow-volumes. self add-menu named "Reset Ball" for-method "reset-ball". + to reset-ball: theBall reset. theSquare reset. } Stationary : Step { + to create at location (vector) size sizeVector (vector): stepShape (object). stepShape = (new Cube init-with size sizeVector). # self set-e to 0.01. # self set-mu to 999999999. self set-shape to stepShape. self move to location. } Mobile : Ball (aka Balls) { + to iterate: # The iterate method is called each timestep... # if the Y component (height) of our position is less than -2.0, # then the ball has passed the steps and is continuing to fall, # so we'll reset the ball with new starting conditions. if (self get-location)::y < -2.0: self reset. + to init: self set-shape to (new Sphere init-with radius .05 + random[ .01 ] ). self enable-physics. self reset. + to reset: # vary initial conditions slightly each time self set-color to random[(1, 1, 1)]. self move to ( -.9, .5, -1 ) + random[ ( .5, .1, 4) ]. self set-velocity to (1 + random[4.0], 1.0 + random[1.0], 1). } Mobile : Square (aka Squares) { + to iterate: tx (int). tx = 0. # The iterate method is called each timestep... # if the Y component (height) of our position is less than -2.0, # then the Cube has passed the steps and is continuing to fall, # so we'll reset the cube with new starting conditions. if (self get-location)::y < -2.0: self reset. # if (abs((self get-velocity)::x) < 0.0001): self reset. + to init: # self set-shape to (new Cube init-with size (.05, .05, .05)). self set-shape to (new PolygonCone init-with sides 5 height .128 radius .238). self enable-physics. self reset. + to reset: # vary initial conditions slightly each time self set-color to random[(1, 1, 1)]. self move to ( -.9, .5, -1 ) + random[ ( .5, .1, 4) ]. self set-velocity to (1 + random[1.0], 1.0 + random[.5], .3). }