DragMe[] drags = new DragMe[20];
PGraphics backLayer;
color backgr;
color fillcolor=0;
float colourincrement=1;
void setup() {
size(500, 500);
for (int i = 0; i < drags.length; i++) {
drags[i] = new DragMe();
}
backLayer = createGraphics(width, height, g.getClass().getName());
}
void draw()
{
frameRate(10);
background(backgr);
{
backLayer.beginDraw();
backLayer.noFill();
if (mousePressed ==true && t()) {
backLayer.line( pmouseX, pmouseY, mouseX, mouseY );
backLayer.stroke(0);
backLayer.endDraw(); }
image( backLayer, 0, 0 );
}
for (int i = 0; i < drags.length; i++)
{
drags[i].update(); }
{
ellipse(width/2.5, height/2.5,110, 110);
}
}
boolean t() {
return millis() < 20000;
}
void mousePressed() {
for (int i = 0; i < drags.length; i++) {
if (!drags[i].isOver())
drags[i].dontMove = true;
drags[i].offset_x = mouseX - drags[i].pos_x;
drags[i].offset_y = mouseY - drags[i].pos_y;
}
}
void mouseReleased() {
for (int i = 0; i < drags.length; i++) {
drags[i].locked = false;
drags[i].dontMove = false;
}
}
class DragMe {
float pos_x, pos_y;
float SIZE = random(10,45);
float prev_x, prev_y;
boolean locked;
boolean dontMove;
color c = color (255);
float offset_x, offset_y;
DragMe() {
pos_x = random(width-SIZE);
pos_y = random(height-SIZE);
}
void update() {
ellipse(pos_x, pos_y, SIZE, SIZE);
fill(c);
ellipseMode(CORNER);
noStroke();
{ if (isOver() && !locked && !dontMove || locked && !dontMove )
c = color (255);
if (isClicked()) {
locked = true;
}
if(isIn()){
locked = false;
}
if (locked && !dontMove) {
pos_x = mouseX - offset_x;
pos_y = mouseY - offset_y;
}
if (time() && fillcolor>=0) {
fillcolor+=colourincrement;
backgr= fillcolor;
c = color (255,255,255,0);}
if (t2() ){
backgr= 255;}
}
}
boolean isOver() {
float right_x = pos_x + SIZE;
float bottom_y = pos_y + SIZE;
return mouseX >= pos_x && mouseX <= right_x &&
mouseY >= pos_y && mouseY <= bottom_y;
}
boolean isClicked() {
return isOver() && mousePressed && !dontMove;
}
boolean isIn() {
float right_x = pos_x + SIZE;
float bottom_y = pos_y + SIZE;
return right_x >= width/2.5 + SIZE && right_x <= width/2.5 + 100 &&
bottom_y >= height/2.5 + SIZE && bottom_y <= height/2.5 + 100;
}
boolean time() {
return millis() > 20000;
}
boolean t2() {
return millis() > 20500;
}
}
No hay comentarios:
Publicar un comentario