From e7b0213ebf2621b71fcaa04e7ad80614853e9551 Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 26 Jan 2014 00:11:32 -0500 Subject: toggle gallery --- js/render.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/render.js') diff --git a/js/render.js b/js/render.js index fdb0125..4a9eeef 100644 --- a/js/render.js +++ b/js/render.js @@ -103,4 +103,4 @@ function draw(t) { shade(frame, t) } -function status(s){ $("#status").html(s); console.log(s) } +function status(s){ $(".status").html(s); console.log(s) } -- cgit v1.2.3-70-g09d2 From 009007363dfca587c2cbbdbba6566179a05d8fb6 Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 26 Jan 2014 00:17:45 -0500 Subject: merge js into combo --- js/frames.js | 6 ++++-- js/help.js | 2 ++ js/render.js | 2 -- shader-combo.html | 20 +++++++++++++++----- 4 files changed, 21 insertions(+), 9 deletions(-) (limited to 'js/render.js') diff --git a/js/frames.js b/js/frames.js index c9c844d..2dddae2 100644 --- a/js/frames.js +++ b/js/frames.js @@ -29,6 +29,10 @@ frame_editor.bind = function(){ $("#render").click(render) $("#save").click(save) $("#upload").click(upload) + + $("#background").change(function(){ + document.body.style.backgroundColor = $("#background").string() + }) } function add_frame(){ @@ -121,8 +125,6 @@ function render (){ $("#render").html("rendering") } -function status(s){ $(".status").html(s) } - var encoder = new GifEncoder() encoder.on("quantized", function(url){ diff --git a/js/help.js b/js/help.js index 5610794..1794f3b 100644 --- a/js/help.js +++ b/js/help.js @@ -17,3 +17,5 @@ help.bind = function(){ function drag_start(){ dragging = true; $(this).addClass("dragging") } function drag_stop(){ dragging = false; $(".dragging").removeClass("dragging") } + +function status(s){ $(".status").html(s); console.log(s) } diff --git a/js/render.js b/js/render.js index 4a9eeef..a22c9fe 100644 --- a/js/render.js +++ b/js/render.js @@ -102,5 +102,3 @@ function draw(t) { frame = giveFrame(t) shade(frame, t) } - -function status(s){ $(".status").html(s); console.log(s) } diff --git a/shader-combo.html b/shader-combo.html index 92cb6e1..aa6edd2 100644 --- a/shader-combo.html +++ b/shader-combo.html @@ -46,13 +46,13 @@ a { color: #00f; } | + + - - @@ -80,7 +80,6 @@ a { color: #00f; }
-
@@ -125,16 +124,24 @@ a { color: #00f; } var cc = cq(0,0).appendTo("#workspace") var w, h +var lastGif +var mousex, mousey + var firsttime = true var shader_gallery_template = $("#shader-gallery-template").html() - $(init) function init(){ $("#url").change(load) $("#reset").click(reset) $("#pause").click(pause) + $("#step-forward").click(step_forward) + + $(document).on("mousemove", function(e) { + mousex = e.pageX + mousey = e.pageY + }) $("#toggle-shaders").click(function(){ $("#header .form").hide() @@ -152,6 +159,10 @@ function init(){ $("#header .form").hide() $(".bold").removeClass("bold") }) + + frame_editor.init() + help.init() + load() user.init() help.init() @@ -164,6 +175,5 @@ function init(){ } - -- cgit v1.2.3-70-g09d2 From b0b1b4cfbe3217b9f35343bdc35cdd058f4cf534 Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 26 Jan 2014 02:26:23 -0500 Subject: allow empty canvas w/ no url --- js/api/gallery.js | 3 ++- js/api/set.js | 2 +- js/gallery.js | 1 - js/image.js | 12 ++++++++++-- js/render.js | 40 ++++++++++++++++++++++++++++++++++------ js/shader.js | 6 ++++-- shader-combo.html | 11 +++++++---- 7 files changed, 58 insertions(+), 17 deletions(-) (limited to 'js/render.js') diff --git a/js/api/gallery.js b/js/api/gallery.js index c1a779d..0404009 100644 --- a/js/api/gallery.js +++ b/js/api/gallery.js @@ -68,7 +68,7 @@ function load_shaders(err, shaders){ var $shader = display_shader(shaders[i]) $el.append( $shader ) } - if (firsttime) { + if (false && firsttime) { firsttime = false run_shader(shaders[0]) } @@ -81,5 +81,6 @@ function display_shader(shader_object){ html = html.replace("{" + field + "}", shader_object[field]) } $shader.html(html) + shader_object.id && $shader.data("id", shader_object.id) return $shader; } diff --git a/js/api/set.js b/js/api/set.js index 461f3e3..16e60fe 100644 --- a/js/api/set.js +++ b/js/api/set.js @@ -59,7 +59,7 @@ function save_thumbnail(id, thumb){ status('') var data = JSON.parse(resp) if (data.success) { - $shader.find("img").attr("src", data.url) + $(".shader[data-id="+id+"]").find("img").attr("src", data.url) } }); } diff --git a/js/gallery.js b/js/gallery.js index b9acfc0..839316c 100644 --- a/js/gallery.js +++ b/js/gallery.js @@ -14,7 +14,6 @@ gallery.bind = function(){ $("#gallery-random").click(asdf.random) $("#gallery-search").submit(dumpfm.search) $(document).on("click", "#gallery-images canvas", gallery.click) - status("ready") } gallery.load = function(ims){ diff --git a/js/image.js b/js/image.js index 7a5240f..4de7fd9 100644 --- a/js/image.js +++ b/js/image.js @@ -1,15 +1,23 @@ +var gif, img + function loadImage(imageURL, callback) { var imageURL = proxify( imageURL ); window.gif = window.img = null - if (imageURL.substr(-3) === "gif") { + if (! imageURL) { + window.gif = null + window.img = null + callback() + } + else if (imageURL.substr(-3) === "gif") { window.gif = GIF(imageURL); // gif.on("error", tryToLoadNextImage); // gif.on("rendered", trackLoadTime); gif.on("rendered", callback); return gif.render(); - } else { + } + else { window.img = new Image(); // img.addEventListener("error", tryToLoadNextImage); img.addEventListener("load", callback); 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) { diff --git a/js/shader.js b/js/shader.js index 4a6e950..7773b89 100644 --- a/js/shader.js +++ b/js/shader.js @@ -1,3 +1,5 @@ +function shader (x,y,t,d) {} + var shader_build = function(){ var fn_str = document.getElementById('shader').value if (!fn_str.length) fn_str = "" @@ -46,7 +48,7 @@ var firefox_stack_regexp = /:([0-9]+)$/; function shade_error_handling(frame, t){ if (! t || isNaN(t)) throw Error ("No time specified") - if (! frame) throw Error ("No frame specified") + if (! frame || ! frame.ctx || ! frame.cloneData) throw Error ("No frame specified") var imgData = frame.ctx.getImageData(0,0,w,h) var data = imgData.data @@ -77,7 +79,7 @@ function shade_error_handling(frame, t){ } else if (lines.length > 1) { // attempt chrome match var matches = lines[1].match(chrome_stack_regexp) - if (matches.length > 1) + if (matches && matches.length > 1) error_highlight.on(parseInt(matches[1]) - 3) } diff --git a/shader-combo.html b/shader-combo.html index 6d402da..e61beee 100644 --- a/shader-combo.html +++ b/shader-combo.html @@ -3,7 +3,8 @@ @@ -99,23 +101,20 @@ form { display: inline-block; }
- - + + + +
+
- - - -
- -
-
- - frames +
+ + frames -


+ gif delay background +   + + + +
-- cgit v1.2.3-70-g09d2 From c3470d02a57396e92a71d3cfb072e655ccb51780 Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 26 Jan 2014 04:25:35 -0500 Subject: examples placeholder --- js/image.js | 3 ++- js/render.js | 2 -- shader-combo.html | 3 +++ 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'js/render.js') diff --git a/js/image.js b/js/image.js index aabab89..1f36473 100644 --- a/js/image.js +++ b/js/image.js @@ -1,4 +1,5 @@ var gif, img +var imageURL = null function loadImage(imageURL, callback) { var imageURL = proxify( imageURL ); @@ -37,7 +38,7 @@ function giveImage(t) { function proxify (url) { if (url.indexOf("http") == 0) - return "/cgi-bin/proxy?" + url // .replace(/^https?:\/\//, ""); + return "/cgi-bin/proxy?" + url.replace(/^https?:\/\//, ""); else return url } diff --git a/js/render.js b/js/render.js index cfc2d81..4de7329 100644 --- a/js/render.js +++ b/js/render.js @@ -2,10 +2,8 @@ var frame, img_frame; var timeout, raf_id, start_t = 0, old_t = 0, pause_t = 0 var paused = false, dragging = false, rendering = false, scrolling = false, deferring = false, scrollTimeout = null var fps = 30 -var imageURL = "" function choose (){ - imageURL = this.src loading = true $("#url").val(imageURL) loadImage(imageURL, ready) diff --git a/shader-combo.html b/shader-combo.html index f51037b..5b218a6 100644 --- a/shader-combo.html +++ b/shader-combo.html @@ -59,6 +59,9 @@ form { display: inline-block; }
@@ -231,6 +225,12 @@ function init(){ cc.canvas.width = w cc.canvas.height = h }) + $("#reorder-frames").change(function(){ + var order = $(this).val() + if (order) { + + } + }) load() help.init() -- cgit v1.2.3-70-g09d2 From e3297c52583f38ed71f7734f1ff04a267834e40c Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 26 Jan 2014 21:45:12 -0500 Subject: fix rendering bug --- js/api/gallery.js | 1 + js/frames.js | 3 +-- js/render.js | 2 ++ shader-combo.html | 11 +++++------ 4 files changed, 9 insertions(+), 8 deletions(-) (limited to 'js/render.js') diff --git a/js/api/gallery.js b/js/api/gallery.js index 830ff93..e8af7f1 100644 --- a/js/api/gallery.js +++ b/js/api/gallery.js @@ -76,6 +76,7 @@ function load_shaders(err, shaders){ function display_shader(shader_object){ var $shader = $("
").addClass("shader") $shader.data("shader", shader_object) + $shader.data("id", shader_object.id) var html = shader_gallery_template for (var field in shader_object) { html = html.replace("{" + field + "}", shader_object[field]) diff --git a/js/frames.js b/js/frames.js index 887b497..571e862 100644 --- a/js/frames.js +++ b/js/frames.js @@ -97,12 +97,11 @@ function sort_frames(){ function render (){ if (rendering) return - rendering = true - if ($("#frames canvas.fullsize").length == 0) { add_frame() } + rendering = true encoder.reset() var delay = $("#framedelay").float() * 1000 || 100 $("#frames canvas.fullsize").each(function(){ diff --git a/js/render.js b/js/render.js index 205da88..bd6deb1 100644 --- a/js/render.js +++ b/js/render.js @@ -7,6 +7,7 @@ function choose (){ loading = true $("#url").val(this.src) loadImage(this.src, ready) + reset() } function load(){ @@ -84,6 +85,7 @@ function reset(){ pause(false) $("#workspace img").remove() $("#workspace canvas").show() + $("#uploaded-url").hide().val("") remove_all_frames() draw(0) } diff --git a/shader-combo.html b/shader-combo.html index 97ffd33..65b81e9 100644 --- a/shader-combo.html +++ b/shader-combo.html @@ -3,6 +3,10 @@ +

shaderblaster