The Story: (click on the red words)
``Once I saw a house. When I went into the house I found a present. When I opened the present, I found a TV set. And what do you know ... the TV was showing a little story about a house!''
The Java Program: import java.awt.*; public class Story extends GenericApplet { int n = 0, S = 60; int I[][] = {{-1, 0, 0, 1},{ 0,0,-1,1},{-2,-1, 1, 2},{-1, 0, 0, 1}}; int J[][] = {{-1,-2,-2,-1},{-1,1, 0,0},{-2,-1,-1,-2},{-2,-1,-1,-2}}; public void render(Graphics g) { if (S <= 60) { // While still zooming: int width = bounds().width , x = width /2; int height = bounds().height, y = height/2; g.setColor(Color.white); g.fillRect(0, 0, width, height); // clear the background, g.setColor(Color.black); g.drawRect(x - S, y - S, 2*S, 2*S); // draw box and lines, g.drawLine(x+S*I[n][0],y+S*J[n][0],x+S*I[n][1],y+S*J[n][1]); g.drawLine(x+S*I[n][2],y+S*J[n][2],x+S*I[n][3],y+S*J[n][3]); S++; // increment the scale. } } public void doClick(int i) { // on user signal: n = i; // set image state S = 1; // set scale=1 to restart } } |