diff options
| author | jules <jules@okfoc.us> | 2014-01-26 02:26:23 -0500 |
|---|---|---|
| committer | jules <jules@okfoc.us> | 2014-01-26 02:26:23 -0500 |
| commit | b0b1b4cfbe3217b9f35343bdc35cdd058f4cf534 (patch) | |
| tree | a7806b86b555b40a77e6f5fce28dcee66fb42275 /js/render.js | |
| parent | 2d0d3f2bcf078d8ab0747061f2fc5cc3d626e6e3 (diff) | |
allow empty canvas w/ no url
Diffstat (limited to 'js/render.js')
| -rw-r--r-- | js/render.js | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/js/render.js b/js/render.js index a22c9fe..f6684d7 100644 --- a/js/render.js +++ b/js/render.js @@ -9,9 +9,10 @@ function choose (){ $("#url").val(imageURL) loadImage(imageURL, ready) } + function load(){ - loading = true var imageURL = $("#url").val() + loading = true loadImage(imageURL, ready) } @@ -25,7 +26,7 @@ function ready(){ f.cloneData = f.ctx.getImageData(0,0,w,h) } } - else { + else if (window.img) { fc = cq(img.width, img.height) fc.drawImage(img, 0, 0) frame = img_frame = { ctx: fc.context } @@ -33,25 +34,52 @@ function ready(){ h = cc.canvas.height = frame.ctx.canvas.height frame.cloneData = frame.ctx.getImageData(0,0,w,h) } + else { + cc.canvas.width = w + cc.canvas.height = h + shader_build() + } + displayWidthHeight(w, h) } +function displayWidthHeight(width, height){ + $("#width").val(width) + $("#height").val(height) +} +$("#width").change(function(){ + w = abs(parseInt(this.value,10)) || 1 + cc.canvas.width = w + cc.canvas.height = h +}) +$("#height").change(function(){ + h = abs(parseInt(this.value,10)) || 1 + cc.canvas.width = w + cc.canvas.height = h +}) function giveFrame(t){ if (window.gif) { if (gif.currentFrame) { return gif.frames[gif.currentFrame(t)] } - else { + else if (gif.frames) { return gif.frames[0] } } - else if (window.img) { + if (window.img) { return img_frame } else { - return cq(w, h) + return empty_frame() } } +function empty_frame(){ + w = w || 400 + h = h || 266 + var cx = cq(w, h).fillStyle("rgba(255,255,255,255)").fillRect(0,0,w,h) + return { ctx: cx.context, cloneData: cx.getImageData(0,0,w,h) } +} + function reset(){ start_t = old_t pause_t = 0 @@ -76,7 +104,7 @@ function animate(t){ var step_t = t - old_t old_t = t - + if (paused || dragging || rendering || scrolling || deferring) { pause_t += step_t if (scrolling) { |
