33
44import * as React from "react" ;
55import "../../styles/Clue.css" ;
6+ import { DEFAULT_CLUE_STATE } from "./ClueSimulator" ;
67export interface IRefObject {
78 [ key : string ] : React . RefObject < SVGRectElement > ;
89}
910interface IProps {
1011 displayImage : string ;
1112 neopixel : number [ ]
1213}
13-
14+ const LED_TINT_FACTOR = 0.5
1415export 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