# Time Based Modelling - Jumping Ball

## Introduction

LEVEL: MASTER
Expected Time: 30 min
An animated ball (if not animated, click on image)

Designers occasionally use animation to visualize their designs. Although Rhino in combination with Grasshopper is not developed for making animations, there are some workarounds to give your parametric design some movement. In this tutorial we will explain the principle of making time based animations in Grasshopper. Before starting this tutorial, it is important to note some limitations:

• Grasshopper uses a timer component based on the internal clock of your operating system. In the case of Windows the minimum interval is 1 ms. Therefore, the trigger component in Grasshopper cannot step shorter than 1 ms.
• Grasshopper is NOT intended to use for complex animations. Please use software like Blender, Houdini or Maya to make efficient animations.
• Animations in Grasshopper are slow, sometimes very slow, if you compare them to other software. Use it only fitting circumstances.
• In many cases, the use of the recorder component in Grasshopper is required. This component can be highly memory based. Your laptop/PC may therefore not be able to animate great amounts of data.

In this tutorial, we will explain the basics of animation in Grasshopper. To illustrate the possibilities, we will create a jumping ball.

## Animating a jumping ball

Create a mesh sphere

First, we need to create the object we want to move. If you have followed the tutorials of the TOIpedia, you may have noted we do not use meshes most of the time, because can be hard to model. For animation however, it is better to use meshes, because they can be displayed using the Graphics Card of your computer.

• Create a mesh sphere Mesh » Primitive » Mesh Sphere
• Define the radius with a Number slider Params » Input » Number Slider
• Divide the radius by two Maths » Operators » Division
• Create a point as base for the sphere on half the height of the radius Vector » Point » Construct Point

Create a trigger

Now we need to create the stepper for our script. This can be done in several ways. For most of the options you will need a plugin for you Grasshopper. In the following case this is not necessary:

• Create a Number parameter Params » Parameter » Number
• Set a value of 1 to the parameter RMB on Number parameter » Set Number » Type 1
• Connect a trigger component to the Number parameter Params » Util » Trigger

Set the trigger interval

If you now click on play, the data inside the parameter will update at an interval you defined. To change the interval, right click on the trigger component.

• Change the interval to 100 ms RMB on trigger » Interval » 100 ms

Record the iterations

Next, we record the data of the number parameter using the Data Recorder function. This function can also be useful if you want to save multiple stages of your model using standard parametric design.

• Connect a data recorder to the number parameter Params » Util » Data Recorder

By right-clicking on the Data Recorder you can specify the maximum amount of iterations to store. By clicking on the X sign, you can delete the data.

Count the iterations

Now the Data Recorder will add the value 1 to it’s internal stage every 100ms. However, this is not what we want. By connecting a List Length to the output of the Data Recorder, we can track how many iterations we did. Therefore we have a fully working counter.

• Connect a List Length to the output of the Data Recorder Sets » List » List Length

Click on play

Shortly click on play on the trigger to get an output for the List Length. After you got an output, turn the trigger off. We don’t want the trigger on while we are building the script.

Click on play

In the following part of this tutorial we will make the sphere move fluently up and down. First connect a move node to the mesh sphere output.

• Connect a Move component to the Mesh sphere output Transform » Euclidian » Move

Calculate the modulus of the List Length

Since we don’t want to move the sphere up infinitely, we have to limit the counter. We can do that by calculating the modulus of the List Length output. Simply said, the modulus calculates the remainder of a division. By connecting a Number Slider to the B input, you can define the maximum height of the jump.

• Connect the List Length output to the A input of a modulus function Maths » Operators » Modulus
• Define the max height with a Number Slider into the B input of the modulus Params » Input » Number Slider

Remap the values to a range of 0 to 1

If would now connect this to the Move component with a Z-vector, the sphere would just jump up. We want it to go up and down, and do this smoothly. Therefore we have to remap the value.

• Remap the modulus output to a range 0 to 1 Maths » Domain » Remap Numbers
• Use the Number Slider for the height as input for the Source range

Remap the values according to a Graph

Now we use a Graph mapper to change the values of the remap node output. By using a inverted parabola type, we make sure the ball goes up and down smoothly.

• Connect the Remap Numbers output to a Graph mapper Params » Input » Graph Mapper
• Set the type to parabola RMB on Graph Mapper » Graph types » Parabola
• Change the position of the parabola top upwards

Multiply the output with the maximum height

Now we multiply the Graph mapper output by the height of maximum height Number Slider.

• Multiply the Graph Mapper output by the height Maths » Operators » Multiplication

Convert the values to a Unit Z vector

As final step, we need to convert the value to a z-vector. By using the Unit Z node, we can define the direction and length the ball has to move to.

• Convert the value to a Unit Z vector Vector » Vector » Unit Z

Connnect the vector to the Motion input and click on Play

Now connect the Unit Z vector output to the Motion input of the Move component. If you now click on play on the trigger (make sure you set the preview off for all nodes except the move component), you will see the sphere moving in your Rhino viewport.

• Connect the Unit Z to the motion input of the Move component
• Click on play on the trigger
• By setting the trigger to a lower interval, you can make the animation smoother RMB on trigger » Interval

Generate a rendered view with the Custom Preview component

By adding a custom preview at the end of the script and adding a color, you can see a rendered version in your rendered viewport.

• Connect a Custom Preview to the Move component output Display » Preview » Custom Preview
• Define a color using a Colour Swatch Params » Input » Colour Swatch

The final script

## Export the Animation

Replace the counter nodes with a Number Slider

Unfortunately it is not possible to just export the animation as you see it in the Rhino viewport. However, there are some work-arounds. Replace the trigger part of the script by a Number Slider. This means: everything from the trigger component to the List Length component.

• Replace the trigger part of the script with a Number Slider Params » Input » Number Slider
• Set the Number Slider range to the amount of frames you want to create RMB on Number Slider » Edit

Animate the Number Slider

Right-click on the Number Slider and click on animate. Here you can setup the frame resolution and location to store the frames. If you now click on OK, Rhino will calculate all the frames as individual images. If you want a transparent background, make sure you change the file type to PNG. Using other software like Photoshop or Premiere Pro, you can combine all the frames to a video.

• Right-click on the Number Slider and click Animate... RMB on Number Slider » Animate...
• Set the resolution and location to store the frames
• Change the file type to PNG if you use a transparent background
• Click on OK
• Combine the frames to a video in software like Photoshop or Premiere Pro