Giter Club home page Giter Club logo

dudlpad's Introduction

düdlpad is a simple, lightweight, zero-dependency drawing surface that utilizes the HTML5 canvas tag.

It is implemented in Coffee Script.

Some features:

  • callback-driven API
  • undo/redo support
  • drawing style support (e.g. line width, color, etc.)
  • (planned) recording/playback capabilities

A live demo can be seen here.

Annotated source can be viewed here.

A jQuery plugin that handles input events across different devices is also planned.

v0.2.0 API

DUDLPAD.create [parent]

  pad = DUDLPAD.create my_canvas

pad.start [pos] | [(pos) ->]

  pad.start (pos) ->
    console.log "started at #{pos[0]}, #{pos[1]}"

  pad.start [25,25]

pad.draw [coords] | [(coords) ->]

  pad.draw (coords) ->
    i = 0
    while i < coords.length
      console.log "#{'drew from' if i==0 else '  then to'} (#{coords[i]}, #{coords[i+1]})"
      i += 2

  pad.draw [
    25,25
    50,50
  ]

pad.end [pos] | [(pos) ->]

  pad.end (pos) ->
    console.log "ended at #{pos[0]}, #{pos[1]}"

  pad.end [50,50]

pad.undo (->)

  pad.undo ->
    console.log "undo!"

  $('#undo').click ->
    pad.undo()

pad.redo (->)

  pad.redo ->
    console.log "redo!"

  $('#redo').click ->
    pad.redo()

pad.lineColor () | [cssColor] | [(cssColor) ->]

  console.log "the current line color is '#{pad.lineColor()}'"

  pad.lineColor (cssColor) ->
    console.log "line color was changed to '#{cssColor}'"

  $('input#color').change ->
    pad.lineColor $(this).val()

pad.lineWidth () | [width] | [(width) ->]

  console.log "the current line width is '#{pad.lineWidth()}'"

  pad.lineWidth (width) ->
    console.log "line width was changed to '#{width}'"

  $('#widen').click ->
    pad.lineWidth pad.lineWidth() + 1.0

  $('#narrow').click ->
    pad.lineWidth pad.lineWidth() - 1.0

pad.clear (->)

  pad.clear ->
    console.log 'canvas was cleared!'

  $('#clear').click ->
    pad.clear()

pad.unbind (event)

  pad.start ->
    console.log 'start!'
  pad.start [0,0] # console output: 'start!'

  pad.unbind 'start'

  pad.start [0,0] # No console output.

pad.reset (->)

This will clear the canvas and reset the line color/thickness. It doesn't reset any callbacks. (See unbind)

  pad.reset ->
    console.log 'canvas was reset!'

  $('#reset').click ->
    pad.reset()

dudlpad's People

Contributors

namuol avatar

Stargazers

Katalyzzt avatar  avatar

Watchers

 avatar James Cloos 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.