Although I already managed to make my squares move by Wednesday, they still did not do what I initially planned so I went on trying. Eventually I managed to sort of get where I wanted, but I am glad it took me a while as the graphics that were created in the development process are actually more interesting.
One single square moving code:
class Square {
float xPos;
float yPos;
float diam;
int rot;
int colorCount;
int level;
int topLevel;
boolean rotated;
int rotationValue;
Square(float x, float y, float d, int counter, int e, int max)
{
xPos = x;
yPos= y;
diam = d;
colorCount = counter;
rot = 0;
level = e;
topLevel = max;
rotated = false;
rotationValue = 0;
}
void render() {
if (colorCount==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCount==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCount==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(3);
stroke(red, green, blue);
rectMode(CENTER);
rect(xPos+(diam/2), yPos+(diam/2), diam, diam);
}
void rotateSquare() {
if(level==topLevel){
if (colorCount==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCount==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCount==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(3);
stroke(red, green, blue);
{rectMode(CENTER);
pushMatrix();
translate(xPos+(diam/2), yPos+(diam/2));
rotate(radians(rot));
rect(0, 0, diam, diam);
// translate(-(xPos+(diam/2)),-(yPos+(diam/2)));
// drawBackground();
popMatrix();
rot+=8;
rotated = true;
rotationValue = rot;
}
}
}
void rotateBack() {
if((rotated)){
if (colorCount==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCount==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCount==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(5);
stroke(red, green, blue);
if((mouseX> xPos-(diam/20) && mouseX< xPos+(21*diam/20))
|| (mouseY> yPos-(diam/20) && mouseY< yPos+(21*diam/20))
)
{
while(rotationValue>=0){
rectMode(CENTER);
pushMatrix();
translate(xPos+(diam/2), yPos+(diam/2));
rotate(radians(rotationValue));
rect(0, 0, diam, diam);
// translate(-(xPos+(diam/2)),-(yPos+(diam/2)));
// drawBackground();
popMatrix();
rotationValue-=15;
}}
}
}
void drawBackground () {
float y = 0;
float x= 0;
float d= 120;
int colorCounter = 0;
while (d>=0){
if (colorCounter==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCounter==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCounter==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(3);
stroke(red, green, blue);
Square mySquare1 = new Square(x, y, d, colorCounter, 0, 4 );
mySquare1.render();
x+=d+5;
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0;}}
colorCounter+=1;
if(colorCounter==3){colorCounter=0;}
}
}
}
Square[] mySquareRow;
Square mySquare1;
float y = 0;
float x= 0;
float d= 120;
int count=0;
int red = 0;
int green =0;
int blue = 0;
int colorCount = 0;
int once = 0;
int rot=0;
int e=0;
int[] topLevel = new int[10];
int max;
void setup(){
size(900,750);
background(255);
while(d>0) //count number of squares that will be displayed
{x+=d+5;
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0; topLevel[e]= e; e++;}}
count+=1;
}
int max= max(topLevel);
println(max);
println(count);
x=0;
y=0;
d=120;
mySquareRow = new Square[count];
}
void draw(){
if (once ==0){
mySquare1=new Square(x, y, d, colorCount, 0, max);
mySquare1.render();
x+=d+5;
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0;}}
colorCount+=1;
if(colorCount==3){colorCount=0;}
if(d<=0 || (mousePressed)){once=1; x=0;
y=0;
d=120; colorCount =0; }
}
else if (once ==1) {
drawSquares();
once = 2;
}
else {
for (Square square : mySquareRow)
{ if((square.level == 4)&&(mouseX> square.xPos-(square.diam/20) && mouseX< square.xPos+(21*square.diam/20))
&&( mouseY> square.yPos-(square.diam/20) && mouseY< square.yPos+(21*square.diam/20)))
{
square.rotateSquare();
//square.rotateBack();
}
else {
square.render();
}
if(mousePressed){once=0;}
}
}
}
void drawSquares(){
e=0;
for (int i=0; i<(count); i++) {
//
mySquareRow[i] = new Square(x, y, d, colorCount, e, 4);
x+=d+5;
colorCount++;
if (colorCount == 3) {colorCount =0;}
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0; e++;}
println(i);}
}
//
for (Square square : mySquareRow) {
square.render();
colorCount++;}
}
//void drawBackground () {
// while (d>=0){
// if (colorCount==0)
// { red = 121;
// green = 30;
// blue = 157;
// }
//
// if (colorCount==1)
// {red = 255;
// green = 194;
// blue = 62;
// }
//
// if (colorCount==2)
// { red = 255;
// green = 62;
// blue = 168;
// }
//
// strokeWeight(3);
// stroke(red, green, blue);
//
// mySquare1=new Square(x, y, d);
// mySquare1.render();
// x+=d+5;
// if (x>=width){x=0; y+=d+5; d-=2;
// if (y>=height){y=0;}}
// colorCount+=1;
// if(colorCount==3){colorCount=0;}
// }
//}
//
More exciting versions:
1) lines moving:
class Square {
float xPos;
float yPos;
float diam;
int rot;
int colorCount;
int level;
int topLevel;
boolean rotated;
int rotationValue;
Square(float x, float y, float d, int counter, int e, int max)
{
xPos = x;
yPos= y;
diam = d;
colorCount = counter;
rot = 0;
level = e;
topLevel = max;
rotated = false;
rotationValue = 0;
}
void render() {
if (colorCount==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCount==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCount==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(3);
stroke(red, green, blue);
rectMode(CENTER);
rect(xPos+(diam/2), yPos+(diam/2), diam, diam);
}
void rotateSquare() {
if(level==topLevel){
if (colorCount==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCount==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCount==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(3);
stroke(red, green, blue);
{rectMode(CENTER);
pushMatrix();
translate(xPos+(diam/2), yPos+(diam/2));
rotate(radians(rot));
rect(0, 0, diam, diam);
// translate(-(xPos+(diam/2)),-(yPos+(diam/2)));
// drawBackground();
popMatrix();
rot+=8;
rotated = true;
rotationValue = rot;
}
}
}
void rotateBack() {
if((rotated)){
if (colorCount==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCount==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCount==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(5);
stroke(red, green, blue);
if((mouseX> xPos-(diam/20) && mouseX< xPos+(21*diam/20))
|| (mouseY> yPos-(diam/20) && mouseY< yPos+(21*diam/20))
)
{
while(rotationValue>=0){
rectMode(CENTER);
pushMatrix();
translate(xPos+(diam/2), yPos+(diam/2));
rotate(radians(rotationValue));
rect(0, 0, diam, diam);
// translate(-(xPos+(diam/2)),-(yPos+(diam/2)));
// drawBackground();
popMatrix();
rotationValue-=15;
}}
}
}
void drawBackground () {
float y = 0;
float x= 0;
float d= 120;
int colorCounter = 0;
while (d>=0){
if (colorCounter==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCounter==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCounter==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(3);
stroke(red, green, blue);
Square mySquare1 = new Square(x, y, d, colorCounter, 0, 4 );
mySquare1.render();
x+=d+5;
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0;}}
colorCounter+=1;
if(colorCounter==3){colorCounter=0;}
}
}
}
Square[] mySquareRow;
Square mySquare1;
float y = 0;
float x= 0;
float d= 120;
int count=0;
int red = 0;
int green =0;
int blue = 0;
int colorCount = 0;
int once = 0;
int rot=0;
int e=0;
int[] topLevel = new int[10];
int max;
void setup(){
size(900,750);
background(255);
while(d>0) //count number of squares that will be displayed
{x+=d+5;
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0; topLevel[e]= e; e++;}}
count+=1;
}
int max= max(topLevel);
println(max);
println(count);
x=0;
y=0;
d=120;
mySquareRow = new Square[count];
}
void draw(){
if (once ==0){
mySquare1=new Square(x, y, d, colorCount, 0, max);
mySquare1.render();
x+=d+5;
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0;}}
colorCount+=1;
if(colorCount==3){colorCount=0;}
if(d<=0 || (mousePressed)){once=1; x=0;
y=0;
d=120; colorCount =0; }
}
else if (once ==1) {
drawSquares();
once = 2;
}
else {
for (Square square : mySquareRow)
{ if((square.level == 4)&&(mouseX> square.xPos-(square.diam/20) && mouseX< square.xPos+(21*square.diam/20))
&&( mouseY> square.yPos-(square.diam/20) && mouseY< square.yPos+(21*square.diam/20)))
{
square.rotateSquare();
//square.rotateBack();
}
else {
square.render();
}
if(mousePressed){once=0;}
}
}
}
void drawSquares(){
e=0;
for (int i=0; i<(count); i++) {
//
mySquareRow[i] = new Square(x, y, d, colorCount, e, 4);
x+=d+5;
colorCount++;
if (colorCount == 3) {colorCount =0;}
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0; e++;}
println(i);}
}
//
for (Square square : mySquareRow) {
square.render();
colorCount++;}
}
//void drawBackground () {
// while (d>=0){
// if (colorCount==0)
// { red = 121;
// green = 30;
// blue = 157;
// }
//
// if (colorCount==1)
// {red = 255;
// green = 194;
// blue = 62;
// }
//
// if (colorCount==2)
// { red = 255;
// green = 62;
// blue = 168;
// }
//
// strokeWeight(3);
// stroke(red, green, blue);
//
// mySquare1=new Square(x, y, d);
// mySquare1.render();
// x+=d+5;
// if (x>=width){x=0; y+=d+5; d-=2;
// if (y>=height){y=0;}}
// colorCount+=1;
// if(colorCount==3){colorCount=0;}
// }
//}
//
2) all moving proportionally to the placement:
class Square {
float xPos;
float yPos;
float diam;
float rot;
int colorCount;
int level;
int topLevel;
boolean rotated;
int rotationValue;
Square(float x, float y, float d, int counter, int e, int max)
{
xPos = x;
yPos= y;
diam = d;
colorCount = counter;
rot = 0;
level = e;
topLevel = max;
rotated = false;
rotationValue = 0;
}
void render() {
if (colorCount==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCount==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCount==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(3);
stroke(red, green, blue);
rectMode(CENTER);
rect(xPos+(diam/2), yPos+(diam/2), diam, diam);
}
void rotateSquare() {
if(level==topLevel){
if (colorCount==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCount==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCount==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(3);
stroke(red, green, blue);
{rectMode(CENTER);
pushMatrix();
rot = sqrt(((mouseX-xPos)*(mouseX-xPos))+((mouseY-yPos)*(mouseY-yPos)));
translate(xPos+(diam/2), yPos+(diam/2));
rotate(radians(rot));
rect(0, 0, diam, diam);
// translate(-(xPos+(diam/2)),-(yPos+(diam/2)));
// drawBackground();
popMatrix();
// rot+=15;
// rotated = true;
// rotationValue = rot;
}
}
}
void rotateBack() {
if((rotated)){
if (colorCount==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCount==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCount==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(5);
stroke(red, green, blue);
if((mouseX> xPos-(diam/20) && mouseX< xPos+(21*diam/20))
|| (mouseY> yPos-(diam/20) && mouseY< yPos+(21*diam/20))
)
{
while(rotationValue>=0){
rectMode(CENTER);
pushMatrix();
translate(xPos+(diam/2), yPos+(diam/2));
rotate(radians(rotationValue));
rect(0, 0, diam, diam);
// translate(-(xPos+(diam/2)),-(yPos+(diam/2)));
// drawBackground();
popMatrix();
rotationValue-=15;
}}
}
}
void drawBackground () {
float y = 0;
float x= 0;
float d= 120;
int colorCounter = 0;
while (d>=0){
if (colorCounter==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCounter==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCounter==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(3);
stroke(red, green, blue);
Square mySquare1 = new Square(x, y, d, colorCounter, 0, 4 );
mySquare1.render();
x+=d+5;
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0;}}
colorCounter+=1;
if(colorCounter==3){colorCounter=0;}
}
}
}
Square[] mySquareRow;
Square mySquare1;
float y = 0;
float x= 0;
float d= 120;
int count=0;
int red = 0;
int green =0;
int blue = 0;
int colorCount = 0;
int once = 0;
int rot=0;
int e=0;
int[] topLevel = new int[10];
int max;
void setup(){
size(900,750);
background(255);
while(d>0) //count number of squares that will be displayed
{x+=d+5;
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0; topLevel[e]= e; e++;}}
count+=1;
}
int max= max(topLevel);
println(max);
println(count);
x=0;
y=0;
d=120;
mySquareRow = new Square[count];
}
void draw(){
if (once ==0){
mySquare1=new Square(x, y, d, colorCount, 0, max);
mySquare1.render();
x+=d+5;
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0;}}
colorCount+=1;
if(colorCount==3){colorCount=0;}
if(d<=0 || (mousePressed)){once=1; x=0;
y=0;
d=120; colorCount =0; }
}
else if (once ==1) {
drawSquares();
once = 2;
}
else {
for (Square square : mySquareRow)
{square.rotateSquare();
//square.rotateBack();
}
if(mousePressed){once=0;}
}
}
void drawSquares(){
e=0;
for (int i=0; i<(count); i++) {
//
mySquareRow[i] = new Square(x, y, d, colorCount, e, 4);
x+=d+5;
colorCount++;
if (colorCount == 3) {colorCount =0;}
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0; e++;}
println(i);}
}
//
for (Square square : mySquareRow) {
square.render();
colorCount++;}
}
//void drawBackground () {
// while (d>=0){
// if (colorCount==0)
// { red = 121;
// green = 30;
// blue = 157;
// }
//
// if (colorCount==1)
// {red = 255;
// green = 194;
// blue = 62;
// }
//
// if (colorCount==2)
// { red = 255;
// green = 62;
// blue = 168;
// }
//
// strokeWeight(3);
// stroke(red, green, blue);
//
// mySquare1=new Square(x, y, d);
// mySquare1.render();
// x+=d+5;
// if (x>=width){x=0; y+=d+5; d-=2;
// if (y>=height){y=0;}}
// colorCount+=1;
// if(colorCount==3){colorCount=0;}
// }
//}
//
3) background pattern moving:
class Square {
float xPos;
float yPos;
float diam;
int rot;
int colorCount;
int level;
int topLevel;
boolean rotated;
int rotationValue;
Square(float x, float y, float d, int counter, int e, int max)
{
xPos = x;
yPos= y;
diam = d;
colorCount = counter;
rot = 0;
level = e;
topLevel = max;
rotated = false;
rotationValue = 0;
}
void render() {
if (colorCount==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCount==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCount==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(3);
stroke(red, green, blue);
rectMode(CENTER);
rect(xPos+(diam/2), yPos+(diam/2), diam, diam);
}
void rotateSquare() {
if(level==topLevel){
if (colorCount==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCount==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCount==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(5);
stroke(red, green, blue);
if(mouseX> xPos-(diam/20) && mouseX< xPos+(21*diam/20) && mouseY> yPos-(diam/20) && mouseY< yPos+(21*diam/20))
{rectMode(CENTER);
pushMatrix();
translate(xPos+(diam/2), yPos+(diam/2));
rotate(radians(rot));
rect(0, 0, diam, diam);
drawBackground();
popMatrix();
rot+=15;
rotated = true;
rotationValue = rot;
}
}
}
void rotateBack() {
if((rotated)){
if (colorCount==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCount==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCount==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(5);
stroke(red, green, blue);
if(mouseX> xPos-(diam/20) && mouseX< xPos+(21*diam/20) && mouseY> yPos-(diam/20) && mouseY< yPos+(21*diam/20))
{
while(rotationValue>=0){
rectMode(CENTER);
pushMatrix();
translate(xPos+(diam/2), yPos+(diam/2));
rotate(radians(rotationValue));
rect(0, 0, diam, diam);
drawBackground();
popMatrix();
rotationValue-=15;
}}
}
}
void drawBackground () {
float y = 0;
float x= 0;
float d= 120;
int colorCounter = 0;
while (d>=0){
if (colorCounter==0)
{ red = 121;
green = 30;
blue = 157;
}
if (colorCounter==1)
{red = 255;
green = 194;
blue = 62;
}
if (colorCounter==2)
{ red = 255;
green = 62;
blue = 168;
}
strokeWeight(3);
stroke(red, green, blue);
Square mySquare1 = new Square(x, y, d, colorCounter, 0, 4 );
mySquare1.render();
x+=d+5;
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0;}}
colorCounter+=1;
if(colorCounter==3){colorCounter=0;}
}
}
}
Square[] mySquareRow;
Square mySquare1;
float y = 0;
float x= 0;
float d= 120;
int count=0;
int red = 0;
int green =0;
int blue = 0;
int colorCount = 0;
int once = 0;
int rot=0;
int e=0;
int[] topLevel = new int[10];
int max;
void setup(){
size(900,750);
background(255);
while(d>0) //count number of squares that will be displayed
{x+=d+5;
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0; topLevel[e]= e; e++;}}
count+=1;
}
int max= max(topLevel);
println(max);
println(count);
x=0;
y=0;
d=120;
mySquareRow = new Square[count];
}
void draw(){
if (once ==0){
mySquare1=new Square(x, y, d, colorCount, 0, max);
mySquare1.render();
x+=d+5;
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0;}}
colorCount+=1;
if(colorCount==3){colorCount=0;}
if(d<=0 || (mousePressed)){once=1; x=0;
y=0;
d=120; colorCount =0; }
}
else if (once ==1) {
drawSquares();
once = 2;
}
else {
for (Square square : mySquareRow)
{square.rotateSquare();
square.rotateBack();}
if(mousePressed){once=0;}
}
}
void drawSquares(){
e=0;
for (int i=0; i<(count); i++) {
//
mySquareRow[i] = new Square(x, y, d, colorCount, e, 4);
x+=d+5;
colorCount++;
if (colorCount == 3) {colorCount =0;}
if (x>=width){x=0; y+=d+5; d-=2;
if (y>=height){y=0; e++;}
println(i);}
}
//
for (Square square : mySquareRow) {
square.render();
colorCount++;}
}
//void drawBackground () {
// while (d>=0){
// if (colorCount==0)
// { red = 121;
// green = 30;
// blue = 157;
// }
//
// if (colorCount==1)
// {red = 255;
// green = 194;
// blue = 62;
// }
//
// if (colorCount==2)
// { red = 255;
// green = 62;
// blue = 168;
// }
//
// strokeWeight(3);
// stroke(red, green, blue);
//
// mySquare1=new Square(x, y, d);
// mySquare1.render();
// x+=d+5;
// if (x>=width){x=0; y+=d+5; d-=2;
// if (y>=height){y=0;}}
// colorCount+=1;
// if(colorCount==3){colorCount=0;}
// }
//}
//




