aboutsummaryrefslogtreecommitdiff
path: root/PunchingBag
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2011-09-12 16:20:11 +0100
committerChristopher Baines <cbaines8@gmail.com>2011-09-12 16:20:11 +0100
commit0e1a25d62e358f017faf6ee9735a668161dc640d (patch)
tree69e04d777f8d0b7dde21cc2a90945285de5bbe2d /PunchingBag
parent7d06a1bb2ef15c57766886831f47fdc83519e6de (diff)
downloadpunchingbag-0e1a25d62e358f017faf6ee9735a668161dc640d.tar
punchingbag-0e1a25d62e358f017faf6ee9735a668161dc640d.tar.gz
Improving the ripple
Diffstat (limited to 'PunchingBag')
-rw-r--r--PunchingBag/src/PunchingBag.java81
-rw-r--r--PunchingBag/src/PunchingBagGUI.java4
2 files changed, 52 insertions, 33 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);
diff --git a/PunchingBag/src/PunchingBagGUI.java b/PunchingBag/src/PunchingBagGUI.java
index 5ba30a8..03e8f97 100644
--- a/PunchingBag/src/PunchingBagGUI.java
+++ b/PunchingBag/src/PunchingBagGUI.java
@@ -534,8 +534,8 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener,
@Override
public void buttonPressed(int x, int y) {
System.out.println("Button Pressed: " + x + " " + y);
- //bag.circleExpand(x, y, 16);
- bag.setLED(x, y, PunchingBag.Colour.Red);
+ bag.circleExpand(x, y, 16);
+ //bag.setLED(x, y, PunchingBag.Colour.Red);
//bag.noise(new Rectangle(0, 0, 9, 20), 5000);
/*for (int bx=0; bx<bag.ledWidth; bx++) {
for (int by=0; by<bag.ledHeight; by++) {