Learn creative coding writing simple programs

63. Time for our first 3D animation

After many episodes of 2D graphics we find out how to draw things on 3D. It's actually very simple. We call the box() function to draw a 3D cube. We send just one parameter to box() to indicate the size of the box. To place the cube somewhere in the screen we use translate(). It's not the first time we use translate, but it is the first time we use it with three parameters. The third parameter indicates the depth, or how close to you or far away from you is the cube. This third parameter is called Z. If Z is positive, the object is closer to you. Making that value smaller, even negative, will bring the cube away from you.
Using the box() function will not work if you don't change the current renderer. By default, Processing wants to draw only 2D. To switch to 3D mode, you can add a third parameter when you call size, for example size(400, 400, P3D); The P3D part is telling Processing you want to do 3D graphics.
Once you get used to using translate() to move the cube around, try using rotateX(), rotateY() and rotateZ() to make the cube rotate around different axes.

Tags: 3D, software tutorial

Code editor

You can make changes to the code below. Then
Below you can ask and answer questions related to this video. If your question is unrelated to the video, please post it at the Processing Forum as I'm unable to help with all of your programs and still have enough free time to eat and sleep :)
comments powered by Disqus