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 A Simple Drawing Tool
Page Index Toggle Pages: 1
Making A Simple Drawing Tool (Read 1589 times)
Making A Simple Drawing Tool
Oct 29th, 2007, 11:08am
 
Hey there everyone, any ideas or help for a 1st time processing guy wanting to create a basic drawing tool?  Sites and code accepted,  

thanks, gary
Re: Making A Simple Drawing Tool
Reply #1 - Oct 29th, 2007, 5:02pm
 
very simple.

void setup() {
 size(300, 300);
 background(0);
}


void draw() {
 stroke(255);
 strokeWeight(4);
 smooth();
 // Draw if mouse is pressed
 if (mousePressed) {
   line(pmouseX, pmouseY, mouseX, mouseY);
 }
}
Re: Making A Simple Drawing Tool
Reply #2 - Oct 29th, 2007, 5:26pm
 
kontrol is right!

The important thing to know is that you can use
line, rect, ellipse to draw primitive shapes.
You can also use beginShape(MODE) along with Vertex to create custom shapes to use as brushes.

To erase a drawing, all you need to do is call the background(0) function again.

Cheers!

Re: Making A Simple Drawing Tool
Reply #3 - Oct 31st, 2007, 12:26pm
 
yeah, i wanted to create different brushes. how would i constrict it to a certain area of the screen? i,e have a window in a window?
Re: Making A Simple Drawing Tool
Reply #4 - Oct 31st, 2007, 12:28pm
 
and thanks so far for the help!
Re: Making A Simple Drawing Tool
Reply #5 - Oct 31st, 2007, 6:10pm
 
its quite buggy at fast speeds, but its the basic way of doing it.

code:

int xMin = 40; // the position of the canvas from left
int xMax = 260; // the position of the canvas from right

int yMin = 40; // the position of the canvas from top
int yMax = 260; // the position of the canvas from bottom

void setup() {
 size(300, 300);
 background(100);
 noStroke();
 rect(xMin, yMin, width - 2*xMin, height - 2*yMin); // the canvas, must be drawed inside setup
 
}


void draw() {
 

 stroke(0);
 strokeWeight(4);
 smooth();
 // Draw only if the mouse is inside the canvas and it is pressed
 if((mouseX > xMin) && (mouseX < xMax)){
   if((mouseY > yMin) && (mouseY < yMax)){

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

   }
 }  
}
Page Index Toggle Pages: 1