Learn creative coding writing simple programs

59. A space-triangle flying through the galaxy

Some quick enhancements to our previous moving star-field. We make the slow stars smaller than the fast stars. We let the star speed define also the star size. We do that by using the speed to set the strokeWeight(). Since the speed is a number between 1 and 5, that value is compatible with the strokeWeight(). We also make slow stars darker than fast stars. But the color values are not so compatible with the speed. The speed is a number between 1 and 5, but the colors are usually numbers between 0 and 255. So we decide to use map() to convert the 1 to 5 range into a 100 to 255 range. Stars moving 1 pixel per frame will get a gray shade of 100. Stars moving 5 pixels per frame will get a bright white color. Stars moving at speeds between 1 and 5 will get also different shades of gray.
Then we draw a triangle that represents a small space ship. We draw this triangle wherever the mouse pointer is, so we can control the position by moving the mouse. We then call the noCursor() function to hide the mouse pointer, which didn't look so good on top of our "space triangle".

Tags: space, animation, animate, ship, triangle, nocursor, track, mouse

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); } ```