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 & HelpPrograms › slope project
Page Index Toggle Pages: 1
slope project (Read 554 times)
slope project
Jan 13th, 2009, 4:02am
 
im working on a project for my school with processing

the project is to create a line that moves with your mouse around the window and it gives you the coordinates of where the end of the line is (it's kinda confusing, but if you see my code, you'll get it)

my question is how to click and get the line in the same place


int x =30;
PFont fontA;


void setup(){
 size(700,700);
 
 smooth();
 
 fontA = createFont("Sans Serif", 32);
 textFont (fontA, 32);
 
 
}

void draw(){
 background(145,123,234);

 
 //line
 stroke(255,175,0);
 strokeWeight(10);
 line(350,350, mouseX,mouseY);
 //points
 strokeWeight(20);
 point(350,350);
 point(mouseX,mouseY);
 
 if(mouseX==0) {
   text("Slope undefined", x,60);
 }
 else{
     //text
 fill(0,255,0);
 text("Slope", x, 60);
 //slope coordinates
 fill(0,255,0);
 text(-1*(width-mouseX*2), 150,60);
 text(height-mouseY*2, 250,60);
 text("X", 150, 30);
 text("Y", 250, 30);
 }
 if(mousePressed) {
   
   
   
 }
}
Re: slope project
Reply #1 - Jan 13th, 2009, 5:25am
 
I want the line to stay where it is. Then, when you click back, it starts moving again. I'm sorry if I wasn't that specific in the first post.
Re: slope project
Reply #2 - Jan 13th, 2009, 2:38pm
 
Thanks
Re: slope project
Reply #3 - Jan 14th, 2009, 1:03am
 
sw01, I am in fact a student working on a project. That code was very useful and I thank you for that( you didn't spoil the homework). I didn't get much chance to look at it, and I was wondering if you could show it again or at least tell me what you did. That would be great, and I would appreciate it a lot.  Also, if anyone else is willing to help me out with this, I would love it.
Re: slope project
Reply #4 - Jan 14th, 2009, 5:01am
 
Do you want me to just give you the whole code, that would be easier
Re: slope project
Reply #5 - Jan 14th, 2009, 5:12am
 
horsecomp, this might not do what you want it to do. When you click in this code, the whole thing dissapears. you'll see when you run the code


int x =30;
PFont fontA;

boolean lineLock;

void mousePressed () {
 lineLock = !lineLock;
}
int posX;
int posY;

void setup(){
 size(700,700);
 
 smooth();
 
 fontA = createFont("Sans Serif", 32);
 textFont (fontA, 32);
 
 lineLock = false;
}

void draw(){
 background(145,123,234);

if(lineLock==false) {
 posX= mouseX;
 posY = mouseY;
 
 //line
 stroke(255,175,0);
 strokeWeight(10);
 line(350,350, posX, posY);
 //points
 strokeWeight(20);
 point(350,350);
 point(posX, posY);
 
 if(mouseX==0) {
   text("Slope undefined", x,60);
 }
 else{
     //text
 fill(0,255,0);
 text("Slope", x, 60);
 //slope coordinates
 fill(0,255,0);
 text(-1*(width-posX*2), 150,60);
 text(height-posY*2, 250,60);
 text("X", 150, 30);
 text("Y", 250, 30);
 }
 if(mousePressed) {
 
   }
   
   
 }


}

Re: slope project
Reply #6 - Jan 15th, 2009, 5:14am
 
u should just post a new topic dolphin22 or instant message sw01
Page Index Toggle Pages: 1