You are reading a single comment by @PaddeK and its replies. Click here to read the full conversation.
  • First off thanks for the pattern launcher @crazysaem , the title of this thread is very fitting!
    I may have some detection improvement, based on some testing in the web ide. At the very least it reduces the code a bit.

      const CIRCLE_RADIUS = 25;
      const CIRCLE_RADIUS_2 = Math.pow(CIRCLE_RADIUS, 2);
    
      let positions = [];
    
      const getPattern = positions => {
        let circles = [
            {x: 25,  y: 25,  i: 0},
            {x: 87,  y: 25,  i: 1},
            {x: 150, y: 25,  i: 2},
            {x: 25,  y: 87,  i: 3},
            {x: 87,  y: 87,  i: 4},
            {x: 150, y: 87,  i: 5},
            {x: 25,  y: 150, i: 6},
            {x: 87,  y: 150, i: 7},
            {x: 150, y: 150, i: 8}
        ];
    
        return positions.reduce((pattern, p, i, arr) => {
          const idx = circles.findIndex(c => {
            const dx = p.x > c.x ? p.x - c.x : c.x - p.x;
    
            if (dx > CIRCLE_RADIUS) {
              return false;
            }
    
            const dy = p.y > c.y ? p.y - c.y : c.y - p.y;
    
            if (dy > CIRCLE_RADIUS) {
              return false;
            }
    
            if (dx + dy <= CIRCLE_RADIUS) {
              return true;
            }
    
            return dx * dx + dy * dy <= CIRCLE_RADIUS_2;
          });
    
          if (idx >= 0) {
            pattern += circles[idx].i;
            circles.splice(idx, 1);
          }
    
          if (circles.length === 0) {
            arr.splice(1);
          }
    
          return pattern;
        }, '');
      };
    
      const dragHandler = position => {
        positions.push(position);
    
        if (position.b === 0 || positions.length >= 200) {
          console.log('pattern', getPattern(positions));
          positions = [];
        }
      };
    
      Bangle.on("drag", dragHandler);
    
About

Avatar for PaddeK @PaddeK started