Creating a moving line
in
Programming Questions
•
1 year ago
Hey people.
I'm working on a game at the moment, I am stuck on something at the moment. I want to create a line which starts from a static starting position, and when I click it will gradually move towards where the mouse was clicked.
The code below shows what I want to achieve.
int endX;
int endY;
int endvar;
int startX;
void setup() {
size(500, 500);
startX = (int)random(150, 300);
endY = 0;
endvar = (int)random(-1 , 2);
endX = startX;
}
void draw(){
background (255);
smooth();
stroke(255,0,0);
line(startX, 0, endX, endY);
endY++;
endX = endX + endvar;
}
(That is part of a separate section).
This is the code I have so far -
int endX;
int endY;
int startX;
int startY;
void setup(){
size(500, 500);
startX = 250;
startY = 480;
}
void draw(){
background (255);
smooth();
stroke(0,255,255);
}
void mousePressed() {
smooth();
stroke(255,0,0);
line(250, 480, mouseX, mouseY);
}
I've tried integrating both pieces of code together, but this hasn't seemed to work at all and I think I need some sort of variable system. Could somebody lend me a hand with this?
I'm working on a game at the moment, I am stuck on something at the moment. I want to create a line which starts from a static starting position, and when I click it will gradually move towards where the mouse was clicked.
The code below shows what I want to achieve.
int endX;
int endY;
int endvar;
int startX;
void setup() {
size(500, 500);
startX = (int)random(150, 300);
endY = 0;
endvar = (int)random(-1 , 2);
endX = startX;
}
void draw(){
background (255);
smooth();
stroke(255,0,0);
line(startX, 0, endX, endY);
endY++;
endX = endX + endvar;
}
(That is part of a separate section).
This is the code I have so far -
int endX;
int endY;
int startX;
int startY;
void setup(){
size(500, 500);
startX = 250;
startY = 480;
}
void draw(){
background (255);
smooth();
stroke(0,255,255);
}
void mousePressed() {
smooth();
stroke(255,0,0);
line(250, 480, mouseX, mouseY);
}
I've tried integrating both pieces of code together, but this hasn't seemed to work at all and I think I need some sort of variable system. Could somebody lend me a hand with this?
1