Coder Social home page Coder Social logo

bcrikko / xypadjs Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 2.0 875 KB

:control_knobs: XYPad controller component using Canvas API

Home Page: https://twitter.com/bc_rikko/status/1167363302327869442

License: MIT License

HTML 5.79% TypeScript 82.73% CSS 9.54% JavaScript 1.94%
javascript typescript canvas xypad

xypadjs's Introduction

🎛️ XYPad.js

XYPad.js is XYPad controller component using Canvas API.

XYPad.jsはCanvasAPIを使った2次元パッドコントローラのコンポーネントです。

📚 Examples

rikko

🚀 Getting started

<div id="app"></div>
<p id="output"></p>
new XYPad({
  // Specifies the selector of the parent element. XYPad creates a Canvas element within parent element.
  // 親要素のセレクターを指定します。XYPadは親要素の中にCanvas要素を作成します。
  el: '#app',

  // (Option)Specifies the color of the current position pointer. The default color is `black `.
  // (省略可能)現在位置を示すポインターの色を指定します。デフォルトは`black`です。
  pointerColor: '#23CBF5',
  
  // (Option)Specifies the size of the Canvas elements to display. The default is 300px x 300px.
  // (省略可能)表示するCanvas要素のサイズを指定します。デフォルトは300x300です。
  width: 300,
  height: 300,

  // (Option)Specifies the maximum and minimum values that XYPad can take in two dimensions. The default is `xRange: {min: -100, max: 100}` `yRange: {min: -100, max: 100}`.
  // (省略可能)XYPadが取りうる2次元上の最大値と最小値を指定します。デフォルトは`xRange: {min: -100, max: 100}` `yRange: {min: -100, max: 100}`です。
  xRange: { min: -100, max: 100 },
  yRange: { min: -100, max: 100 },

  // (Option)Callback for pointer drag event. The argument value is a Pointer class.
  // (省略可能)ポインターのドラッグイベントのコールバックです。引数はPointerクラスです。
  callback: (pointer) => {
    document.querySelector('#output').innerHTML = pointer.toString()

    // current point
    const { x, y } = p.point

    // { x: 50, y: 30 }
    console.log(p.toString())
  })

  // (Option)Callback to start dragging. The argument value is a Pointer class.
  // (省略可能)ドラッグを開始したときのコールバックです。引数はPointerクラスです。
  onDragStart: (pointer) => {
    console.log('drag start:', p.toString())
  }

  // (Option)Callback while dragging. The argument value is a Pointer class.
  // (省略可能)ドラッグ中のコールバックです。引数はPointerクラスです。
  onDragMove: (pointer) => {
    console.log('drag move:', p.toString())
  }

  // (Option)Callback when finished dragging. The argument value is a Pointer class.
  // (省略可能)ドラッグを終了したときのコールバックです。引数はPointerクラスです。
  onDragEnd: (pointer) => {
    console.log('drag end:', p.toString())
  }
})

📖 API

destroy

xyPad.destroy()

Removes XYPad drag events.

XYPadのドラッグイベントを削除します。

getPointer

const p = xyPad.getPointer()
const { x, y } = p.point

Gets the value of the current pointer.

現在のポインターの値を取得します。

movePointerTo

const newPoint = new Pointer(10, 20)
xyPad.movePointerTo(newPoint)

// or

xyPad.movePointerTo(10, 20)

Sets the value of the current pointer.

ポインターの値を設定します。

©️ Copyright and license

Code and documentation copyright 2019 B.C.Rikko. Code released under the MIT License. Docs released under Creative Commons.

xypadjs's People

Contributors

bcrikko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.