Computer Science 120
Introduction to Programming

Spring 2011, Siena College

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.


Spirograph.java

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.
 *
 * $Id: Spirograph.java 1495 2011-01-20 03:51:59Z 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);
  }
}