Skip to content

Commit 12c81ff

Browse files
committed
fix: Low LED brightness levels are indistinguishable #4
1 parent b594618 commit 12c81ff

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/led-element.stories.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ storiesOf('LED', module)
9595
() =>
9696
html`
9797
<wokwi-led color="red" label="0" .value=${true} brightness="0"></wokwi-led>
98+
<wokwi-led color="red" label="1%" .value=${true} brightness="0.01"></wokwi-led>
9899
<wokwi-led color="red" label="10%" .value=${true} brightness="0.1"></wokwi-led>
99100
<wokwi-led color="red" label="25%" .value=${true} brightness="0.25"></wokwi-led>
100101
<wokwi-led color="red" label="50%" .value=${true} brightness="0.5"></wokwi-led>

src/led-element.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class LEDElement extends LitElement {
4444
const { color, lightColor } = this;
4545
const lightColorActual = lightColor || lightColors[color] || '#ff8080';
4646
const opacity = this.brightness ? 0.3 + this.brightness * 0.7 : 0;
47+
const lightOn = this.value && this.brightness > Number.EPSILON;
4748
return html`
4849
<div class="led-container">
4950
<svg
@@ -54,7 +55,7 @@ export class LEDElement extends LitElement {
5455
xmlns="http://www.w3.org/2000/svg"
5556
>
5657
<filter id="light1" x="-0.8" y="-0.8" height="2.2" width="2.8">
57-
<feGaussianBlur stdDeviation="2.6" />
58+
<feGaussianBlur stdDeviation="2" />
5859
</filter>
5960
<filter id="light2" x="-0.8" y="-0.8" height="2.2" width="2.8">
6061
<feGaussianBlur stdDeviation="4" />
@@ -116,20 +117,26 @@ export class LEDElement extends LitElement {
116117
opacity=".5"
117118
/>
118119
</g>
119-
<g
120-
class="light"
121-
xmlns="http://www.w3.org/2000/svg"
122-
style="display: ${this.value ? '' : 'none'}; opacity: ${opacity}"
123-
>
120+
<g class="light" style="display: ${lightOn ? '' : 'none'}">
124121
<ellipse
125122
cx="8"
126123
cy="10"
127124
rx="10"
128125
ry="10"
129126
fill="${lightColorActual}"
130127
filter="url(#light2)"
128+
style="opacity: ${opacity}"
129+
></ellipse>
130+
<ellipse cx="8" cy="10" rx="2" ry="2" fill="white" filter="url(#light1)"></ellipse>
131+
<ellipse
132+
cx="8"
133+
cy="10"
134+
rx="3"
135+
ry="3"
136+
fill="white"
137+
filter="url(#light1)"
138+
style="opacity: ${opacity}"
131139
></ellipse>
132-
<ellipse cx="8" cy="10" rx="3" ry="3" fill="white" filter="url(#light1)"></ellipse>
133140
</g>
134141
</svg>
135142
<span class="led-label">${this.label}</span>

0 commit comments

Comments
 (0)