| CSCI A201/A597Lab Notes 9 Spring 2000 |
Use the lab to get help using appendix E or to start with your assignment.
A survey will be posted and be available from now until April 1st.
Here's another application that may or may not be presented in lecture.
1. Drawing one curve with the mouse.
import element.*;
public class Lab9 {
public static void main(String[] args) {
DrawingWindow d = new DrawingWindow();
Pt p = d.awaitMousePress();
d.moveTo(p);
while (d.mousePressed()) {
d.lineTo(d.getMouse());
}
}
}
2. Drawing any number of curves with the mouse.
import element.*;
public class Lab9 {
public static void main(String[] args) {
DrawingWindow d = new DrawingWindow();
while (true) {
Pt p = d.awaitMousePress();
d.moveTo(p);
while (d.mousePressed()) {
d.lineTo(d.getMouse());
}
}
}
}
Essentially one one ends we need to go back and wait to start a new one. 3. Making it somewhat more explicit.
import element.*;
public class Lab9 {
public static void main(String[] args) {
DrawingWindow d = new DrawingWindow();
while (true) {
Pt current = d.awaitMousePress();
d.moveTo(current);
while (d.mousePressed()) {
Pt next = d.getMouse();
d.lineTo(next);
}
}
}
}
4. Symmetry.
import element.*;
public class Lab9 {
public static void main(String[] args) {
DrawingWindow d = new DrawingWindow();
while (true) {
Pt current = d.awaitMousePress();
d.moveTo(current);
while (d.mousePressed()) {
Pt next = d.getMouse();
d.lineTo(next);
Pt tnerruc = new Pt(current); // [1]
tnerruc.x(2 * 100 - current.x()); // [1]
Pt txen = new Pt(next); // [2]
txen.x(2 * 100 - next.x()); // [2]
d.moveTo(tnerruc); // [3]
d.lineTo(txen); // [3]
d.moveTo(next); // [4]
current = next; // [5]
}
}
}
}
There are a few comments that one could make here: current with respect
to the vertical that goes through the middle of a default drawing window
(with the x coordinate equals 100).
next
tnerruc to txen
current. What happens otherwise?
Check page 78 in your textbook for more.