Constructor
# new LED(parent, x, y, label, color, lit)
Constructor
Parameters:
Name | Type | Description |
---|---|---|
parent |
HTMLElement | The element to add this LED to. |
x |
number | The x position of the LED. Default 0. |
y |
number | The y position of the LED. Default 0. |
label |
string | The text of the label of the LED. Default empty string. |
color |
string | The color of the LED. Default #f00. |
lit |
boolean | The initial lit state of the LED. Default false. |
Example
const panel = new Panel(document.body, 20, 20, 240, 240);
const canvas = new LED(panel, 20, 20, "LED", "#f00", true);
Extends
Classes
Members
# (static) color
Default color of all LEDs.
# (static) labelPosition
Default labelPosition of all LEDs.
# (static) size
Default size of all LEDs.
# color
Gets whether or not the LED is blinking.
get blinking() {
return this.getBlinking();
}
/**
Gets and sets the color of the LED.
# enabled
Sets and gets whether or not this component is enabled. Non-enabled components will be faded out and not respond to events.
- Overrides:
- Source:
# height
Sets and gets the height of this component.
- Overrides:
- Source:
# label
Gets and sets the text of the LED's text label.
# labelPosition
Gets and sets the position of the text label displayed on the LED. Valid values are "top" (default), "left", "right" and "bottom".
# lit
Gets and sets whether or not this LED is lit.
# width
Sets and gets the width of this component.
- Overrides:
- Source:
# x
Sets and gets the x position of this component.
- Overrides:
- Source:
# y
Sets and gets the y position of this component.
- Overrides:
- Source:
Methods
# blink(bps)
Starts the LED blinking at a specified or default rate.
Parameters:
Name | Type | Description |
---|---|---|
bps |
number | Blinks per second. Defaults to 2 blinks per second if no parameter is given. |
Returns:
This instance, suitable for chaining.
# getBlinking()
Returns:
whether or not the LED is blinking.
# getColor()
Returns:
the color of the LED.
# getEnabled()
Gets whether the component is enabled.
- Overrides:
- Source:
Returns:
Whether or not the component is enabled.
# getHeight()
Gets the height of the component.
- Overrides:
- Source:
Returns:
The height of the component.
# getLabel()
Returns:
the text in the label.
# getLabelPosition()
Returns:
the label position (top, left, right or bottom).
# getLit()
Returns:
whether or not the LED is lit.
# getWidth()
Gets the width of the component.
- Overrides:
- Source:
Returns:
The width of the component.
# getX()
Gets the x position of the component.
- Overrides:
- Source:
Returns:
The x position of the component.
# getY()
Gets the y position of the component.
- Overrides:
- Source:
Returns:
The y position of the component.
# move(x, y)
Moves the component to a specified position.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The new x position of the component. |
y |
number | The new y position of the component. |
- Overrides:
- Source:
Returns:
This instance, suitable for chaining.
# rotate(rad)
Rotates the component.
Parameters:
Name | Type | Description |
---|---|---|
rad |
number | The number of radians to rotate the component by. |
- Overrides:
- Source:
Returns:
This instance, suitable for chaining.
# rotateDeg(deg)
Rotates the component.
Parameters:
Name | Type | Description |
---|---|---|
deg |
number | The number of degrees to rotate the component by. |
- Overrides:
- Source:
Returns:
This instance, suitable for chaining.
# setColor(color)
Sets the color of this LED.
Parameters:
Name | Type | Description |
---|---|---|
color |
string | The color to set. |
Returns:
This instance, suitable for chaining.
# setEnabled(enabled)
Sets the enabled state of this component.
Parameters:
Name | Type | Description |
---|---|---|
enabled |
boolean | Whether or not the component will be enabled. |
- Overrides:
- Source:
Returns:
This instance, suitable for chaining.
# setHeight(height)
Sets the height of this component.
Parameters:
Name | Type | Description |
---|---|---|
height |
number | The height of this component. |
- Overrides:
- Source:
Returns:
This instance, suitable for chaining.
# setLabel(label)
Sets the label of this LED.
Parameters:
Name | Type | Description |
---|---|---|
label |
string | The label to set on this LED. |
Returns:
this instance, suitable for chaining.
# setLabelPosition(position)
Sets the text position of the text label.
Parameters:
Name | Type | Description |
---|---|---|
position |
string | The position to place the text lable: "top" (default), "left", "right" or "bottom". |
Returns:
this instance, suitable for chaining.
# setLit(lit)
Sets whether this LED is lit up.
Parameters:
Name | Type | Description |
---|---|---|
lit |
boolean | Whether or not the LED is lit. |
Returns:
This instance, suitable for chaining.
# setSize(width, height)
Sets the size of the LED. Because an LED will always be round, if you try to set width and height to different values, they will be set to the smallest value of the two.
Parameters:
Name | Type | Description |
---|---|---|
width |
number | The width of the LED. |
height |
number | The height of the LED. |
- Overrides:
Returns:
This instance, suitable for chaining.
# setWidth(width)
Sets the width of this component.
Parameters:
Name | Type | Description |
---|---|---|
width |
number | The width of this component. |
- Overrides:
- Source:
Returns:
This instance, suitable for chaining.
# setX(x)
Sets the x position of this component.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x position of this component. |
- Overrides:
- Source:
Returns:
This instance, suitable for chaining.
# setY(y)
Sets the y position of this component.
Parameters:
Name | Type | Description |
---|---|---|
y |
number | The y position of this component. |
- Overrides:
- Source:
Returns:
this instance, suitable for chaining.
# stop()
Stops the LED blinking and turns it off.
Returns:
This instance, suitable for chaining.