-
Notifications
You must be signed in to change notification settings - Fork 0
/
LED.java
66 lines (58 loc) · 1.91 KB
/
LED.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/** LED is an AWT widget, written for use in the ochre applet.
It simulates a rectangular LED (no, not the seven segment kind) which
displays information via brightness.*/
import java.awt.*;
public class LED extends Canvas {
private int boundwidth, boundheight;
private int viswidth, visheight;
private float hue, sat, bright;
/** The default constructor. Creates a 40x40 LED widget, with a "visible"
dimension of 40x20 centered in the middle. The color is red, with 90%
saturation.
@returns LED object
*/
public LED() {
this(40,40,40,20,0.01f,0.9f);
}
/**The main constructor.
@param tboundwidth The width (in pixels) of the widget.
@param tboundheight The height (in pixels) of the widget.
@param tviswidth The width (in pixels) of the actual light.
@param tvisheight The height (in pixels) of the actual light.
@param thue The hue of the LED. Ranges from 0.0 (red) to 1.0 (violet)
@param tsat The saturation of the LED. Ranges from 0.0 (grayish) to 1.0
(fully saturated).
@return LED object with the given properties.
*/
public LED(int tboundwidth, int tboundheight,
int tviswidth, int tvisheight, float thue, float tsat) {
super();
boundwidth=tboundwidth;
boundheight=tboundheight;
viswidth=tviswidth;
visheight=tvisheight;
hue=thue;
sat=tsat;
bright=0;
reshape(0,0,boundwidth,boundheight);
}
/**Sets the brightness of the LED.
@param tbright Brightness, ranging from 0.0 to 1.0.
*/
public void setLED(double tbright) {
bright=(float)tbright;
repaint();
}
/**Paints the LED AWT widget.
@param g Graphics object
*/
public void paint(Graphics g) {
g.setColor(Color.getHSBColor(hue,sat,bright));
g.fill3DRect(((boundwidth-viswidth)/2),((boundheight-visheight)/2),
viswidth,visheight,true);
}
/**Updates the LED AWT widget. This method simply calls paint.
@param g Graphics object
*/
public void update(Graphics g) { paint(g); }
}