aboutsummaryrefslogtreecommitdiff
path: root/PunchingBag/src/PunchingBag.java
diff options
context:
space:
mode:
Diffstat (limited to 'PunchingBag/src/PunchingBag.java')
-rw-r--r--PunchingBag/src/PunchingBag.java81
1 files changed, 50 insertions, 31 deletions
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java
index e5b8011..f27738f 100644
--- a/PunchingBag/src/PunchingBag.java
+++ b/PunchingBag/src/PunchingBag.java
@@ -158,16 +158,16 @@ public class PunchingBag implements Runnable {
}
class CircleExpand extends Effect {
- final int x;
- final int y;
+ final double x;
+ final double y;
int intensity;
boolean drawnSomething = true;
- float currentRadius = 0;
+ double currentRadius = 0.5;
public CircleExpand(int x, int y, int intensity) {
- this.x = x;
- this.y = y;
+ this.x = x + 0.5;
+ this.y = y + 0.5;
this.intensity = intensity;
}
@@ -184,13 +184,12 @@ public class PunchingBag implements Runnable {
intensity -= 5;
- currentRadius += 0.1 + 0.1 + (currentRadius / 20);
+ currentRadius += 0.2 + (currentRadius / 20);
// currentRadius += 0.01;
// longhand: currentRadius = currentRadius + 0.1 + (currentRadius /
// 10);
- if (!drawEllipse(x, y, (int) currentRadius, (int) currentRadius,
- colour))
+ if (!drawCircle(x, y, currentRadius, colour))
stop = true;
}
@@ -386,7 +385,24 @@ public class PunchingBag implements Runnable {
}
return doneSomething;
}
-
+
+ public boolean drawCircle(double x, double y, double radius, Colour colour) {
+ boolean drawnSomething = false;
+ int px;
+ int py;
+ for (double i = 0; i < 360; i++) {
+ px = (int) (x + Math.round(radius * Math.cos(i)));
+ py = (int) (y + Math.round(radius * Math.sin(i)));
+
+ if (x >= 0 && x <= 8 && y >= 0 && y <= 19) {
+ if (setLEDInternal(px, py, colour)) {
+ drawnSomething = true;
+ }
+ }
+ }
+ return drawnSomething;
+ }
+
public boolean rectfill(int x, int y, int height, int width, Colour colour) {
if (height < 0) {
height = 0;
@@ -396,36 +412,39 @@ public class PunchingBag implements Runnable {
}
if (width == 0 && height == 0) {
return setLEDInternal(x, y, colour);
-
+
}
-
- boolean doneSomething = false;
-
+
+ boolean doneSomething = false;
+
return doneSomething;
-
+
}
private void calculateRawLeds() {
// First clear everything
Arrays.fill(rawLeds, (byte) 0);
// First loop through the 5 easy arrays
- for (int grid=0; grid<5; grid++) {
+ for (int grid = 0; grid < 5; grid++) {
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
if ((y % 2) == 0) {
- if (leds[1 + x][(grid * 4) + (y/2)] == Colour.Green || leds[1 + x][(grid * 4) + (y/2)] == Colour.Yellow ) {
- rawLeds[(grid*8) + x] = (byte) (rawLeds[(grid*8) + x] | (1 << (7-y)));
+ if (leds[1 + x][(grid * 4) + (y / 2)] == Colour.Green
+ || leds[1 + x][(grid * 4) + (y / 2)] == Colour.Yellow) {
+ rawLeds[(grid * 8) + x] = (byte) (rawLeds[(grid * 8)
+ + x] | (1 << (7 - y)));
}
} else {
- if (leds[1 + x][(grid * 4) + (y/2)] == Colour.Red || leds[1 + x][(grid * 4) + (y/2)] == Colour.Yellow ) {
- rawLeds[(grid*8) + x] = (byte) (rawLeds[(grid*8) + x] | (1 << (7-y)));
+ if (leds[1 + x][(grid * 4) + (y / 2)] == Colour.Red
+ || leds[1 + x][(grid * 4) + (y / 2)] == Colour.Yellow) {
+ rawLeds[(grid * 8) + x] = (byte) (rawLeds[(grid * 8)
+ + x] | (1 << (7 - y)));
}
}
}
}
}
-
/*
* for (int y = 0; y <= 18; y++) { for (int x = 0; x <= 6; x++) { if ((y
* % 2) == 0) { if (leds[x][y] == Colour.Green || leds[x][y] ==
@@ -548,13 +567,13 @@ public class PunchingBag implements Runnable {
buttonsChanged = true;
}
}
-
+
private void printByte(byte b) {
- //System.out.println("Byte: " + b);
+ // System.out.println("Byte: " + b);
String str;
for (int j = 0; j < 8; j++) {
- byte val = (byte) (b & (1 << (7-j)));
- //System.out.println("Val: " + val + " " + (1 << (7-j)));
+ byte val = (byte) (b & (1 << (7 - j)));
+ // System.out.println("Val: " + val + " " + (1 << (7-j)));
if (val > 0) {
str = "1";
} else {
@@ -563,7 +582,7 @@ public class PunchingBag implements Runnable {
System.out.print(str);
}
}
-
+
private void printlnByte(byte b) {
printByte(b);
System.out.println("");
@@ -608,7 +627,7 @@ public class PunchingBag implements Runnable {
// sb.append((char) read);
}
// System.out.println("");
- //readAccelData(str);
+ // readAccelData(str);
// String[] nums = sbString.trim().split(" ");
// System.out.println(nums);
// for (int x=0; x<4; x++) {
@@ -638,13 +657,13 @@ public class PunchingBag implements Runnable {
calculateRawLeds();
String str;
for (int i = 0; i < (6 * 8); i++) {
- //printByte(rawLeds[i]);
+ // printByte(rawLeds[i]);
}
- //System.out.println("");
-
- //Arrays.fill(rawLeds, (byte) -42);
+ // System.out.println("");
+
+ // Arrays.fill(rawLeds, (byte) -42);
if (ledArduino.out != null) {
- //calculateRawLeds();
+ // calculateRawLeds();
try {
ledArduino.write(((byte) 108));
ledArduino.write(rawLeds);