Back to index

plt-scheme  4.2.1
draw-multiple-worlds.java
Go to the documentation of this file.
00001 import draw.*;
00002 import colors.*;
00003 import geometry.*;
00004 
00005 class SW extends World {
00006  int x = 50; 
00007  int y;
00008  int low; 
00009  AColor c;
00010  AColor white = new White();
00011  
00012  SW(int y, int low, AColor c) { this.y = y; this.low = low; this.c = c; }
00013 
00014  boolean go() { return this.bigBang(100,100,.1); }
00015  
00016  World onTick() { 
00017   if (y >= low)
00018     return endOfWorld("the end");
00019   else
00020    return new SW(this.y+1,this.low,this.c); 
00021  }
00022 
00023  World onKeyEvent(String ke) { return this; }
00024 
00025  boolean draw() { return this.theCanvas.drawDisk(new Posn(this.x,this.y),3,c); }
00026  
00027  boolean erase() { return this.theCanvas.drawRect(new Posn(0,0),100,100,white); }
00028 }
00029 
00030 class Example {
00031   SW sw1 = new SW(10,40,new Red());
00032   SW sw2 = new SW(10,90,new Green());
00033   boolean tst1 = sw1.go();
00034   boolean tst2 = sw2.go();
00035   String result = "two worlds, green goes to bottom, red goes to center";
00036 }