Learn creative coding writing simple programs

70. Slowly change the direction

We can use an angle to define in which direction we are moving an object. If we slowly change that angle, we smoothly change the direction too. In this episode we create a program that draws a line. The line is born at the center of the screen and moves toward a random initial direction. This direction slowly changes randomly. Sometimes it will be a quite straight line, other times it might turn around and go back where it was coming from. We achieve this by using sin() and cos() to calculate what is the next position according to the current position and the current direction.

Tags: direction, angle, sin, cos, Sine

Code editor

You can make changes to the code below. Then

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
Do `float` and `int` smell similar?
To highlight code blocks, surround it with ``` code-fences ``` like this:
``` void setup() { size(600, 600); } ```