xxxxxxxxxx
//Lescano Carlos Daniel 2015
//Use the mouse buttons and numbers
int base = 8;
void setup() {
size(900, 700);
background(0, 100, 100);
smooth();
text("Use the mouse buttons and numbers", 25, 25);
text("Utiliza los botones del mouse y los números", 50, 50);
text("Play, stop: press 0 ", 75, 75);
}
int contu = 1;
boolean achicar = true;
void draw() {
if (mousePressed == true) {
basevariable();
if (mouseButton == RIGHT) {
rotate(PI/base);
translate(-width/2, -height/2);
basevariable();
}
} else {
stroke(255, random(255), random(255),70);
fill(random(255), 255, random(255),70);
}
if((contu == 5)&&(achicar == true))achicareluniverso();
contu++;
}
void basevariable() {
translate(width/2, height/2);
for (int i = 0; i < base; i += 1) {
rotate(TWO_PI/base);
lineavariable(mouseX-(width/2), mouseY-(height/2), pmouseX-(width/2), pmouseY-(height/2));
lineavariable(((width/2) - mouseX), mouseY-(height/2), ((width/2) - pmouseX), pmouseY-(height/2));
}
}
void lineavariable(int x, int y, int px, int py) {
float speed = abs(x-px) + abs(y-py);
ellipse(x, y, speed, speed);
// star(x,y,int(speed/2),int(speed), int(random(8)));
strokeWeight(speed/4);
}
void keyPressed() {
if (key == '9') {
base = 9;
} else if (key == '8') {
base = 8;
} else if (key == '7') {
base = 7;
} else if (key == '6') {
base = 6;
} else if (key == '5') {
base = 5;
} else if (key == '4') {
base = 4;
} else if (key == '3') {
base = 3;
} else if (key == '2') {
base = 2;
} else if (key == '1') {
base = 1;
} else if (key == '0') {
achicar = !achicar;
contu = 1;
}
}
void achicareluniverso() {
loadPixels();
for (int y = height/2; y < height; y++) {
for (int x = 0; x < width; x++) {
int loc = x + y*width;
int loc2= x + y*width;
if ((x != 1) && (y != 1) && ( x != width ) && (y != height)) {
if (width/2 >= x) {
if (height/2 >= y) {
} else {
loc2 = ( x +1)+ ((y-1)*width);
}
} else {
if (height/2 >= y) {
} else {
loc2 = ( x-1 )+ ((y-1)*width);
}
}
}
pixels[loc2] = pixels[loc] ;
}
}
for ( int y = (height/2)+1; y > 1; y--) {
for ( int x = width; x > 1 ; x--) {
int loc = x + y*width;
int loc2= x + y*width;
if ((x != 1) && (y != 1) && ( x != width ) && (y != height)) {
if (width/2 >= x) {
if (height/2 >= y) {
loc2 = ( x+1 )+ ((y+1)*width);
} else {
loc2 = ( x +1)+ ((y-1)*width);
}
} else {
if (height/2 >= y) {
loc2 = ( x -1)+ ((y+1)*width);
} else {
loc2 = ( x-1 )+ ((y-1)*width);
}
}
}
pixels[loc2] = pixels[loc] ;
}
}
updatePixels();
contu = 0;
}
void star(float x, float y, float radius1, float radius2, int npoints) {
float angle = TWO_PI / npoints;
float halfAngle = angle/2.0;
beginShape();
for (float a = 0; a < TWO_PI; a += angle) {
float sx = x + cos(a) * radius2;
float sy = y + sin(a) * radius2;
vertex(sx, sy);
sx = x + cos(a+halfAngle) * radius1;
sy = y + sin(a+halfAngle) * radius1;
vertex(sx, sy);
}
endShape(CLOSE);
}