aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Martindale <awiamartindale@googlemail.com>2011-09-02 14:14:09 +0100
committerAdam Martindale <awiamartindale@googlemail.com>2011-09-02 14:14:09 +0100
commitd32662fe2f461a38cc0e99951dfe9f82316a936c (patch)
tree2d615e665173eed6045a6aa512aac1178f9f263c
parent63f8fd609fc2966eb7bf2ddf53a3241f70a02689 (diff)
downloadpunchingbag-d32662fe2f461a38cc0e99951dfe9f82316a936c.tar
punchingbag-d32662fe2f461a38cc0e99951dfe9f82316a936c.tar.gz
Renamed CirclePulsate class and added Draw Ellipse
-rw-r--r--PunchingBag/src/PunchingBag.java67
1 files changed, 46 insertions, 21 deletions
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java
index 2efe903..7e04d33 100644
--- a/PunchingBag/src/PunchingBag.java
+++ b/PunchingBag/src/PunchingBag.java
@@ -2,7 +2,7 @@ import javax.swing.event.EventListenerList;
import java.util.Arrays;
public class PunchingBag implements Runnable {
- private byte[] rawLeds = new byte[6*8];
+ private byte[] rawLeds = new byte[6 * 8];
private Colour[][] leds = new Colour[9][20];
private byte[] ledGridIntensities = new byte[6];
private boolean[][] buttons = new boolean[8][19];
@@ -27,22 +27,25 @@ public class PunchingBag implements Runnable {
public void addButtonListener(ButtonListener l) {
buttonListenerList.add(ButtonListener.class, l);
}
-
- public void setLED(byte x, byte y, Colour colour) {
- leds[x][y] = colour;
+
+ public void setLED(int i, int j, Colour colour) {
+ leds[i][j] = colour;
}
- public void drawRipple(byte x, byte y, byte intensity) {
- new Ripple(x, y, intensity);
+ void CircleExpand(int x, int y, int delay, Colour colour) {
+ for (int i = 0; i <= 15; i++) {
+ DrawEllipse(x, y, i, i, colour);
+
+ }
}
- class Ripple implements Runnable {
+ class CircleExpand implements Runnable {
double currentWidth;
final byte x;
final byte y;
byte intensity;
- public Ripple(byte x, byte y, byte intensity) {
+ public CircleExpand(byte x, byte y, byte intensity) {
this.x = x;
this.y = y;
this.intensity = intensity;
@@ -67,8 +70,8 @@ public class PunchingBag implements Runnable {
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));
+ // 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);
@@ -79,7 +82,7 @@ public class PunchingBag implements Runnable {
currentWidth += 0.1 + (currentWidth / 10);
try {
- Thread.sleep(1000/60);
+ Thread.sleep(1000 / 60);
} catch (InterruptedException e) {
e.printStackTrace();
}
@@ -88,17 +91,38 @@ public class PunchingBag implements Runnable {
}
+ public void DrawEllipse(int x, int y, int radx, int rady, Colour colour) {
+ if (radx == 0 && rady == 0) {
+ setLED(x, y, colour);
+ return;
+ }
+ 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 */
-void CirclePulsate (int x, int y)
-{
-for ( int i= 0 ; i<= 15 ; i++ ) {
-/*matrix. Clear ( ) ;
-matrix. DrawEllipse ( AS1107:: Maxx / x , y ,i,i ) ;
-matrix. Update ( ) ;
-delay ( d ) ;*/
-}
-}
+ 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 */
+
+ e2 = 2 * err;
+ if (e2 < (2 * dx + 1) * b2) {
+ dx++;
+ err += (2 * dx + 1) * b2;
+ }
+ if (e2 > -(2 * dy - 1) * a2) {
+ dy--;
+ err -= (2 * dy - 1) * a2;
+ }
+ } while (dy >= 0);
+
+ while (dx++ < radx) { /* correction for flat ellipses (b=1) */
+ setLED(x + dx, y, colour);
+ setLED(x - dx, y, colour);
+ }
+ }
public void addLEDChangeListener(ButtonListener l) {
ledListenerList.add(ButtonListener.class, l);
@@ -125,7 +149,8 @@ delay ( d ) ;*/
// TODO: Complete and test, or rethink the following?
for (int startY = 0; startY <= 4; startY++) {
for (int y = 0; y <= 3; y++) {
- if (leds[x][startY + (y * 4)] == Colour.Red || leds[x][startY + (y * 4)] == Colour.Yellow) {
+ if (leds[x][startY + (y * 4)] == Colour.Red
+ || leds[x][startY + (y * 4)] == Colour.Yellow) {
rawLeds[(5 * 8) + startY] = (byte) (rawLeds[(int) Math
.floor(y / 4)] | (1 << (7 - x)));
}