From 043763756108f1bad553d260f4b5b2431185dac6 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 2 Sep 2011 14:16:33 +0100 Subject: Implement an effect class to manage stopping and refreshing for the effects. --- PunchingBag/src/PunchingBag.java | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'PunchingBag/src/PunchingBag.java') diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index 2efe903..b179e2f 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -28,6 +28,10 @@ public class PunchingBag implements Runnable { buttonListenerList.add(ButtonListener.class, l); } + public void addLEDChangeListener(LEDListener l) { + ledListenerList.add(LEDListener.class, l); + } + public void setLED(byte x, byte y, Colour colour) { leds[x][y] = colour; } @@ -35,8 +39,32 @@ public class PunchingBag implements Runnable { public void drawRipple(byte x, byte y, byte intensity) { new Ripple(x, y, intensity); } + + class Effect implements Runnable { + boolean stop = false; + int refreshRate = 60; // Times per second to refresh + + public void stop() { + stop = true; + } + + public void run() { + while (!stop) { + draw(); + try { + Thread.sleep(1000/60); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + private void draw() { + + } + } - class Ripple implements Runnable { + class Ripple extends Effect { double currentWidth; final byte x; final byte y; @@ -100,10 +128,6 @@ delay ( d ) ;*/ } } - public void addLEDChangeListener(ButtonListener l) { - ledListenerList.add(ButtonListener.class, l); - } - private void calculateRawLeds() { for (int y = 0; y <= 18; y++) { for (int x = 0; x <= 6; x++) { -- cgit v1.2.3