Permalink
Browse files

test

  • Loading branch information...
1 parent d08ceb5 commit 93ceb6c1413dbeddba67f7de2c6523f8ee253186 Daome committed Feb 20, 2012
Showing with 252 additions and 0 deletions.
  1. +8 −0 css/unselectable.css
  2. BIN img/bucket.png
  3. BIN img/pen.png
  4. BIN img/rubber.png
  5. +56 −0 js/test.coffee
  6. +95 −0 js/test.js
  7. +65 −0 log
  8. +28 −0 test.html
View
@@ -0,0 +1,8 @@
+div{
+ -moz-user-select: -moz-none;
+ -khtml-user-select: none;
+ -webkit-user-select: none;
+ user-select: none;
+}
+
+
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,56 @@
+log = ->
+ console.log arguments
+pixels = []
+MAXSTACK = 0
+isInCanvas = (ctx,pixel)->
+ result = ((0 <= pixel.x <= ctx.canvas.width) and (0 <= pixel.y <= ctx.canvas.height))
+ return result
+
+bucketFill = (ctx,pixel, colcible, colrep)->
+ #console.log("bucketFill",ctx,pixel.x,pixel.y,colcible,colrep)
+ MAXSTACK+=1
+ #if MAXSTACK < 50000 then log MAXSTACK
+ if !isInCanvas(ctx,pixel) then return null
+ #if pixels.indexOf(pixel)!=-1 then return null
+ if getColorAtPixel(ctx,pixel) == colcible
+ ctx.fillStyle = colrep
+ ctx.fillRect(pixel.x,pixel.y,1,1)
+ pixels.push(pixel)
+ left = {x:pixel.x,y:pixel.y-1}
+ right = {x:pixel.x,y:pixel.y+1}
+ up = {x:pixel.x+1,y:pixel.y}
+ down = {x:pixel.x-1,y:pixel.y}
+ bucketFill(ctx,left,colcible,colrep) unless (!isInCanvas(ctx,left) or getColorAtPixel(ctx,left)!=colcible)
+ bucketFill(ctx,right,colcible,colrep) unless (!isInCanvas(ctx,right) or getColorAtPixel(ctx,right)!=colcible)
+ bucketFill(ctx,up,colcible,colrep) unless (!isInCanvas(ctx,up) or getColorAtPixel(ctx,up)!=colcible)
+ bucketFill(ctx,down,colcible,colrep) unless( !isInCanvas(clx,down) or getColorAtPixel(ctx,up)!=colCible)
+ return
+
+getColorAtPixel=(ctx,pixel)->
+ imageData = ctx.getImageData(pixel.x,pixel.y,1,1)
+ return rgbArrayToCssColorString(imageData.data)
+
+rgbArrayToCssColorString=(array)->
+ #log(["rgbArrayToCssColorString",array])
+ result = "#"
+ result+=array[i] for i in [0..2]
+ return result
+
+main=->
+
+ log("début du script")
+ canvas = document.getElementById("canvas")
+ ctx = canvas.getContext("2d")
+ ctx.fillStyle = "#0FF"
+ ctx.fillRect(10,10,40,40)
+ penPosition = {x:1,y:1}
+ fillColor = "#FF0000"
+ colCible = getColorAtPixel(ctx,penPosition)
+ try
+ bucketFill(ctx,penPosition,colCible,fillColor)
+ catch e
+ log e,MAXSTACK
+ log(colCible)
+ log(MAXSTACK)
+window.onload=->
+ main()
View
@@ -0,0 +1,95 @@
+var MAXSTACK, bucketFill, getColorAtPixel, isInCanvas, log, main, pixels, rgbArrayToCssColorString;
+
+log = function() {
+ return console.log(arguments);
+};
+
+pixels = [];
+
+MAXSTACK = 0;
+
+isInCanvas = function(ctx, pixel) {
+ var result, _ref, _ref2;
+ result = ((0 <= (_ref = pixel.x) && _ref <= ctx.canvas.width)) && ((0 <= (_ref2 = pixel.y) && _ref2 <= ctx.canvas.height));
+ return result;
+};
+
+bucketFill = function(ctx, pixel, colcible, colrep) {
+ var down, left, right, up;
+ MAXSTACK += 1;
+ if (!isInCanvas(ctx, pixel)) return null;
+ if (getColorAtPixel(ctx, pixel) === colcible) {
+ ctx.fillStyle = colrep;
+ ctx.fillRect(pixel.x, pixel.y, 1, 1);
+ pixels.push(pixel);
+ left = {
+ x: pixel.x,
+ y: pixel.y - 1
+ };
+ right = {
+ x: pixel.x,
+ y: pixel.y + 1
+ };
+ up = {
+ x: pixel.x + 1,
+ y: pixel.y
+ };
+ down = {
+ x: pixel.x - 1,
+ y: pixel.y
+ };
+ if (!(!isInCanvas(ctx, left) || getColorAtPixel(ctx, left) !== colcible)) {
+ bucketFill(ctx, left, colcible, colrep);
+ }
+ if (!(!isInCanvas(ctx, right) || getColorAtPixel(ctx, right) !== colcible)) {
+ bucketFill(ctx, right, colcible, colrep);
+ }
+ if (!(!isInCanvas(ctx, up) || getColorAtPixel(ctx, up) !== colcible)) {
+ bucketFill(ctx, up, colcible, colrep);
+ }
+ if (!(!isInCanvas(clx, down) || getColorAtPixel(ctx, up) !== colCible)) {
+ bucketFill(ctx, down, colcible, colrep);
+ }
+ }
+};
+
+getColorAtPixel = function(ctx, pixel) {
+ var imageData;
+ imageData = ctx.getImageData(pixel.x, pixel.y, 1, 1);
+ return rgbArrayToCssColorString(imageData.data);
+};
+
+rgbArrayToCssColorString = function(array) {
+ var i, result;
+ result = "#";
+ for (i = 0; i <= 2; i++) {
+ result += array[i];
+ }
+ return result;
+};
+
+main = function() {
+ var canvas, colCible, ctx, fillColor, penPosition;
+ log("début du script");
+ canvas = document.getElementById("canvas");
+ ctx = canvas.getContext("2d");
+ ctx.fillStyle = "#0FF";
+ ctx.fillRect(10, 10, 40, 40);
+ penPosition = {
+ x: 1,
+ y: 1
+ };
+ fillColor = "#FF0000";
+ colCible = getColorAtPixel(ctx, penPosition);
+ try {
+ bucketFill(ctx, penPosition, colCible, fillColor);
+ } catch (e) {
+ log(e, MAXSTACK);
+ }
+ log(colCible);
+ return log(MAXSTACK);
+};
+
+window.onload = function() {
+ return main();
+};
View
65 log
@@ -0,0 +1,65 @@
+commit 7cf0f7ad8d3a1ff5ae60ccb871acc24bdbf6018f
+Author: Daome <aikah@free.fr>
+Date: Sun Feb 19 19:30:00 2012 +0100
+
+ ajout undo redo
+
+commit e51d69f6265a68d3140f9fb2a710358328e1ab32
+Author: Daome <aikah@free.fr>
+Date: Sun Feb 19 13:35:36 2012 +0100
+
+ App.Utils.Iterator ajoute
+
+commit 10a9ac393ea5a3b824e92307217c6e1b16753064
+Author: Daome <aikah@free.fr>
+Date: Sun Feb 19 13:35:07 2012 +0100
+
+ App.Utils.Iterator ajout�
+
+commit d0043f187b3fbaff72213341410e1d1eac411de5
+Author: Daome <aikah@free.fr>
+Date: Sun Feb 19 02:59:21 2012 +0100
+
+ thickbox
+
+commit 949aa4300e0a4f0c8b0558b19c1253d9179baaab
+Author: Daome <aikah@free.fr>
+Date: Sat Feb 18 22:08:31 2012 +0100
+
+ deletion du manifeste
+
+commit 77f8b896c32690bd8cae25555d73db3b34afd0f5
+Author: Daome <aikah@free.fr>
+Date: Sat Feb 18 20:25:29 2012 +0100
+
+ modification css
+
+commit b2fc6e7286a932a50b4ebee472eec420aab61cd5
+Author: Daome <aikah@free.fr>
+Date: Sat Feb 18 17:55:41 2012 +0100
+
+ modifications html et css
+
+commit 9334267396c95121969da9e7e3434a4f006ad6f1
+Author: Daome <aikah@free.fr>
+Date: Sat Feb 18 16:34:59 2012 +0100
+
+ modifications html et css
+
+commit 23910a60871caca0fa2dd9059e51ef4c844b1143
+Author: Daome <aikah@free.fr>
+Date: Sat Feb 18 15:19:03 2012 +0100
+
+ modification main
+
+commit 18f0268cf7a5bfa85f0b9479073c311a64c4d0e3
+Author: Daome <aikah@free.fr>
+Date: Sat Feb 18 15:17:17 2012 +0100
+
+ ajout FactorSelector
+
+commit 8dea83ecca36a56f781cb3b37a5f5740930582f2
+Author: Daome <aikah@free.fr>
+Date: Sat Feb 18 11:49:47 2012 +0100
+
+ import initial
View
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Untitled Document</title>
+ </head>
+ <body>
+ <canvas id='canvas' width="50" height='50'>
+ canvas vide
+ </canvas>
+ <script type="text/javascript">
+ console.log(i)
+ var i = 0
+ </script>
+ <script type="text/javascript" src="js/test.js"></script>
+ <style type="text/css">
+ canvas{
+ border:1px solid #999;
+ margin:10px;
+ }
+ div{
+ font-color:#222;
+ font-size:10px;
+ }
+
+ </style>
+ </body>
+</html>

0 comments on commit 93ceb6c

Please sign in to comment.