examples added for draw/idraw Canvases in htdch
svn: r3866
This commit is contained in:
parent
04e4477b20
commit
09ae4070ea
44
collects/htdch/Examples/draw-multiple-canvas.ss
Normal file
44
collects/htdch/Examples/draw-multiple-canvas.ss
Normal file
|
@ -0,0 +1,44 @@
|
|||
import draw.*;
|
||||
import colors.*;
|
||||
import geometry.*;
|
||||
|
||||
class Example {
|
||||
Canvas create(int w, int h, Color bg) {
|
||||
Canvas c = new Canvas(w,h);
|
||||
boolean tstC = c.show();
|
||||
boolean tstCDraw = c.drawRect(new Posn(0,0),w,h,bg);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
class Example1 extends Example {
|
||||
Canvas c = create(100,200,new Black());
|
||||
Canvas d = create(200,100,new White());
|
||||
|
||||
boolean tst = c.close();
|
||||
|
||||
String result = "the white 200 x 100 canvas is visible; the black one has disappeared";
|
||||
}
|
||||
|
||||
class Example2 extends Example {
|
||||
Canvas c = create(100,200,new Blue());
|
||||
Canvas d = create(200,100,new Red());
|
||||
|
||||
boolean tst = d.close();
|
||||
|
||||
String result = "the blue canvas is visible; the green one has disappeared";
|
||||
}
|
||||
|
||||
class Example3 extends Example {
|
||||
Canvas c = create(100,100,new Green());
|
||||
String sc = "a green 100 x 100 canvas pops up";
|
||||
|
||||
Canvas d = create(200,200,new Black());
|
||||
String sd = "a black 200 x 200 canvas pops up";
|
||||
|
||||
boolean tst = c.close();
|
||||
String st = "the green screen has disappeared";
|
||||
boolean tst2 = c.show();
|
||||
String result = "the black canvas is visible; a second white one (of 100 x 100) is visible";
|
||||
}
|
||||
|
36
collects/htdch/Examples/draw-multiple-worlds.ss
Normal file
36
collects/htdch/Examples/draw-multiple-worlds.ss
Normal file
|
@ -0,0 +1,36 @@
|
|||
import draw.*;
|
||||
import colors.*;
|
||||
import geometry.*;
|
||||
|
||||
class SW extends World {
|
||||
int x = 50;
|
||||
int y;
|
||||
int low;
|
||||
Color c;
|
||||
Color white = new White();
|
||||
|
||||
SW(int y, int low, Color c) { this.y = y; this.low = low; this.c = c; }
|
||||
|
||||
boolean go() { return this.bigBang(100,100,.1); }
|
||||
|
||||
World onTick() {
|
||||
if (y >= low)
|
||||
return endOfWorld();
|
||||
else
|
||||
return new SW(this.y+1,this.low,this.c);
|
||||
}
|
||||
|
||||
World onKeyEvent(String ke) { return this; }
|
||||
|
||||
boolean draw() { return this.theCanvas.drawDisk(new Posn(this.x,this.y),3,c); }
|
||||
|
||||
boolean erase() { return this.theCanvas.drawRect(new Posn(0,0),100,100,white); }
|
||||
}
|
||||
|
||||
class Example {
|
||||
SW sw1 = new SW(10,40,new Red());
|
||||
SW sw2 = new SW(10,90,new Green());
|
||||
boolean tst1 = sw1.go();
|
||||
boolean tst2 = sw2.go();
|
||||
String result = "two worlds, green goes to bottom, red goes to center";
|
||||
}
|
39
collects/htdch/Examples/draw-world-close-canvas.ss
Normal file
39
collects/htdch/Examples/draw-world-close-canvas.ss
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* Let's have a second canvas into which the world can draw.
|
||||
See whether it interferes.
|
||||
*/
|
||||
|
||||
import draw.*;
|
||||
import colors.*;
|
||||
import geometry.*;
|
||||
|
||||
// can I close the canvas of a world?
|
||||
class SW extends World {
|
||||
int x = 50;
|
||||
int y;
|
||||
Color red = new Red();
|
||||
Color white = new White();
|
||||
|
||||
SW(int v) { y = v; }
|
||||
|
||||
boolean go() { return this.bigBang(100,100,.1); }
|
||||
|
||||
World onTick() { return new SW(this.y+1); }
|
||||
|
||||
World onKeyEvent(String ke) {
|
||||
if (ke.equals("s"))
|
||||
return this.endOfWorld();
|
||||
else if (ke.equals("*"))
|
||||
return new SW(99);
|
||||
else
|
||||
return this;
|
||||
}
|
||||
|
||||
boolean draw() { return this.theCanvas.drawDisk(new Posn(this.x,this.y),3,red); }
|
||||
|
||||
boolean erase() { return this.theCanvas.drawRect(new Posn(0,0),100,100,white); }
|
||||
}
|
||||
|
||||
class Example {
|
||||
SW sw = new SW(10);
|
||||
boolean tst1 = sw.go();
|
||||
}
|
Loading…
Reference in New Issue
Block a user