Eased motion on tiled stage
import processing.core.PApplet; | |
import processing.core.PGraphics; | |
/** | |
* Created by cbrowning on 2/28/16. | |
*/ | |
PGraphics tile; | |
int tileWidth; | |
int tileHeight; | |
float cX, cY; | |
float dX, dY; | |
int destinationCount; | |
Boolean isRecording; | |
public void setup() { | |
size(720, 480); | |
// setup method | |
frameRate(60); | |
tileWidth = 50; | |
tileHeight = 50; | |
tile = createGraphics(tileWidth, tileHeight); | |
isRecording = true; | |
cX = cY = 0; | |
dX = dY = 50; | |
destinationCount = 0; | |
} | |
// handy reference: | |
// https://processing.org/tutorials/rendering/ | |
public void renderTile() { | |
tile.beginDraw(); | |
tile.noStroke(); | |
tile.background(255); | |
tile.fill(0); | |
fill(0); | |
cX += (dX-cX)/2.0f; | |
cY += (dY-cY)/2.0f; | |
tile.ellipse(cX, cY, 5, 5); | |
if (abs(dX-cX)<0.01f && abs(dY-cY)<0.01f) { | |
if (destinationCount < 5) { | |
dX = random(50); | |
dY = random(50); | |
destinationCount++; | |
} else if ( destinationCount == 5) { | |
dX = dY = 0; | |
} else { | |
isRecording = false; | |
} | |
} | |
tile.endDraw(); | |
} | |
public void draw() { | |
background(255); | |
renderTile(); | |
for (int i=0; i<height/tileHeight+1; i++) { | |
for (int j=0; j<width/tileWidth+1; j++) { | |
pushMatrix(); | |
noTint(); | |
translate(j*tileWidth, i*tileHeight); | |
if (j%2 == 0) { | |
// tint(255,64,192); // handy for seeing whats going on | |
translate(tileWidth, 0); | |
scale(-1.0f, 1.0f); | |
} | |
if (i%2 == 0) { | |
// tint(192,212,0); // handy for seeing whats going on | |
translate(0, tileHeight); | |
scale(1.0f, -1.0f); | |
} | |
image(tile, 0, 0); | |
popMatrix(); | |
} | |
} | |
String framenum = nf(frameCount, 3); | |
// for export | |
if (isRecording) { | |
saveFrame("processingexample-"+framenum+".jpg"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment