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 › Hello, and a question.
Page Index Toggle Pages: 1
Hello, and a question. (Read 494 times)
Hello, and a question.
May 3rd, 2007, 2:37pm
 
I'm just starting out with Processing today, and I'm kind of surprised how painless it's been, so far! Cool!

Now, I'm wanting to take a user-drawn line (mouse input), and turn it into an object. It seems like createGraphic() is sort of the way to go, but it demands that I know the size of the drawing's boundaries when I create the object... which I obviously don't.

I'm sure this has been done a thousand times, so any tips greatly appreciated.

Thanks in advance.

J.
Re: Hello, and a question.
Reply #1 - May 3rd, 2007, 3:39pm
 
welcome!

first thing: a better title helps with getting your qestions answered ..

i think you just need to know when the mouse-input starts and when it ends. in between you just record the coordinates in an array. once the user finished his drawing you can use that array for whatever you want ( send it to an object, keep it somewhere else, ..). so there is no need to use createGraphics which will just give you another "layer" for drawing.

maybe you need to describe your project in a little more detail for us .. so we can give better "support".

best,
F
Re: Hello, and a question: Lines to Objects
Reply #2 - May 3rd, 2007, 3:48pm
 
cheers, and thanks for the tip!

Well, right now I'm just trying to build "gesture" objects from the lines a user draws on the screen. These will eventually be given different capabilities, but the goal right now is to be able to draw these gestures, store them, select them (by clicking), and delete them. I guess they're kind of like sprites.
I kind of figured it would be a matter storing the cooridinates of the drawing, but I'm not clear on whether that will allow me to delete/erase the original drawing. How would I manage that?

Thanks,

J.
Re: Hello, and a question.
Reply #3 - May 3rd, 2007, 7:17pm
 
something like:
Code:

boolean drawing = false;
Vector gestures;
Vector gesture;
void setup()
{
size(800,600);
gestures = new Vector();
gesture = new Vector();
}
void draw()
{
background(255);
stroke(0);
if(gesture != null){
for(int i = 1; i < gesture.size(); i++){
Point pp = (Point)gesture.get(i-1);
Point p = (Point)gesture.get(i);
line((float)pp.getX(),(float)pp.getY(),(float)p.getX(),(float)p.getY());
}
}
}

void setDrawing(boolean d)
{
if(d){
gesture = new Vector();
}
else{
gestures.add(gesture);
}
drawing = d;
}

void mousePressed()
{
setDrawing(!drawing);
}

void mouseDragged()
{
gesture.add(new Point(mouseX,mouseY));
}

void mouseReleased()
{
setDrawing(!drawing);
}



best
seltar
Re: Hello, and a question.
Reply #4 - May 3rd, 2007, 7:47pm
 
Yup! That's the idea.

I'll play around with your code for a bit, and figure out what else I can do with it. But it makes sense to me. The use of Point to do the drawing is good to know - I think I would have spent some time tracking that down!

cheers,

J.
Page Index Toggle Pages: 1