Created
January 11, 2018 23:35
-
-
Save felipecustodio/5df23eb25d960e78488532f2479a4321 to your computer and use it in GitHub Desktop.
Simple trail in Processing 3 (Java)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| float posX, posY; | |
| float radiusX, radiusY; | |
| float theta; | |
| int frames = 0; | |
| PVector position; | |
| ArrayList<PVector> trail; | |
| int trailSize = 50; | |
| int trailLength; | |
| void setup() { | |
| size(1024, 768); | |
| frameRate(60); | |
| posX = 150; | |
| posY = 0; | |
| radiusX = 100; | |
| radiusY = 100; | |
| theta = 0; | |
| trail = new ArrayList<PVector>(); | |
| } | |
| void draw() { | |
| background(0); | |
| translate(width/2, height/2); | |
| theta += 0.1; | |
| posX = radiusX * cos( theta ); | |
| posY = radiusY * sin( theta ); | |
| position = new PVector(posX, posY); | |
| trail.add(position); | |
| trailLength = trail.size() - 2; | |
| stroke(#F6F6F6); | |
| fill(#F6F6F6); | |
| ellipse(0,0,100,100); | |
| for (int i = 0; i < trailLength; i++) { | |
| PVector currentTrail = trail.get(i); | |
| PVector previousTrail = trail.get(i + 1); | |
| stroke(#EE2B47, 255 * i / trailLength); | |
| line( | |
| currentTrail.x, currentTrail.y, | |
| previousTrail.x, previousTrail.y | |
| ); | |
| } | |
| stroke(#EE2B47); | |
| fill(#EE2B47); | |
| ellipse(position.x, position.y, 10, 10); | |
| if (trailLength >= trailSize) { | |
| trail.remove(0); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
faster, cooler way of saving frames