Skip to content

Commit 2dba715

Browse files
committed
Remove gradient if led is off
1 parent efe32bb commit 2dba715

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/view/components/clue/ClueSimulator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { sendMessage } from "../../utils/MessageUtils";
1212
import ActionBar from "../simulator/ActionBar";
1313
import { BUTTONS_KEYS, ClueImage } from "./ClueImage";
1414

15-
const DEFAULT_CLUE_STATE: IClueState = {
15+
export const DEFAULT_CLUE_STATE: IClueState = {
1616
buttons: { button_a: false, button_b: false },
1717
displayMessage: DEFAULT_IMG_CLUE,
1818
neopixel: [0, 0, 0]

src/view/components/clue/Clue_svg.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33

44
import * as React from "react";
55
import "../../styles/Clue.css";
6+
import { DEFAULT_CLUE_STATE } from "./ClueSimulator";
67
export interface IRefObject {
78
[key: string]: React.RefObject<SVGRectElement>;
89
}
910
interface IProps {
1011
displayImage: string;
1112
neopixel: number[]
1213
}
13-
14+
const LED_TINT_FACTOR = 0.5
1415
export class ClueSvg extends React.Component<IProps, {}> {
1516
private svgRef: React.RefObject<SVGSVGElement> = React.createRef();
1617
private neopixel: React.RefObject<SVGCircleElement> = React.createRef()
@@ -35,6 +36,8 @@ export class ClueSvg extends React.Component<IProps, {}> {
3536
}
3637
componentDidMount() {
3738
this.updateDisplay();
39+
this.updateNeopixel()
40+
3841
}
3942
componentDidUpdate() {
4043
this.updateDisplay();
@@ -46,7 +49,7 @@ export class ClueSvg extends React.Component<IProps, {}> {
4649
<div className="microbit-svg">
4750
<svg
4851
xmlns="http://www.w3.org/2000/svg"
49-
viewBox="0 0 350 250.98"
52+
viewBox="0 0 375 250.98"
5053
ref={this.svgRef}
5154
x="0px"
5255
y="0px"
@@ -55,7 +58,7 @@ export class ClueSvg extends React.Component<IProps, {}> {
5558
>
5659
<defs >
5760
<radialGradient id="grad1" cx="50%" cy="50%" r="70%" fx="50%" fy="50%" >
58-
<stop offset="0%" stopColor="rgb(0,0,255)" stopOpacity="1" ref={this.pixelStopGradient} />
61+
<stop offset="0%" stopColor="rgb(0,0,0)" stopOpacity="1" ref={this.pixelStopGradient} />
5962
<stop offset="100%" stopOpacity="0" />
6063
</radialGradient></defs>
6164
<g id="Green">
@@ -944,8 +947,8 @@ export class ClueSvg extends React.Component<IProps, {}> {
944947
rx="18.28"
945948
/>
946949
</g>
947-
<circle cx={330} cy={100} r="30" fill="url(#grad1)" />
948-
<circle cx={330} cy={100} r="12" ref={this.neopixel} />
950+
<circle cx={340} cy={100} r="30" fill="url(#grad1)" />
951+
<circle cx={340} cy={100} r="12" ref={this.neopixel} />
949952
</svg>
950953
</div>
951954
);
@@ -960,13 +963,21 @@ export class ClueSvg extends React.Component<IProps, {}> {
960963
}
961964
private updateNeopixel() {
962965
const { neopixel } = this.props
963-
const rgbColor = `rgb(${neopixel[0]},${neopixel[1]},${neopixel[2]})`
966+
const rgbColor = `rgb(${neopixel[0] + (255 - neopixel[0]) * LED_TINT_FACTOR},
967+
${neopixel[1] + (255 - neopixel[1]) * LED_TINT_FACTOR},${neopixel[2] + (255 - neopixel[2]) * LED_TINT_FACTOR})`
964968

965969
if (this.neopixel.current) {
966-
console.log(rgbColor)
967970
this.neopixel.current.setAttribute('fill', rgbColor)
968971
}
969972
if (this.pixelStopGradient.current) {
973+
if (neopixel === DEFAULT_CLUE_STATE.neopixel) {
974+
console.log("remove opacity")
975+
976+
this.pixelStopGradient.current.setAttribute('stop-opacity', '0')
977+
} else {
978+
this.pixelStopGradient.current.setAttribute('stop-opacity', '1')
979+
980+
}
970981
this.pixelStopGradient.current.setAttribute('stop-color', rgbColor)
971982
}
972983

0 commit comments

Comments
 (0)