Animating a simple line, and then watching it rotate
Answered
- Need more info
- Answered
- Working on it
in
Programming Questions
•
3 years ago
Hello-- I'm very new to Processing, but I have a fair amount of experience programming in other languages (mostly BASIC and Mathematica). I'm trying to understand the best strategies for some simple animations, so that I can eventually write a program to execute a much more complex animation. I really have two questions, for now at least.
1. The code below lets a simple line sort of "draw itself" on the screen, which is what I want. I'm wondering if my code, though, is the best or most elegant way of making this happen.
2. After the final line is drawn, I would like to watch that line rotate through, say, PI/4 radians at a speed of 0.05 rad/frame. (I understand the line is already drawn at an angle. That's how I need the line. I need the line to be further rotated after that.) I know how to make a line rotate over time using the same sort of incrementation as I'm using to build the line. What I don't see how to do is work within the same Draw function. When I make an effort to rotate the line after it's finished, it's caught up in the Draw loop and it wants to rotate the line as it's being drawn, which makes sense. How does one make a draw loop "stop," and then work with what remains on the screen when it's done?
Many thanks to anyone who can point me in the right direction.
Best--
Dominick T.
_________________________
float linespeed = 1;
float endx = 0;
void setup() {
size(420, 420);
smooth();
}
void draw() {
translate(30, 100);
rotate(PI/6);
if (endx < 350) {
background(255);
line(0, 0, endx, 0);
endx += linespeed;
}
}
1. The code below lets a simple line sort of "draw itself" on the screen, which is what I want. I'm wondering if my code, though, is the best or most elegant way of making this happen.
2. After the final line is drawn, I would like to watch that line rotate through, say, PI/4 radians at a speed of 0.05 rad/frame. (I understand the line is already drawn at an angle. That's how I need the line. I need the line to be further rotated after that.) I know how to make a line rotate over time using the same sort of incrementation as I'm using to build the line. What I don't see how to do is work within the same Draw function. When I make an effort to rotate the line after it's finished, it's caught up in the Draw loop and it wants to rotate the line as it's being drawn, which makes sense. How does one make a draw loop "stop," and then work with what remains on the screen when it's done?
Many thanks to anyone who can point me in the right direction.
Best--
Dominick T.
_________________________
float linespeed = 1;
float endx = 0;
void setup() {
size(420, 420);
smooth();
}
void draw() {
translate(30, 100);
rotate(PI/6);
if (endx < 350) {
background(255);
line(0, 0, endx, 0);
endx += linespeed;
}
}
1