Daniel Vu

23 Jan 2014

animation

I ended up rushing this. I had hoped to tweak it a little bit more to make it smoother. Started off with just a squiggle I made up in my sketchbook with the idea that I would use multiple smaller circles to create the design. Programming/code and math not being my forte, I took longer than I should have to figure out how to get the movement the way I wanted.

Negative things I can point out are: not as smooth as I wanted, not a perfect loop, does not end in a complete circle. Positive things: I think the flower-like pattern it creates is nice, the sizing seems to be fine, the offset where it is not symmetrical if split vertically/horizontally without rotating it is kind of cool.

sketch

// This is a template for creating a looping animation in Processing.
// When you press a key, this program will export a series of images
// into an "output" directory located in its sketch folder.
// These can then be combined into an animated GIF.
// Prof. Golan Levin, January 2014 - CMU IACD
// modified by Daniel Vu

int canvas_width = 500;
int canvas_height = 500;
int nFramesInLoop = 30; //change to 10 for lenticular
int nElapsedFrames;
boolean bRecording;

String myName = "danielvu";

void setup(){
size(canvas_width, canvas_height);
nElapsedFrames = 0;
frameRate (nFramesInLoop);
bRecording = false;
}

void keyPressed(){
//press a key to export to the output folder
bRecording = true;
nElapsedFrames = 0;
}

void draw(){
float percentCompleteFraction = 0; //Compute a percentage (0 to 1) representing the current point in the loop
if (bRecording) {
percentCompleteFraction = (float) nElapsedFrames / (float) nFramesInLoop;
}
else {
float modFrame = (float) (frameCount % nFramesInLoop);
percentCompleteFraction = modFrame / (float) nFramesInLoop;
}

render(percentCompleteFraction);

if(bRecording) {
saveFrame("output/" + myName + "-loop-" + nf(nElapsedFrames, 4) + ".png");
nElapsedFrames++;
if (nElapsedFrames == nFramesInLoop){
bRecording = false;
  }
 }
}

void render (float percent){
background(100);
smooth();
noStroke();

fill(0,0,0);
ellipse(canvas_width/2, canvas_height/2, 100, 100);

float cx = canvas_width/2;
float cy = canvas_height/2;
float offset = 50;

for(int i = 0; i < 5; i++){
float offset1 = -(offset/percent);
float angle = (TWO_PI/5) * i;
float px = cx + offset1*cos(angle);
float py = cy + offset1*sin(angle);
ellipse (px, py, 40, 40);
}

for(int j = 0; j < 5; j++){
float newOffset = (offset - 20)/(percent);
float angle2 = ((TWO_PI/5) * j) + 120;
float px = cx + newOffset*cos(angle2);
float py = cy + newOffset*sin(angle2);
ellipse (px, py, 80, 80);
 }
}