CSCI A201/A597

Lab Notes 9

Spring 2000


Mouse input: scribbling mirrored drawings.

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:
  1. this part creates the symmetric of current with respect to the vertical that goes through the middle of a default drawing window (with the x coordinate equals 100).

  2. same thing for next

  3. draw the line from tnerruc to txen

  4. now the current position is in the symmetric drawing; fix that

  5. update current. What happens otherwise?

5. Try to come up with a different way of drawing symmetric drawings.
Check page 78 in your textbook for more.