1 package sample;
2
3 import java.util.Timer;
4 import java.util.TimerTask;
5 import java.util.Random;
6
7 import fi.jyu.mit.graphics.*;
8
9
10
11
15 public class ColorChangeSample {
16
21 public static class ColorChanger extends TimerTask {
22 private final Drawable shape;
23 private int r = 0;
24 private final Random rand = new Random();
25
26
31 public ColorChanger(Drawable shape,long dt) {
32 super();
33 this.shape = shape;
34 new Timer().schedule(this,dt,dt);
35 }
36
37
41 @Override
42 public void run() {
43 r = (r+10) % 256;
44 shape.setColor(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
45 }
46 }
47
48
52 @SuppressWarnings("unused")
53 public static void main(String[] args) {
54 EasyWindow window = new EasyWindow();
55 Line line = window.addLine(0,0,100,100);
56 window.showWindow();
57 new ColorChanger(line,120);
58
59 Line line2 = window.addLine(0,0, 150,0);
60 line2.setTransform(new TranslateMatrix(100,100,0));
61 new Rotator(line2,Axis.Z,1,50);
62 }
63
64 }
65