Skip to content

Instantly share code, notes, and snippets.

@ohmygodwin
Last active December 24, 2015 08:49
Show Gist options
  • Save ohmygodwin/6773367 to your computer and use it in GitHub Desktop.
Save ohmygodwin/6773367 to your computer and use it in GitHub Desktop.
more spinning primatives!
int squareCount = 0;
int circleCount = 0;
SquareSpin[] square = new SquareSpin[300];
CircleSpin[] circle = new CircleSpin[300];
void setup() {
size(662, 662);
for (int a = -320; a <= 320; a = a + 40) {
for (int b = -320; b <= 320; b = b + 40) {
square[squareCount] = new SquareSpin(a, b);
squareCount++;
}
}
for (int c = -320; c <= 320; c = c + 40) {
for (int d = -320; d <= 320; d = d + 40) {
circle[circleCount] = new CircleSpin(c, d);
circleCount++;
}
}
}
void draw() {
background(220, 155, 127);
pushMatrix();
translate(width/128, height/128);
int f = 0;
int j = 0;
float d = map(mouseX, 0, width, 7, 70);
float d2 = map(mouseY, 0, height, 7, 70);
while (f < squareCount) {
square[f].go();
square[f].show();
square[f].updateSize(d);
f++;
}
while (j < circleCount) {
circle[j].go();
circle[j].show();
circle[j].updateSize(d2);
j++;
}
popMatrix();
}
class Spin {
float speed = random(-0.05, 0.05);
float angle = 0;
float d = 20;
int x, y;
Spin(int xpos, int ypos) {
x = xpos;
y = ypos;
}
void go() {
angle += speed;
}
void updateSize(float size) {
d = size;
}
}
class SquareSpin extends Spin {
SquareSpin(int x, int y) {
super(x, y);
}
void show() {
pushMatrix();
translate(((width/2)+x), ((height/2)+y));
rotate(angle);
rectMode(CENTER);
noStroke();
fill(150, 93, 102, 200);
rect(x/128, y/128, d, d);
popMatrix();
}
}
class CircleSpin extends Spin {
CircleSpin(int x, int y) {
super(x, y);
}
void show() {
pushMatrix();
translate(((width/2)+x), ((height/2)+y));
rotate(angle);
ellipseMode(CORNER);
noFill();
strokeWeight(2);
stroke(2, 81, 75);
ellipse(x/128, y/128, d, d);
popMatrix();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment