Skip to content

Instantly share code, notes, and snippets.

@dattasaurabh82
Forked from anonymous/sketch_160216a.pde
Created February 24, 2016 02:39
Show Gist options
  • Save dattasaurabh82/51ff0cce792101a69ceb to your computer and use it in GitHub Desktop.
Save dattasaurabh82/51ff0cce792101a69ceb to your computer and use it in GitHub Desktop.
float t;
float size = 40; //50
boolean makeGIF = true;
void setup(){
//size(540, 540);
size(270,270);
}
void draw(){
background(#00FFCC); // bright green
//background(#331940); // dark purple
for (int i = 0; i < height/size + 1; i++){
oneline(t,0+size*i,1,0+20*i);
oneline(1.5*t,size/4+size*i,1,0+20*i);
oneline(2*t,size/2+size*i,1,0+20*i);
oneline(2.5*t,3.*size/4+size*i,1,0+20*i);
}
// increment time
t++;
t++;
//t++;
//t++;
// save frames for animated gif
if(frameCount <= 320/2 && makeGIF){
TImage frame = new TImage(width,height,RGB,sketchPath("frame_"+nf(frameCount,3)+".png"));
frame.set(0,0,get());
frame.saveThreaded();
}
}
void oneline(float t, float offset, int direction, float phase){
noStroke();
//fill(#0CCA98); // dark green
fill(#331940); // dark purple
// line of moving circles
for (int i = -2; i < width/size+2; i++){
float xloc = size*i - direction*((t+phase)/4)%size;
ellipse(xloc, 0+offset-10.*sin(xloc/10.),
size*direction*(2.+cos(xloc/10.))/3.,
size*direction*(2.+cos(xloc/10.))/3.);
}
fill(#0CCA98); // dark green
//fill(#00FFCC); // bright green
// line of moving circles
for (int i = -2; i < width/size+2; i++){
float xloc = size*i + direction*((t+phase)/4)%size;
ellipse(xloc, 1+offset+10.*cos(xloc/10.),
size*direction*(2.+cos(xloc/10.))/3.,
size*direction*(2.+cos(xloc/10.))/3.);
}
fill(#5E366A); // purple
// line of moving circles
for (int i = -2; i < width/size+2; i++){
float xloc = size*i - direction*((t+phase)/4)%size;
ellipse(xloc, 0+offset-10.*cos(xloc/10.),
size*direction*(2.+cos(xloc/10.))/5.,
size*direction*(2.+cos(xloc/10.))/5.);
}
}
// from http://stackoverflow.com/questions/22124039/exporting-a-gif-from-a-processing-sketch-w-gif-animation-library
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