meltingice / CamanJS

Javascript HTML5 (Ca)nvas (Man)ipulation
http://camanjs.com
BSD 3-Clause "New" or "Revised" License
3.55k stars 404 forks source link

Making draggable sliders somoother #71

Closed fardeem closed 11 years ago

fardeem commented 11 years ago

In the example page, Caman waits for the dragging to be finished. Is there some way that I can apply filters realtime?

meltingice commented 11 years ago

Sure, the delay is simply being set by a debounce function right now. If that was changed to throttle, then the filters would be applied in realtime. The only reason I went with debounce was that the effect didn't look as good on HiDPI screens due to longer render times.

busy = false # Are we currently rendering?
changed = false # Tracks unrendered changes

# Triggers the render, throttled to every 400ms max
render = _.throttle ->
  if busy
    changed = true
    return
  else
    changed = false

  busy = true
  caman.revert()
  for own filter, value of filters
    value = parseFloat value, 10
    continue if value is 0

    caman[filter](value)

  caman.render ->
    busy = false
    render() if changed
, 400
bostondevin commented 11 years ago

Is this something I can configure somehow without mucking with the library code? I want to do the same thing. I'm using the javascript code - not the coffee script