diff options
Diffstat (limited to 'public/drawing.html')
| -rw-r--r-- | public/drawing.html | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/public/drawing.html b/public/drawing.html new file mode 100644 index 0000000..8c377b0 --- /dev/null +++ b/public/drawing.html @@ -0,0 +1,65 @@ +<!doctype html> +<html> +<head> +<title>Palette Test</title> +<script type="text/javascript" src="/js/jquery-1.9.1.min.js"></script> +<script type="text/javascript" src="/js/canvasquery.js"></script> +<script type="text/javascript" src="/js/point.js"></script> +<script type="text/javascript" src="/js/color.js"></script> +<script type="text/javascript" src="/js/util.js"></script> +</head> +<body> +<img src="/img/palette.gif" id="palette"> +</body> +<script type="text/javascript"> + +$("#palette").load(function(){ + console.log("hello"); + var offset = $("#palette").offset(); + var paletteImg = $("#palette")[0]; + var palette = cq(paletteImg); + var pattern, mask; + var color = new Color( 0, 0, 0 ); + + // $("body").append(palette.canvas); + + $("#palette").click(function(e){ + // they are all 8x8 + // the first one starts at (15, 5), next one is 16 pixels down or to the right + // there are 16 rows and 6 columns, so 92 patterns total + var point = new Point(e, offset); + click(point); + }); + var click = function(point) { + point.subtract({ x: 15, y: 5 }); + point.quantize( 18, 16 ); + point.add({ x: 15, y: 5 }); + + pattern = palette.clone().crop( point.x, point.y, 8, 8 ); + mask = pattern.colorToMask("#fff"); + pattern.applyMask(mask); + patternURI = pattern.clone().blend( color.toString(), "screen", 1.0 ).canvas.toDataURL("image/png"); + document.body.style.backgroundImage = 'url(' + patternURI + ')'; + } + + var random = function(){ + var point = new Point(paletteImg.width, paletteImg.height).scale( Math.random(), Math.random() ).floor(); + click(point); + } + random(); + + for (var i in colors) { + var swatch = colors[i].swatch(); + document.body.appendChild(swatch); + swatch.onclick = function(){ + color = $(this).data("color"); + p = cq(paletteImg); + patternURI = pattern.clone().blend( color.toString(), "screen", 1.0 ).canvas.toDataURL("image/png"); + document.body.style.backgroundImage = 'url(' + patternURI + ')'; + } + } + +}); +</script> +</html> + |
