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.
IndexDiscussionExhibition › How to make a line without line();
Page Index Toggle Pages: 1
How to make a line without line(); (Read 577 times)
How to make a line without line();
Feb 21st, 2010, 8:39am
 
I have made a little program to draw a line without the line(); funktion.

void setup(){
 size(500, 500, P2D);
 background(255);
 stroke(0);
 frameRate(5000);
}
void draw(){
float s;
 float x1 = mouseX;
 float y1 = mouseY;
 float x2 = width/2;
 float y2 = height/2;
 float px = x1;
 float py = y1;
 float c = 0;
 float g = 0;
 if(x2>x1){
   c = x2-x1;
   px = x1;
 }
 if(x1>x2){
   c = x1-x2;
   px = x2;
 }
 if(y2>y1){
   g = y2-y1;
   py = y1;
 }
 if(y1>y2){
   g = y1-y2;
   py = y2;
 }
 float x0;
 point(x1,y1);
 point(x2,y2);
 s=(y2-y1)/(x2-x1);
 x0=y2-(x2*s);
 println(x0);  
 for(int b = 0; b<c; b++){
 px++;
 py=s*px+x0;
 point(px, py);
 }
 if(x2>x1){
   c = x2-x1;
   px = x1;
 }
 if(x1>x2){
   c = x1-x2;
   px = x2;
 }
 if(y2>y1){
   g = y2-y1;
   py = y1;
 }
 if(y1>y2){
   g = y1-y2;
   py = y2;
 }
 for(int b = 0; b<g; b++){
 py++;
 px=(py-x0)/s;
 point(px, py);  
 }
 println(frameRate);
}
void mousePressed(){
 background(255);
}

perhaps someone of you knew how I can make it better. Grin
Page Index Toggle Pages: 1