diff options
author | Christopher Baines <cbaines8@gmail.com> | 2011-09-02 17:26:16 +0100 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2011-09-02 17:26:16 +0100 |
commit | 00f3c6adc3e971aab992edaa05afcc86ca7f33b9 (patch) | |
tree | 9081acc82102d6f9a52feb8851d574cd147059c9 | |
parent | fca8c8c1f8b0dc2febd1b1cfba6ffc4ab46da026 (diff) | |
parent | 79c99b7403d40e984a7cfb42a4148b6e3f1f8179 (diff) | |
download | punchingbag-00f3c6adc3e971aab992edaa05afcc86ca7f33b9.tar punchingbag-00f3c6adc3e971aab992edaa05afcc86ca7f33b9.tar.gz |
Resolved SetLED
Merge branch 'master' of gitorious.org:punchingbag/punchingbag
Conflicts:
PunchingBag/src/PunchingBag.java
-rw-r--r-- | PunchingBag/src/PunchingBag.java | 78 |
1 files changed, 45 insertions, 33 deletions
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index 8ea984e..00a5866 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -8,8 +8,10 @@ import java.util.Iterator; public class PunchingBag implements Runnable { boolean ledsChanged = false; + final public int ledHeight = 20; + final public int ledWidth = 9; private byte[] rawLeds = new byte[6 * 8]; - private Colour[][] leds = new Colour[9][20]; + private Colour[][] leds = new Colour[ledWidth][ledHeight]; private byte[] ledGridIntensities = new byte[6]; private boolean[][] buttons = new boolean[8][19]; @@ -41,10 +43,16 @@ public class PunchingBag implements Runnable { ledListenerList.add(LEDListener.class, l); } - public void setLED(int i, int j, Colour colour) { - if (leds[i][j] != colour) { - ledsChanged = true; - leds[i][j] = colour; + public boolean setLED(int x, int y, Colour colour) { + if (x >= 0 && x < ledWidth && y >= 0 && y < ledHeight) { + if (leds[x][y] != colour) { + leds[x][y] = colour; + ledsChanged = true; + + } + return true; + } else { + return false; } } @@ -78,12 +86,13 @@ public class PunchingBag implements Runnable { } class CircleExpand extends Effect { - double currentWidth; final byte x; final byte y; byte intensity; boolean drawnSomething = true; + float currentRadius = 0; + public CircleExpand(byte x, byte y, byte intensity) { this.x = x; this.y = y; @@ -102,42 +111,41 @@ public class PunchingBag implements Runnable { colour = Colour.Green; } - drawnSomething = false; - - for (double i = 0; i < 360; i++) { - // int x = x + (int) Math.round(currentWidth * Math.cos(i)); - // int y = y + (int) Math.round(currentWidth * Math.sin(i)); - - if (x >= 0 && x <= 8 && y >= 0 && y <= 19) { - setLED(x, y, colour); - drawnSomething = true; - } - - } - - currentWidth += 0.1 + (currentWidth / 10); + currentRadius += 0.1 + (currentRadius / 10); + // longhand: currentRadius = currentRadius + 0.1 + (currentRadius / + // 10); - if (!drawnSomething) + if (!DrawEllipse(2, 4, (int) currentRadius, (int) currentRadius, + colour)) stop = true; } } - public void DrawEllipse(int x, int y, int radx, int rady, Colour colour) { + public boolean DrawEllipse(int x, int y, int radx, int rady, Colour colour) { if (radx == 0 && rady == 0) { - setLED(x, y, colour); - return; + return setLED(x, y, colour); } + boolean doneSomething = false; + int dx = 0, dy = rady; /* first quadrant from top left to bottom right */ int a2 = radx * radx, b2 = rady * rady; int err = b2 - (2 * rady - 1) * a2, e2; /* error value in the first step */ do { - setLED(x + dx, y + dy, colour); /* I. Quadrant */ - setLED(x - dx, y + dy, colour); /* II. Quadrant */ - setLED(x - dx, y - dy, colour); /* III. Quadrant */ - setLED(x + dx, y - dy, colour); /* IV. Quadrant */ + if (setLED(x + dx, y + dy, colour)) {/* I. Quadrant */ + doneSomething = true; + } + if (setLED(x - dx, y + dy, colour)) {/* II. Quadrant */ + doneSomething = true; + } + if (setLED(x - dx, y - dy, colour)) {/* III. Quadrant */ + doneSomething = true; + } + if (setLED(x + dx, y - dy, colour)) {/* IV. Quadrant */ + doneSomething = true; + } e2 = 2 * err; if (e2 < (2 * dx + 1) * b2) { @@ -151,9 +159,14 @@ public class PunchingBag implements Runnable { } while (dy >= 0); while (dx++ < radx) { /* correction for flat ellipses (b=1) */ - setLED(x + dx, y, colour); - setLED(x - dx, y, colour); + if (setLED(x + dx, y, colour)) { + doneSomething = true; + } + if (setLED(x - dx, y, colour)) { + doneSomething = true; + } } + return doneSomething; } private void calculateRawLeds() { @@ -209,8 +222,8 @@ public class PunchingBag implements Runnable { public void run() { while (true) { if (ledsChanged) { - LEDListeners = - ledListenerList. + //LEDListeners = + //ledListenerList. } try { @@ -220,5 +233,4 @@ public class PunchingBag implements Runnable { } } } - } |