@/utils#arrayToColor JavaScript Examples

The following examples show how to use @/utils#arrayToColor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: use-pixel.js    From tools-vue with MIT License 5 votes vote down vote up
usePixel = (usePixelKey, type) => {
  const {
    form,
    dotList,
    downDot,
    lastDot,
    currentDot,
    isMousedown,
    addDot,
  } = usePixelKey;

  if (!Object.keys(currentDot.value).length || !isMousedown.value) {
    return;
  }

  const downX = downDot.value.x;
  const downY = downDot.value.y;
  const lastX = lastDot.value.x;
  const lastY = lastDot.value.y;
  const currentX = currentDot.value.x;
  const currentY = currentDot.value.y;

  const usePencil = () => {
    const addDotList = getStraightDotList({ x: lastX, y: lastY }, { x: currentX, y: currentY });
    const colors = colorToArray(form.color, true);
    addDotList.forEach(dot => {
      dotList.value[dot.x][dot.y] = colors;
      addDot(dot.x, dot.y, colors);
    });
  };

  const useEraser = () => {
    const addDotList = getStraightDotList({ x: lastX, y: lastY }, { x: currentX, y: currentY });
    addDotList.forEach(dot => {
      const colors = [255, 255, 255, 0];
      dotList.value[dot.x][dot.y] = colors;
      addDot(dot.x, dot.y, colors);
    });
  };

  const useAbsorber = () => {
    form.color = arrayToColor(dotList.value[currentX][currentY], true);
  };

  switch (type) {
    case 'pencil':
      usePencil();
      break;
    case 'eraser':
      useEraser();
      break;
    case 'absorber':
      useAbsorber();
      break;
  }
}