Permalink
Browse files

Minor fixes for the jQuery plugin layer.

  • Loading branch information...
1 parent 0205a41 commit 772b55eed76c2dc5f334c1949f9195040bfb7fad @rsandor committed Oct 18, 2010
Showing with 81 additions and 9 deletions.
  1. +69 −0 demos/jquery.html
  2. +4 −4 demos/shared.js
  3. +8 −5 gury.js
View
@@ -0,0 +1,69 @@
+<!--
+ gury - A jQuery inspired canvas utility library
+ By Ryan Sandor Richards
+-->
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>jQuery - By Ryan Sandor Richards</title>
+ <style type="text/css" media="screen">
+ img { cursor: crosshair; }
+ </style>
+ </head>
+ <body style="font-family: helvetica; background-color: #444; color: #ddd; text-align: center">
+
+ <h1>jQuery</h1>
+ <p>By Ryan Sandor Richards</p>
+
+ <div id="content">
+ <canvas></canvas>
+ </div>
+ <div id="controls">
+ <p>(Mouse Over the Image)</p>
+ </div>
+
+ <!-- Nice little link back to the repo -->
+ <p><a href="http://github.com/rsandor/gury" style="color: white">Project on github</a></p>
+
+ <!-- Add jQuery for load behaviors -->
+ <script type="text/javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
+
+ <!-- Include the gury library -->
+ <script type="text/javascript" charset="utf-8" src="../gury.js"></script>
+
+ <!-- Include some shared helper classes -->
+ <script type="text/javascript" charset="utf-8" src="shared.js"></script>
+
+ <!-- Now script up a neato canvas scene! -->
+ <script type="text/javascript" charset="utf-8">
+ function desaturate(ctx, canvas) {
+ var w = canvas.width, h = canvas.height;
+ var imgData = ctx.getImageData(0, 0, w, h);
+ var data = imgData.data;
+ for (var x = 0; x < w; x++) {
+ for (var y = 0; y < h; y++) {
+ var pos = 4*w*y + 4*x;
+ var r = data[pos], g = data[pos+1], b = data[pos+2];
+ var hsv = rgbToHSV(r, g, b);
+ hsv.s = 0;
+ var rgb = hsvToRGB(hsv);
+ data[pos] = rgb.r;
+ data[pos+1] = rgb.g;
+ data[pos+2] = rgb.b;
+ }
+ }
+ ctx.putImageData(imgData, 0, 0);
+ }
+
+ $(function() {
+ var img = new Image();
+ img.src = "./images/mountains.jpg";
+
+ $('canvas').gury().size(128, 128).add(function(ctx) {
+ ctx.drawImage(img, 0, 0);
+ }).play(32);
+
+ });
+ </script>
+ </body>
+</html>
View
@@ -17,9 +17,9 @@ function rgbToHSV(r, g, b) {
var H = 60, S, V = M;
if (C == 0) H *= 0;
- else if (M == r) H *= ((G-B)/C) % 6;
- else if (M == g) H *= (B-R)/C + 2;
- else H *= (R-G)/C + 4;
+ else if (M == r) H *= ((g-b)/C) % 6;
+ else if (M == g) H *= (b-r)/C + 2;
+ else H *= (r-g)/C + 4;
S = C / V;
return {h: H, s: S, v: V};
@@ -31,7 +31,7 @@ function hsvToRGB(c) {
var C = v * s, Hp = h/60, X = C*(1 - Math.abs(Hp % 2 - 1));
var m = v - C;
- if (H == 0) t = [0, 0, 0];
+ if (h == 0) t = [0, 0, 0];
else if (Hp < 1) t = [C, X, 0];
else if (Hp < 2) t = [X, C, 0];
else if (Hp < 3) t = [0, C, X];
View
13 gury.js
@@ -55,6 +55,10 @@ window.$g = window.Gury = (function(window, jQuery) {
return isObject(v) && isDefined(v.getContext);
}
+ function isImage(v) {
+ return isDefined(v.tagName) && v.tagName == "IMG";
+ }
+
/*
* Check for jQuery
* TODO This might be removed with the plugin binding
@@ -69,7 +73,6 @@ window.$g = window.Gury = (function(window, jQuery) {
* Gury exception handling
*/
var _failWithException = true;
-
function GuryException(msg) {
if (_failWithException) {
throw "Gury: " + msg;
@@ -925,8 +928,8 @@ window.$g = window.Gury = (function(window, jQuery) {
if (isObject(q) && isDefined(q.selector, q.length)) {
// TODO Document this behavior:
// When using jQuery canvases will always be unregistered from old Gury instances
- q.each(function(canvas) {
- gury.register(q[i]);
+ q.each(function(i, canvas) {
+ gury.register(canvas);
});
}
// By id
@@ -971,8 +974,8 @@ window.$g = window.Gury = (function(window, jQuery) {
(function($) {
if (typeof $ == "undefined" || $ == null) { return; }
$.fn.gury = function(options) {
- console.log(this);
- //return $g(this, options);
+ //console.log(this);
+ return $g(this, options);
};
})(window.jQuery);

0 comments on commit 772b55e

Please sign in to comment.