How to use the paintvec.Vec2 function in paintvec

To help you get started, we’ve selected a few paintvec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sketchglass / azurite / src / renderer / models / TiledTexture.ts View on Github external
function stringToKey(str: string) {
  const strs = str.split(',')
  return new Vec2(parseInt(strs[0]), parseInt(strs[1]))
}
github sketchglass / azurite / src / renderer / models / Selection.ts View on Github external
boundingRect() {
    const binaryWidth = Math.ceil(this.size.width / 32)
    const binarySize = new Vec2(binaryWidth, this.size.height)
    if (!binaryTexture.size.equals(binarySize)) {
      binaryTexture.size = binarySize
    }
    drawVisibilityToBinary(binaryDrawTarget, this.texture)

    const data = new Int32Array(binarySize.width * binarySize.height)
    binaryDrawTarget.readPixels(new Rect(new Vec2(), binarySize), new Uint8Array(data.buffer))
    return getBoundingRect(data, this.size)
  }
github sketchglass / azurite / src / renderer / models / TiledTexture.ts View on Github external
boundingRect() {
    drawVisibilityToBinary(binaryDrawTarget, this.texture)
    binaryDrawTarget.readPixels(new Rect(new Vec2(), binaryTexture.size), new Uint8Array(binaryData.buffer))
    return getBoundingRect(binaryData, new Vec2(Tile.width))
  }
github sketchglass / azurite / src / renderer / tools / CanvasAreaTool.tsx View on Github external
reset() {
    if (this.picture) {
      this.dimensionSelectViewModel.reset(this.picture.dimension)
      this.dimensionSelectViewModel.unit = 'percent'
      this.resetRect(new Rect(new Vec2(), this.picture.size))
    }
  }
github sketchglass / azurite / src / renderer / models / TiledTexture.ts View on Github external
drawTexture(src: Texture, opts: {transform: Transform, blendMode: BlendMode, bicubic?: boolean, srcRect?: Rect}) {
    const {blendMode, transform, bicubic, srcRect} = opts
    const rect = new Rect(new Vec2(), src.size).transform(transform)
    for (const key of TiledTexture.keysForRect(rect)) {
      tileDrawTarget.texture = this.get(key).texture
      drawTexture(tileDrawTarget, src, {
        transform: transform.translate(key.mulScalar(-Tile.width)),
        blendMode,
        bicubic,
        srcRect
      })
    }
  }
github sketchglass / azurite / src / renderer / tools / RectMoveTool.ts View on Github external
@action keyDown(ev: React.KeyboardEvent) {
    super.keyDown(ev)
    switch (ev.key) {
      case "ArrowLeft":
        this.translation = this.translation.add(new Vec2(-1, 0))
        break
      case "ArrowRight":
        this.translation = this.translation.add(new Vec2(1, 0))
        break
      case "ArrowUp":
        this.translation = this.translation.add(new Vec2(0, -1))
        break
      case "ArrowDown":
        this.translation = this.translation.add(new Vec2(0, 1))
        break
    }
  }
github sketchglass / azurite / src / renderer / tools / RectMoveTool.ts View on Github external
@action keyDown(ev: React.KeyboardEvent) {
    super.keyDown(ev)
    switch (ev.key) {
      case "ArrowLeft":
        this.translation = this.translation.add(new Vec2(-1, 0))
        break
      case "ArrowRight":
        this.translation = this.translation.add(new Vec2(1, 0))
        break
      case "ArrowUp":
        this.translation = this.translation.add(new Vec2(0, -1))
        break
      case "ArrowDown":
        this.translation = this.translation.add(new Vec2(0, 1))
        break
    }
  }
github sketchglass / azurite / src / renderer / services / ThumbnailGenerator.ts View on Github external
private readToThumbnail() {
    this.texture.generateMipmap()

    const rect = new Rect(new Vec2(0), this.thumbnailSize.mul(this.texture.size.div(this.originalSize)))
    drawTexture(this.thumbnailDrawTarget, this.texture, {dstRect: rect, blendMode: "src"})

    const {width, height} = rect
    const data = new ImageData(width, height)
    this.thumbnailDrawTarget.readPixels(rect, new Uint8Array(data.data.buffer))
    this.thumbnailContext.putImageData(data, 0, 0)
  }
github sketchglass / azurite / src / renderer / models / TextureToCanvas.ts View on Github external
updateCanvas() {
    this.drawTarget.readPixels(new Rect(new Vec2(0), this.size), new Uint8Array(this.imageData.data.buffer))
    this.context.putImageData(this.imageData, 0, 0)
  }
github sketchglass / azurite / src / renderer / services / ThumbnailGenerator.ts View on Github external
loadTiledTexture(tiledTexture: TiledTexture) {
    this.clear()
    tiledTexture.drawToDrawTarget(this.drawTarget, {offset: new Vec2(0), blendMode: "src-over"})
    this.readToThumbnail()
  }

paintvec

JavaScript 2D vector math library

MIT
Latest version published 2 months ago

Package Health Score

60 / 100
Full package analysis

Popular paintvec functions