Skip to content

Instantly share code, notes, and snippets.

@LouisStAmour
Created October 18, 2016 04:41
Show Gist options
  • Save LouisStAmour/267f3cc2b8bc2120875a70097578f89d to your computer and use it in GitHub Desktop.
Save LouisStAmour/267f3cc2b8bc2120875a70097578f89d to your computer and use it in GitHub Desktop.
"neat little something" in Processing for DATT 1100
void setup() {
size(480, 480, P2D);
noStroke();
}
long i = 0;
float x = random(width);
float y = random(height);
long duration = 10;
float prevX = width/2;
float prevY = height/2;
float distance = getDistance();
float getDistance() {
return sqrt(pow(prevX-x, 2) + pow(prevY-y, 2));
}
void draw() {
float relativePointInTime = 1.0*i/duration;
fill(relativePointInTime*255);
float currentX = relativePointInTime*x + (1-relativePointInTime)*prevX;
float currentY = relativePointInTime*y + (1-relativePointInTime)*prevY;
ellipse(currentX, currentY, 80, 80);
if(i < duration) {
i++;
} else {
i = 0;
prevX = x;
prevY = y;
x = random(width);
y = random(height);
distance = getDistance();
}
}
import com.hamoid.*;
// Download and install from http://funprogramming.org/VideoExport-for-Processing/
VideoExport videoExport;
void setup() {
size(480, 480, P2D);
noStroke();
videoExport = new VideoExport(this, "internetVideo.mp4");
// The standard frame rate for internet videos is about
// 30 frames per second
videoExport.setFrameRate(30);
// By default Processing tries to play at 60 frames
// per second. That means that your exported videos
// may feel slow, as they are played at half the
// speed of the original. You may want to play your
// sketch at 30 fps too, so the sketch and the video
// run at similar frame rates. To compensate for the
// lower frame rate you may have to adjust your sketch
// to make your objects move faster.
frameRate(30);
}
long i = 0;
float x = random(width);
float y = random(height);
long duration = 10;
float prevX = width/2;
float prevY = height/2;
float distance = getDistance();
float getDistance() {
return sqrt(pow(prevX-x, 2) + pow(prevY-y, 2));
}
void draw() {
float relativePointInTime = 1.0*i/duration;
fill(relativePointInTime*255);
float currentX = relativePointInTime*x + (1-relativePointInTime)*prevX;
float currentY = relativePointInTime*y + (1-relativePointInTime)*prevY;
ellipse(currentX, currentY, 80, 80);
videoExport.saveFrame();
if(i < duration) {
i++;
} else {
i = 0;
prevX = x;
prevY = y;
x = random(width);
y = random(height);
distance = getDistance();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment