THE GEORGE WASHINGTON UNIVERSITY
School of Engineering and Applied Science
Department of Electrical Engineering and Computer Science

CS 185
Interactive Computer Graphics I
Fall 2003

Professor J. L. Sibert
 

Assigned: 9/8 Due: 9/15

Assignment 1

You will implement a two dimensional line class.  This class will be capable of drawing itself on the screen (in the window of an applet, for example).  This week, you will implement a constructor,  and a render method.  The render method is what you call to draw the line.  

Notice that the coordinates are double precision, this will come in handy later.

public class MyLine2d {

// constructor

public MyLine2d (double xbegin,
                                double ybegin,
                                double xend,
                                double yend )  {}

// draws the line in the applet's window

public void render(Graphics g) {}

}

You should also write a test applet to thoroughly test your line class.  For example, the following applet draws a line from the lower left hand corner of the applet to the upper right hand corner.  You should of course test more lines.

import java.util.*;
import java.io.*;
import java.awt.*;
import java.applet.*;


public class Gradeit extends Applet {
MyLine2d minel;

    public void init () {

    setLayout(new BorderLayout());
    minel = new MyLine2d(0.0,0.0,1.0,1.0);

    }// init



    public void paint (Graphics g) {
    minel.render(g);
    } //paint
}// Gradeit

For now, assume that the coordinates are normalized device coordinates (NDC) that run from 0 to 1, that is, creating a line outside of the 0 to 1 range is an error.  We will relax this restriction for the next assignment.

It's obvious that the work is in the render method,  some hints:

look at the API documentation for the Graphics class
use g.drawLine() to draw the line
use g.getClipBounds() to get the size of the applets drawing area
remember that the coordinates used by drawLine have an inverted y axis.

You will turn in, at the beginning of class, a hard copy print out of your source code,
including directions for running the program.

You will also email a zip file, containing all of your source files (including html and
documentation) and your .class files to:

sibert@gwu.edu

include a subject line saying: cs185 assignment 1

The zip file should be named lastname_1.zip, where lastname is your last name.

Get in the habit of doing this, all of your assignments will be turned in this way.