Skip to content

Instantly share code, notes, and snippets.

@ohmygodwin
Created October 8, 2013 06:03
Show Gist options
  • Save ohmygodwin/6880182 to your computer and use it in GitHub Desktop.
Save ohmygodwin/6880182 to your computer and use it in GitHub Desktop.
exploring 2d arrays!
SquareSpin[][] square = new SquareSpin[1000][1000];
CircleSpin[][] circle = new CircleSpin[1000][1000];
int distance = 60;
void setup() {
size(662, 662);
for (int a = 0; a <= width + distance; a = a + distance) {
for (int b = 0; b <= height + distance; b = b + distance) {
square[a/distance][b/distance] = new SquareSpin(a-320, b-320);
}
}
for (int c = 0; c <= width + distance; c = c + distance) {
for (int d = 0; d <= height + distance; d = d + distance) {
circle[c/distance][d/distance] = new CircleSpin(c-320, d-320);
}
}
}
void draw() {
background(54, 161, 104);
filter(INVERT);
//frameRate(1);
pushMatrix();
translate(width/128, height/128);
float f = map(mouseX, 0, width, 7, 100);
float g = map(mouseY, 0, height, 7, 100);
for (int a = 0; a <= width + distance; a = a + 40) {
for (int b = 0; b <= height + distance; b = b + 40) {
square[a/distance][b/distance].go();
square[a/distance][b/distance].show();
square[a/distance][b/distance].updateSize(f);
}
}
for (int c = 0; c <= width + distance; c = c + 40) {
for (int d = 0; d <= height + distance; d = d + 40) {
circle[c/distance][d/distance].go();
circle[c/distance][d/distance].show();
circle[c/distance][d/distance].updateSize(g);
}
}
popMatrix();
}
class Spin {
float speed = random(-0.05, 0.05);
float angle = 0;
float d;
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(183, 223, 221, 180);
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);
noFill();
strokeWeight(2);
stroke(12, 100, 150);
ellipseMode(CORNER);
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