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.
pad = DUDLPAD.create my_canvas
pad.start (pos) ->
console.log "started at #{pos[0]}, #{pos[1]}"
pad.start [25,25]
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) ->
console.log "ended at #{pos[0]}, #{pos[1]}"
pad.end [50,50]
pad.undo ->
console.log "undo!"
$('#undo').click ->
pad.undo()
pad.redo ->
console.log "redo!"
$('#redo').click ->
pad.redo()
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()
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 ->
console.log 'canvas was cleared!'
$('#clear').click ->
pad.clear()
pad.start ->
console.log 'start!'
pad.start [0,0] # console output: 'start!'
pad.unbind 'start'
pad.start [0,0] # No console output.
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()