Back to index

plt-scheme  4.2.1
draw-world-close-canvas.java
Go to the documentation of this file.
00001 /*  Let's have a second canvas into which the world can draw. 
00002     See whether it interferes. 
00003 */
00004 
00005 import draw.*;
00006 import colors.*;
00007 import geometry.*;
00008 
00009 // can I close the canvas of a world? 
00010 class SW extends World {
00011  int x = 50; 
00012  int y;
00013  AColor red = new Red();
00014  AColor white = new White();
00015  
00016  SW(int v) { y = v; }
00017 
00018  boolean go() { return this.bigBang(100,100,.1); }
00019  
00020  World onTick() { return new SW(this.y+1); }
00021 
00022  World onKeyEvent(String ke) { 
00023   if (ke.equals("s"))
00024    return this.endOfWorld("the end");
00025   else if (ke.equals("*"))
00026    return new SW(99);
00027   else 
00028    return this; 
00029  }
00030 
00031  boolean draw() { return this.theCanvas.drawDisk(new Posn(this.x,this.y),3,red); }
00032  
00033  boolean erase() { return this.theCanvas.drawRect(new Posn(0,0),100,100,white); }
00034 }
00035 
00036 class Example {
00037   SW sw = new SW(10);
00038   boolean tst1 = sw.go();
00039 }