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
Author
faster, cooler way of saving frames
// in draw method:
if (frameCount <= numFrames && recording) {
TImage frame = new TImage(width,height,RGB,sketchPath("frames/frame_"+nf(frameCount,3)+".png"));
frame.set(0,0,get());
frame.saveThreaded();
println(frameCount,"/",numFrames);
}
// outside
class TImage extends PImage implements Runnable{//separate thread for saving images
String filename;
TImage(int w,int h,int format,String filename){
this.filename = filename;
init(w,h,format);
}
public void saveThreaded(){
new Thread(this).start();
}
public void run(){
this.save(filename);
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
frames was used for saving a number of frames to the root folder, so you can create a nice GIF out of it.
// Create animation
frames++;
if (frames > 100) {
noLoop();
} else {
saveFrame("line-######.tif");
}