Computer Science 252
Problem Solving with Java
Spring 2014, The College of Saint Rose
Spirograph Demo
A working demo of Spirograph will appear below. Click inside the applet to interact with it.
Spirograph BlueJ Project
Click here to download a BlueJ project for Spirograph.
Spirograph Source Code
The Java source code for Spirograph is below. Click on a file name to download it.
import objectdraw.*; /* * This program is a "Spirograph". When the mouse is pressed then dragged, * a series of lines are drawn from the press point to the current location. * * Jim Teresco, Siena College, CSCI 120, Spring 2011 * Based on similar example from Williams College CS 134. * Updated for CSC 252, The College of Saint Rose, Fall 2013 * * $Id: Spirograph.java 2218 2013-10-18 14:06:39Z terescoj $ */ public class Spirograph extends WindowController { // First coordinate of a line segment private Location linesStart; /* * When the mouse is pressed, save the press point to be used as * the first endpoint of the lines drawn during dragging */ public void onMousePress(Location point) { linesStart = point; } /* * As the user is dragging, draw a line from * initial point where mouse pressed to current point. */ public void onMouseDrag(Location point) { new Line(linesStart, point, canvas); } }