xxxxxxxxxx
/*
* Asynchronous circles
* Programming Challenge of dm2.blockF 2016
*
* Constantinos Miltiadis
* c.miltiades@tugraz.at
* studioany.com
*
* Institute of Architecture and Media
* TU Graz
*/
float angle1 = 0;
float angle2=0;
//to create different shapes
//change these angles to create different shapes
float angleStep1=PI/35.4;
float angleStep2 = PI/25;
float radius1;
float radius2;
PVector center;
void setup() {
size(500, 500);
//initialize the center vector, place it in the center of the canvas
center = new PVector (width/2, height/2);
radius1 = width/2-50;
radius2 = radius1*2/3;
background(255);
fill(0);
text("Press SPACE to Save a picture", 10,height-20);
text("Press any other key to clear the background", 10, height-12);
}
void draw() {
//stroke with opacity
stroke(0, 20);
//calculate the 2 points
PVector p1 = getCirclePoint(center, radius1, angle1);
PVector p2 = getCirclePoint (center, radius2, angle2);
//draw a line between them
line(p1.x, p1.y, p2.x, p2.y);
//add to the angles so that the point animate along the circles
angle1= angle1 +angleStep1;
angle2= angle2 +angleStep2;
}
PVector getCirclePoint(PVector center, float radius, float angle) {
float x= center.x+ radius*cos(angle);
float y = center.y+radius*sin(angle);
PVector result = new PVector (x, y);
return result;
}
void keyPressed() {
if (key==' ') {
saveFrame("image###.png");
println("Saved picture:"+ frameCount);
} else {
clearBackground();
}
}
void clearBackground() {
background(255);
//stamp
fill(0);
text("async circles / studioany.com", 10, height-10);
}