From f5f7d3ca20f102e704f8d0705158ea58a3e4c305 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 2 Sep 2011 11:09:46 +0100 Subject: Changed stuff. Like things. --- PunchingBag/src/PunchingBag.java | 99 +++++++++++++++++++++++++++++++++------- 1 file changed, 82 insertions(+), 17 deletions(-) (limited to 'PunchingBag/src/PunchingBag.java') diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index 278a8fc..7629afe 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -1,24 +1,89 @@ -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; import javax.swing.event.EventListenerList; - public class PunchingBag { protected EventListenerList listenerList = new EventListenerList(); - - /** - * Adds an ActionListener to the button. - * @param l the ActionListener to be added - */ - public void addButtonListener(ButtonListener l) { - listenerList.add(ButtonListener.class, l); - } - - public void setLED(byte x, byte y, byte intensity) { - - + + enum Colour { + None, Red, Yellow, Green + }; + + /** + * Adds an ActionListener to the button. + * + * @param l + * the ActionListener to be added + */ + public void addButtonListener(ButtonListener l) { + listenerList.add(ButtonListener.class, l); + } + + public void setLED(byte x, byte y, byte intensity) { + + } + + public void drawRipple(byte x, byte y, byte intensity) { + new Ripple(x, y, intensity); } + class Ripple implements Runnable { + double currentWidth; + final byte x; + final byte y; + byte intensity; + + public Ripple(byte x, byte y, byte intensity) { + this.x = x; + this.y = y; + this.intensity = intensity; + new Thread(this).start(); + } + + @Override + public void run() { + Colour colour; + boolean drawnSomething = true; + + while (drawnSomething) { + + if (intensity >= 10) { + colour = Colour.Red; + } else if (intensity >= 5) { + colour = Colour.Yellow; + } else { + 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); + try { + Thread.sleep(1000/60); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + } + +} + +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 ) ; } -- cgit v1.2.3