We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Making what you have drawn fall of the screen
Page Index Toggle Pages: 1
Making what you have drawn fall of the screen (Read 377 times)
Making what you have drawn fall of the screen
May 10th, 2008, 3:07pm
 
Hi im making a drawing tool:
void setup() {
 size(300, 300);
 background(0);
 fill(random(0,255), random(0,255), random(0,255));
}



void draw() {
 stroke(255);
 strokeWeight(5);
 smooth();
 // Draw if mouse is pressed

 if (mousePressed) {
   line(pmouseX, pmouseY, mouseX, mouseY);
   
 }
}

Thats the code for it, but I wodered if there was a way to make what you have drawn fall down and go off screen after say 5 seconds, abit like this:

Drop [] drop;
int threshold = 20;
void setup(){
 size(400,400);
 drop = new Drop[100];
 for (int i = 0; i < drop.length; i++){
   drop[i] = new Drop(0,200+10);
 }
 ellipseMode(CENTER);
 smooth();
}
void draw(){
 background(0);
 for (int i = 0; i < drop.length; i++){
   drop[i].draw();
   drop[i].update();
 }
}
class Drop{
 float x,y;
 int timer;
 Drop(float x, float y){
   this.x = x;
   this.y = y;
   timer = 0;
 }
 void draw(){
   ellipse(x,y,5,5);
 }
 void update(){
   if(timer < 100)
timer++;
   else if (y < height+20)
y += 1.0;
 }
 void place(float x, float y){
   this.x = x;
   this.y = y;
   timer = 1;
 }
}
void mousePressed(){
 int item = -2;
 int items = 0;
 for (int i = 0; i < drop.length; i++){
   if (drop[i].y > height){
item = i;
   }  
   else {
items++;
   }
 }
 if (item > -1){
   drop[item].place(mouseX,mouseY);
 }
 if (items > threshold){
   for (int i = 0; i < drop.length; i++){
drop[i].timer = 500;
   }
 }
}

But instead of just dots falling I want what ive drawn to fall.

Im really new to this..
Re: Making what you have drawn fall of the screen
Reply #1 - May 13th, 2008, 7:05pm
 
You have to store what you draw (here the coordinates of the lines) in an array.
When it falls, you increase the y coordinates and redraw.
Page Index Toggle Pages: 1