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
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