Computer Science 252
Problem Solving with Java
Fall 2013, The College of Saint Rose
ActiveScribblesF13 Demo
A working demo of ActiveScribblesF13 will appear below. Click inside the applet to interact with it.
ActiveScribblesF13 BlueJ Project
Click here to download a BlueJ project for ActiveScribblesF13.
ActiveScribblesF13 Source Code
The Java source code for ActiveScribblesF13 is below. Click on a file name to download it.
import objectdraw.*; import java.awt.*; import java.util.Random; /* * "Vanishing Scribble" extensions by CSC 252 Fall 2013 class * * Jim Teresco, The College of Saint Rose, Fall 2013 * and a cast of almost a dozen * * $Id: ActiveScribblesF13.java 2218 2013-10-18 14:06:39Z terescoj $ */ public class ActiveScribblesF13 extends WindowController { // random generator to pick line types private Random whichType = new Random(); // the current line type: 0 through 11 private int lineType; // location of last mouse position to draw scribble components private Location lastMouse; // pick a type of line (fading or falling) for this scribble // and remember starting point public void onMousePress(Location point) { lineType = whichType.nextInt(12); lastMouse = point; } // draw a segment of the appropriate type of line then update lastMouse public void onMouseDrag(Location point) { switch (lineType) { case 0: new FadingLine(lastMouse, point, canvas); break; case 1: new FallingLine(lastMouse, point, canvas); break; case 2: new RisingLine(lastMouse, point, canvas); break; case 3: new SlidingLine(lastMouse, point, canvas); break; case 4: new MovingLine(lastMouse, point, canvas); break; case 5: new RightLine(lastMouse, point, canvas); break; case 6: new MoveSideToSide(lastMouse, point, canvas); break; case 7: new RisingColor(lastMouse, point, canvas); break; case 8: new ShimmyLine(lastMouse, point, canvas); break; case 9: new SlowLine(lastMouse, point, canvas); break; case 10: new PurpleFade(lastMouse, point, canvas); break; case 11: new FlyingLine(lastMouse, point, canvas); break; } lastMouse = point; } }
import objectdraw.*; import java.awt.*; /** * Write a description of class MoveRight here. Submissions * that do not replace this paragraph with your own description * that includes all required items in the class submission * guidelines are subject to penalties. * * @author (your name) */ public class MoveSideToSide extends ActiveObject { //size and speed of moving to the right private static final double INITIAL_X_SPEED = 0.0001; private static final int DELAY_TIME = 33; private static final int INITIAL_DELAY = 100; //the line control private Line line; //how far to fall before stopping and disappering private double xMax; //draw a line to move to the right public MoveSideToSide(Location start, Location end, DrawingCanvas aCanvas) { //draw the line at its initial position line = new Line(start, end, aCanvas); xMax = aCanvas.getWidth(); //activate start(); } public void run() { pause(INITIAL_DELAY); double xSpeed = INITIAL_X_SPEED; while (line.getStart().getX() <= xMax || line.getEnd().getX() <= xMax) { line.move(xSpeed, 0); xSpeed = xSpeed * 1.1; pause(DELAY_TIME); } line.removeFromCanvas(); } }
// Lily K. Appleton // Similar to RisingLine // Addition to VanishingScribble import objectdraw.*; import java.awt.*; public class RisingColor extends ActiveObject { // size and speed of falling lines private static final double INITIAL_Y_SPEED = 0.0002; private static final int DELAY_TIME = 24; private static final int INITIAL_DELAY = 125; // the line controlled by this instance private Line line; // draw something and start it falling public RisingColor(Location start,Location end,DrawingCanvas aCanvas) { line = new Line(start,end,aCanvas); // activate the process start(); } // move the line over and over until it is off the screen public void run() { pause(INITIAL_DELAY); // slow fall starts, then accelerates line.setColor(Color.magenta); double ySpeed = -INITIAL_Y_SPEED; while (line.getStart().getY()>=0 || line.getEnd().getY()>=0) { line.move(0,ySpeed); ySpeed = ySpeed*1.1; pause(DELAY_TIME); } line.removeFromCanvas(); } }
import objectdraw.*; import java.awt.*; /** * Write a description of class SlowLine here. Submissions * that do not replace this paragraph with your own description * that includes all required items in the class submission * guidelines are subject to penalties. * * @author (your name) */ public class SlowLine extends ActiveObject{ private static final double INITIAL_X_SPEED = 2; private static final int DELAY_TIME = 33; private static final int INITIAL_DELAY = 1000; private Line slowline; public SlowLine(Location start, Location end, DrawingCanvas aCanvas){ slowline = new Line(start, end, aCanvas); slowline.setColor(Color.green); start(); } public void run() { pause(INITIAL_DELAY); double xSpeed = -INITIAL_X_SPEED; while ((slowline.getStart().getX() >= 0) || (slowline.getEnd().getX() >= 0)) { slowline.move(xSpeed, 0); xSpeed = xSpeed * 1 ; pause(DELAY_TIME); } slowline.removeFromCanvas(); } }
import objectdraw.*; import java.awt.*; /* * Fading line segments for the VanishingScribble example * * A simple active object that controls a line that fades from black * through shades of grey, then is removed from the canvas when it becomes * white * * Jim Teresco, Siena College, CSIS 120, Spring 2011 * The College of Saint Rose, Fall 2013 * * $Id: FadingLine.java 2218 2013-10-18 14:06:39Z terescoj $ */ public class FadingLine extends ActiveObject { // amount and speed of the fade private static final double FADE_BY = 2; private static final int DELAY_TIME = 33; private static final int INITIAL_DELAY = 1000; // the line controlled by this instance private Line line; // Draw a line and start it falling. public FadingLine(Location start, Location end, DrawingCanvas aCanvas) { // draw the line at its initial position line = new Line(start, end, aCanvas); // activate! start(); } // change the line's color periodically so it fades to white public void run() { pause(INITIAL_DELAY); int hue = 0; while (hue < 255) { line.setColor(new Color(hue, hue, hue)); pause(DELAY_TIME); hue += FADE_BY; } line.removeFromCanvas(); } }
/** * This will allow one of the options for VanishingScribble to * have the line move off the screen to the right. * * * @author Steven Graff */ import objectdraw.*; import java.awt.*; public class MovingLine extends ActiveObject { // size and speed of falling lines private static final double INITIAL_X_SPEED = 0.0001; private static final int DELAY_TIME = 33; private static final int INITIAL_DELAY = 100; // the line controlled by this instance private Line line; // how far to fall before stopping and disappearing? private double xMax; // Draw a ball and start it falling. public MovingLine(Location start, Location end, DrawingCanvas aCanvas) { // draw the line at its initial position line = new Line(start, end, aCanvas); // ask the canvas how big it is so we know when to stop xMax = aCanvas.getWidth(); // activate start(); } // move the line repeatedly until it gets sucked off the screen public void run() { pause(INITIAL_DELAY); // start out with a slow fall, then accelerate double xSpeed = INITIAL_X_SPEED; while ((line.getStart().getX() <= xMax) || (line.getEnd().getX() <= xMax)) { line.move(xSpeed, 0); xSpeed = xSpeed * 1.1; pause(DELAY_TIME); } line.removeFromCanvas(); } }
import objectdraw.*; import java.awt.*; /* * Rising line segments for the VanishingScribble example * * A simple active object that controls a line that falls up the * canvas and disappears when it goes off the end. * * Jim Teresco, Siena College, CSIS 120, Spring 2011 * The College of Saint Rose, Fall 2013 * * $Id: RisingLine.java 2218 2013-10-18 14:06:39Z terescoj $ */ public class RisingLine extends ActiveObject { // size and speed of falling lines private static final double INITIAL_Y_SPEED = 0.0001; private static final int DELAY_TIME = 33; private static final int INITIAL_DELAY = 100; // the line controlled by this instance private Line line; // Draw a ball and start it falling. public RisingLine(Location start, Location end, DrawingCanvas aCanvas) { // draw the line at its initial position line = new Line(start, end, aCanvas); // activate! start(); } // move the line repeatedly until it falls off screen public void run() { pause(INITIAL_DELAY); // start out with a slow fall, then accelerate double ySpeed = -INITIAL_Y_SPEED; while ((line.getStart().getY() >= 0) || (line.getEnd().getY() >= 0)) { line.move(0, ySpeed); ySpeed = ySpeed * 1.1; pause(DELAY_TIME); } line.removeFromCanvas(); } }
import objectdraw.*; import java.awt.*; /* * Falling line segments for the VanishingScribble example * * A simple active object that controls a line that falls down the * canvas and disappears when it goes off the end. * * Jim Teresco, Siena College, CSIS 120, Spring 2011 * The College of Saint Rose, Fall 2013 * * $Id: FallingLine.java 2218 2013-10-18 14:06:39Z terescoj $ */ public class FallingLine extends ActiveObject { // size and speed of falling lines private static final double INITIAL_Y_SPEED = 0.0001; private static final int DELAY_TIME = 33; private static final int INITIAL_DELAY = 100; // the line controlled by this instance private Line line; // how far to fall before stopping and disappearing? private double yMax; // Draw a ball and start it falling. public FallingLine(Location start, Location end, DrawingCanvas aCanvas) { // draw the line at its initial position line = new Line(start, end, aCanvas); // ask the canvas how big it is so we know when to stop yMax = aCanvas.getHeight(); // activate! start(); } // move the line repeatedly until it falls off screen public void run() { pause(INITIAL_DELAY); // start out with a slow fall, then accelerate double ySpeed = INITIAL_Y_SPEED; while ((line.getStart().getY() <= yMax) || (line.getEnd().getY() <= yMax)) { line.move(0, ySpeed); ySpeed = ySpeed * 1.1; pause(DELAY_TIME); } line.removeFromCanvas(); } }
import objectdraw.*; import java.awt.*; /* *This class creates a line that is originally black and then turns purple *before it is removed from the canvas. * *@Victoria Perras */ public class PurpleFade extends ActiveObject { // amount and speed of the fade private static final int COLOR_INC= 2; private static final int DELAY = 33; private static final int TIME_B4 = 1000; // line object private Line line; public PurpleFade(Location start, Location end, DrawingCanvas aCanvas) { // draw line line = new Line(start, end, aCanvas); // activate start(); } public void run() { //delay before action starts pause(TIME_B4); //initialize color variables int blue = 0; int red = 0; while (blue < 255) { line.setColor(new Color(red, 0, blue)); pause(DELAY); blue = COLOR_INC + blue; red = COLOR_INC + red; } pause(DELAY*4); line.removeFromCanvas(); } }
import objectdraw.*; /** * @author Scott */ public class ShimmyLine extends ActiveObject{ // size and speed of falling lines private static final double INITIAL_Y_SPEED = 0.0001; private static final int DELAY_TIME = 33; private static final int INITIAL_DELAY = 100; // the line controlled by this instance private Line line; public ShimmyLine(Location start, Location end, DrawingCanvas aCanvas) { // draw the line at its initial position line = new Line(start, end, aCanvas); // activate! start(); } // move the line repeatedly until it falls off screen public void run() { int xTrack = 0; int xSpeed = 2; pause(INITIAL_DELAY); // start out with a slow fall, then accelerate double ySpeed = -INITIAL_Y_SPEED; while ((line.getStart().getY() >= 0) || (line.getEnd().getY() >= 0)) { line.move(xSpeed, ySpeed); ySpeed = ySpeed * 1.1; if(xTrack > 5) { xSpeed *= -1; xTrack = 0; } xTrack++; pause(DELAY_TIME); } line.removeFromCanvas(); } }
import objectdraw.*; import java.awt.*; /* * This line will fly off to the right. * * @(author) Conor Smith */ public class FlyingLine extends ActiveObject { // size and speed of falling lines private static final double INITIAL_X_SPEED = 0.0001; private static final int DELAY_TIME = 33; private static final int INITIAL_DELAY = 100; // the line controlled by this instance private Line line; // Draw a ball and start it falling. public FlyingLine(Location start, Location end, DrawingCanvas aCanvas) { // draw the line at its initial position line = new Line(start, end, aCanvas); // activate! start(); } // move the line repeatedly until it falls off screen public void run() { pause(INITIAL_DELAY); // start out with a slow fall, then accelerate double xSpeed = INITIAL_X_SPEED; while ((line.getStart().getX() <= 400) || (line.getEnd().getX() <= 400)) { line.move(xSpeed, 0); xSpeed = xSpeed * 1.1; pause(DELAY_TIME); } line.removeFromCanvas(); } }
import objectdraw.*; import java.awt.*; /* * Rising line segments for the VanishingScribble example * * A simple active object that controls a line that falls up the * canvas and disappears when it goes off the end. * * Jim Teresco, Siena College, CSIS 120, Spring 2011 * The College of Saint Rose, Fall 2013 * * $Id: RightLine.java 2218 2013-10-18 14:06:39Z terescoj $ */ public class RightLine extends ActiveObject { // size and speed of falling lines private static final double INITIAL_Y_SPEED = 0.0001; private static final int DELAY_TIME = 33; private static final int INITIAL_DELAY = 100; // the line controlled by this instance private Line line; // Draw a ball and start it falling. public RightLine(Location start, Location end, DrawingCanvas aCanvas) { // draw the line at its initial position line = new Line(start, end, aCanvas); // activate! start(); } // move the line repeatedly until it falls off screen public void run() { pause(INITIAL_DELAY); // start out with a slow fall, then accelerate double ySpeed = -INITIAL_Y_SPEED; while ((line.getStart().getY() >= 0) || (line.getEnd().getY() >= 0)) { line.move(1, ySpeed); ySpeed = ySpeed * 1.1; pause(DELAY_TIME); } line.removeFromCanvas(); } }
import objectdraw.*; import java.awt.*; /** * Sliding line addition to the VanishingScribble program. * This class adds a feature in which lines slide to left. * csc252. 10.1.13. * * @author (Jotham Zak) */ public class SlidingLine extends ActiveObject { // declare variables private static final double INITIAL_X_SPEED = 0.0001; private static final int DELAY_TIME = 33; private static final int INITIAL_DELAY = 100; private Line line; //draw the line and begin sliding. public SlidingLine(Location start, Location end, DrawingCanvas aCanvas){ line = new Line(start, end, aCanvas); start(); } //move the line until it vanishes public void run(){ pause(INITIAL_DELAY); //acceleration double xSpeed = -INITIAL_X_SPEED; while((line.getStart().getX() >= 0) || (line.getEnd().getX() >= 0)){ line.move(xSpeed, 0); xSpeed = xSpeed * 1.1; pause(DELAY_TIME); } line.removeFromCanvas(); } }