Computer Science 120
Introduction to Programming
Spring 2011, Siena College
PerspectiveRR Demo
A working demo of PerspectiveRR will appear below. Click inside the applet to interact with it.
PerspectiveRR BlueJ Project
Click here to download a BlueJ project for PerspectiveRR.
PerspectiveRR Source Code
The Java source code for PerspectiveRR is below. Click on a file name to download it.
import objectdraw.*; import java.awt.*; /* * Example PerspectiveRR * * Jim Teresco, Siena College, CSIS 120, Spring 2011 * * $Id: PerspectiveRR.java 1577 2011-03-28 02:10:20Z terescoj $ */ public class PerspectiveRR extends WindowController { private static final int TOP_OFFSET = 25; private static final int TIE_HEIGHT = 20; private static final int MIN_TIE_WIDTH = 40; private static final int TIE_SPACING = 30; public void begin() { Location topOfLines = new Location(canvas.getWidth()/2, TOP_OFFSET); Location bottomOfLine1 = new Location(canvas.getWidth()/4, canvas.getHeight() - TOP_OFFSET); Location bottomOfLine2 = new Location(3*canvas.getWidth()/4, canvas.getHeight() - TOP_OFFSET); new Line(topOfLines, bottomOfLine1, canvas); new Line(topOfLines, bottomOfLine2, canvas); double biggestTieWidth = 3*canvas.getWidth()/4; int numTies = (canvas.getHeight() - 2 * TOP_OFFSET) / (TIE_HEIGHT + TIE_SPACING); double nextWidth = MIN_TIE_WIDTH; double widthIncrement = (biggestTieWidth - MIN_TIE_WIDTH) / (numTies - 1); double nextYPos = TOP_OFFSET; int tieNum = 0; while (tieNum < numTies) { new FilledRect(canvas.getWidth()/2 - nextWidth/2, nextYPos, nextWidth, TIE_HEIGHT, canvas); nextWidth = nextWidth + widthIncrement; nextYPos = nextYPos + TIE_HEIGHT + TIE_SPACING; tieNum++; } } }