The purpose of this exercise is to help prepare you for the practical components of this course. More specifically, you will:
Firstly, you'll need to get the week 1 final lecture code. You have two options to do this:
cd <the directory you want to keep your graphics work> git clone https://github.com/robeverest/UNSWgraph.git cd UNSWgraph git checkout tags/v0.2 -b lab1
Once you have the code, you need to import it into eclipse. If you are using your own laptop and don't already have eclipse, you can get it from the eclipse website ( https://www.eclipse.org/downloads/ )
The code is already set up as an eclipse project, so you can just import it directly. To do so, go to 'File -> Import...' . In the list that comes up, under "General" select "Existing Projects into Workspace" and click next. On the subsequent screen, click browse at the top right and select the directory containing the project ("UNSWgraph-v0.2" if you downloaded the zip file, "UNSWgraph" if you cloned the git repo).
The project has the following structure:
If you open MoreInteresting.java in the examples package, you'll see that it draws a bunch of lines and a point. You can run it from the "Run" menu. Click "Run As -> Java Application". If everything is working, you should see a badly drawn aquatic animal appear in a window.
Note: If you're running this on the CSE lab machines, you may see some errors in the console relating to EGL, DRI and drivers. If everything else works, then you can safely ignore those messages.
Try adjusting the some of the points directly in the code. See if you can make it look less badly drawn.
In this exercise you will create an application for drawing polygons. You can run a sample version on the lab machines with
java -jar /home/cs3421/public_html/PolygonDrawing.jar
or if you're using your laptop, download the sample , and run it locally with
java -jar PolygonDrawing.jar
in the directory with the file.
Left-clicking in the window creates a point. Subsequent left clicking creates a line strip connecting all the points. Right-clicking turns the last created line strip into a polygon.
Create a Polygon2D class in the unsw.graphics.geometry package. It should contain:
public Polygon2D(List<Point2D> points) { ... }
Hint: Use the LineStrip2D class for inspiration
Make a copy of LineDrawing.java and call it PolygonDrawing.java. Modify it so that polygons are drawn instead of line strips. Like in the sample, a line strip should be used
Play around with your program (maybe try to draw something pretty). What sorts of polygons can't you draw? What happens if you try to create a polygon with only 2 points? If it doesn't work, can you fix it?
Resource created Tuesday 10 July 2018, 10:08:51 PM, last modified Tuesday 24 July 2018, 04:42:53 PM.