Skip to content

Instantly share code, notes, and snippets.

@camb416
Created February 26, 2016 04:24
Show Gist options
  • Save camb416/a467ad76422d39f5aa4a to your computer and use it in GitHub Desktop.
Save camb416/a467ad76422d39f5aa4a to your computer and use it in GitHub Desktop.
import processing.core.PApplet;
import processing.core.PGraphics;
/**
* Created by cbrowning on 2/17/16.
*/
//public class ProcessingExample extends PApplet{
PGraphics tile;
int tileWidth;
int tileHeight;
// public void settings() {
// settings method (because you can't set size(int, int)
// when not in the Processing IDE
// size(720,480);
// }
public void setup(){
size(720,480);
// setup method
frameRate(60);
tileWidth = 50;
tileHeight = 50;
tile = createGraphics(tileWidth,tileHeight);
}
// handy reference:
// https://processing.org/tutorials/rendering/
public void renderTile(){
tile.beginDraw();
tile.noStroke();
tile.background(255);
tile.fill(0);
int numCircles = 16;
// n circles
for(int i=0; i<numCircles;i++){
// first circle
float x = tileWidth/2.0f+cos((float)frameCount/10.0f+i)*tileWidth/2.0f;
float y = tileHeight/2.0f+sin((float)frameCount/10.0f+i)*tileHeight/2.0f;
float circleSize = 2.0f + i;
tile.ellipse(x,y, circleSize,circleSize);
}
// second circle
//x = tileWidth/2.0f+cos((float)(frameCount+30)/10.0f)*tileWidth/2.0f;
//y = tileHeight/2.0f+sin((float)(frameCount+20)/10.0f)*tileHeight/2.0f;
// circleSize = 5.0f;
// tile.ellipse(x,y, circleSize,circleSize);
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,2);
// for export
if((float)frameCount/10.0f < TWO_PI){
saveFrame("processingexample-"+framenum+".jpg");
}
}
// IDE necessities
// static public void main(String args[]) {
// PApplet.main(new String[] { "ProcessingExample" });
//}
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment