Due by email before class, Monday, Jan. 24, but PREFER YOU EMAIL ME SUNDAY EVENING BY 9PM
In class we barely got to the following program. It has a point going up and to the right. When it gets to an edge, the point continues its motion at the opposite edge. Here is what we had (start with this):
final int WIDTH = 640;
final int HEIGHT = 350;
final int WHITE = 255;
final int BLACK = 0;
int position_x;
int position_y;
void setup() {
size(640, 350); // Stylistically, this should be size(WIDTH, HEIGHT).
background(WHITE);
position_x = WIDTH / 2;
position_y = HEIGHT / 2;
}
void draw() {
position_x = position_x + 1;
position_y = position_y - 1;
if (position_x >= WIDTH) {
position_x = 0;
}
if (position_y < 0) {
position_y = HEIGHT - 1;
}
stroke(BLACK);
point(position_x, position_y);
}
Modify this program to have four points:
When any of the points reaches an edge, that point should continue its motion at the opposite edge.
You are going to need four position_x’s and four position_y’s. How about starting by replacing
int position_x;
int position_y;
with
int position_x1;
int position_y1;
int position_x2;
int position_y2;
int position_x3;
int position_y3;
int position_x4;
int position_y4;
As a simple extension, just find the places to swap WHITE and BLACK so that you have white rays on a black background.
As a different extension, can you figure out a way to make about making the dots get less black as the program proceeds?