/**Related Examples:http://processing.org/learning/basics/triangleflower.html
* Shape Revolver
* @author Gabriel Dunne
* @description Revolves a repeating shape around a vertex
* @param int _x the X position
* @param int _y the Y position
* @param int sides the number of sides
* @param float radius the radius
*/
void shapeRevolver(int _x, int _y, int sides, float radius) {
for ( int i = 0; i < 360; i += (360 / sides) ) {
float x = _x + sin(radians(i)) * radius;
float y = _y + cos(radians(i)) * radius;
pushMatrix();
translate(x, y);
rotate(atan2(y - _y, x - _x));
// draw your shape here
rect(0,0,20,20);
//
popMatrix();
}
}
Shape Revolver Function
A "Shape Revolver" function written in Processing. This function revolves a shape around a center point with a specified number and circle radius.
Polygon Function
Polygon Function
// polygon function
void setup() {
size(600, 600);
smooth();
}
void draw() {
background(0);
noStroke();
fill(255);
polygon(100, 100, 5, 40);
polygon(200, 100, 6, 40);
polygon(300, 100, 7, 40);
polygon(100, 300, 7, 40);
polygon(200, 300, 3, 40);
polygon(300, 300, 8, 40);
}
void polygon(int _x, int _y, int sides, float radius) {
if (sides <= 0)
sides = 1;
beginShape();
for ( int i = 0; i < 360; i += (360 / sides) ) {
float x = _x + sin(radians(i)) * radius;
float y = _y + cos(radians(i)) * radius;
vertex(x, y);
// ellipse(x, y, 2, 2);
}
endShape();
}
Array Trails
A bit of code to create trails with the mouse using Arrays
int num = 60;
float mx[] = new float[num];
float my[] = new float[num];
float size[] = new float[num];
void setup() {
size(400, 400);
strokeWeight(10);
smooth();
}
void draw() {
background(0);
fill(255);
noStroke();
int which = frameCount % num;
mx[which] = mouseX;
my[which] = mouseY;
size[which] = abs(mouseX-pmouseX) + abs(mouseY-pmouseY);
for (int i = 0; i < num; i++) {
int index = (which+1 + i) % num;
ellipse(mx[index], my[index], size[index], size[index]);
}
}
Subscribe to:
Posts (Atom)