Skip to content

Instantly share code, notes, and snippets.

@camb416
Created February 19, 2016 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camb416/bcb18c094ef0e3fbadcd to your computer and use it in GitHub Desktop.
Save camb416/bcb18c094ef0e3fbadcd 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(){
// setup method
frameRate(60);
tileWidth = 15;
tileHeight = 15;
tile = createGraphics(tileWidth,tileHeight);
}
// handy reference:
// https://processing.org/tutorials/rendering/
public void renderTile(){
tile.beginDraw();
tile.noStroke();
tile.background(255);
tile.fill(0);
// first circle
float x = tileWidth/2.0f+cos((float)frameCount/10.0f)*tileWidth/2.0f;
float y = tileHeight/2.0f+sin((float)frameCount/10.0f)*tileHeight/2.0f;
float circleSize = 5.0f;
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;i++){
for(int j=0;j<width/tileWidth;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();
}
}
// for export
if((float)frameCount/10.0f < TWO_PI){
saveFrame("processingexample.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