This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const canvas = document.createElement('canvas'); | |
| const tempCanvas = document.createElement('canvas'); | |
| // make all pixells opaque 100% (except pixels that 100% transparent) | |
| function removeTransparency(canvas) { | |
| const ctx = canvas.getContext('2d'); | |
| const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); | |
| const nPixels = imageData.data.length; | |
| for (var i = 3; i < nPixels; i += 4) { | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | circles.forEach(circle => { | |
| // draw on "scene" canvas first | |
| ctx.beginPath(); | |
| ctx.arc(circle.x, circle.y, circle.radius, 0, 2 * Math.PI, false); | |
| ctx.fillStyle = circle.color; | |
| ctx.fill(); | |
| // then draw on offscren "hit" canvas | |
| hitCtx.beginPath(); | |
| hitCtx.arc(circle.x, circle.y, circle.radius, 0, 2 * Math.PI, false); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // colorsHash for saving references of all created circles | |
| const colorsHash = {}; | |
| function getRandomColor() { | |
| const r = Math.round(Math.random() * 255); | |
| const g = Math.round(Math.random() * 255); | |
| const b = Math.round(Math.random() * 255); | |
| return `rgb(${r},${g},${b})`; | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function hasSameColor(color, circle) { | |
| return circle.color === color; | |
| } | |
| canvas.addEventListener('click', (e) => { | |
| const mousePos = { | |
| x: e.clientX - canvas.offsetTop, | |
| y: e.clientY - canvas.offsetLeft | |
| }; | |
| // get pixel under cursor | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function isIntersect(point, circle) { | |
| return Math.sqrt((point.x-circle.x) ** 2 + (point.y - circle.y) ** 2) < circle.radius; | |
| } | |
| canvas.addEventListener('click', (e) => { | |
| const pos = { | |
| x: e.clientX, | |
| y: e.clientY | |
| }; | |
| circles.forEach(circle => { | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const canvas = document.getElementById('canvas'); | |
| const ctx = canvas.getContext('2d'); | |
| // create circles to draw | |
| const circles = [ | |
| { | |
| x: 40, | |
| y: 40, | |
| radius: 10, | |
| color: 'rgb(255,0,0)' | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const TargetView = connect( | |
| (state, ownProps) => ({target: state.targets[ownProps.targetId]}) | |
| )(({ target }) => { | |
| // your render logic | |
| return <Circle radius={target.radius} />; | |
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const TargetsList = connect(state => ({targetsOrder: state.targetsOrder}))( | |
| ({ targetsOrder }) => | |
| <ul> | |
| { targetsOrder.map((id) => <TargetView key={id} targetId={id} />) } | |
| </ul> | |
| ); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const state = { | |
| targetsOrder: ['id-1', 'id-2'], | |
| targets: { | |
| 'id-1': { id: 'id-1', radius: 10 }, | |
| 'id-2': { id: 'id-2', radius: 20 }, | |
| } | |
| }; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function appReducer(state, action) { | |
| if (action.type === 'UPDATE') { | |
| return { | |
| target: state.target.map((target) => { | |
| if (target.id === action.id) { | |
| return { | |
| ...target, | |
| radius: action.radius | |
| }; | |
| } else { | 
NewerOlder