Let me know if you have problems implementing this. It uses processing.js and has functions for changing colors and increasing the drawing point.
<html> <head> <script type="text/javascript" src="processing.js"></script> <script type="text/javascript" src="init.js"></script> <style type="text/css" src="stylesheet.css"> </style> </head> <body> <div id="draggable toolbox"></div> <script type="application/processing"> // new script int prevx, prevy; int newx, newy; boolean cliked; color c1 = #000000; int largeur=2; int ps = 20; int px = 50; int py = 50; void setup() { size(500,500); frameRate(25); background(50); prevx = mouseX; prevy = mouseY; cliked = false; } void draw() { //couleur noStroke(0); fill(#FFFFFF);//blanc rect(px, py, ps, ps); fill(#000000); rect(px, py+(ps), ps, ps); fill(#FF0000); rect(px, py+(ps*2), ps, ps); fill(#00FF00); rect(px, py+(ps*3), ps, ps); fill(#FFFF00); rect(px, py+(ps*4), ps, ps); fill(#0000FF); rect(px, py+(ps*5), ps, ps); //largeur fill(#FFFFFF); rect(px, py+(ps*7), ps, ps); fill(#FFFFFF); rect(px, py+(ps*8), ps, ps); stroke(#000000); line(px+2, py+(ps*7)+(ps/2), px+(ps-2), py+(ps*7)+(ps/2)); line(px+(ps/2), py+(ps*7)+1, px+(ps/2), py+(ps*8)-1); line(px+2, py+(ps*8)+(ps/2), px+(ps-2), py+(ps*8)+(ps/2)); if(cliked==false){ prevx = mouseX; prevy = mouseY; } if(mousePressed) { cliked = true; newx = mouseX; newy = mouseY; strokeWeight(largeur); stroke(c1); line(prevx, prevy, newx, newy); prevx = newx; prevy = newy; }else{ cliked= false; } } void mouseClicked() { if (mouseX>=px && mouseX<=(px+ps)){ //couleur if (mouseY>=py && mouseY<=py+(ps*6)){ c1 = get(mouseX, mouseY); } //largeur if (mouseY>=py+(ps*7) && mouseY<=py+(ps*8)){ largeur += 2; } if (mouseY>=py+(ps*8) && mouseY<=py+(ps*9)){ if (largeur>2){ largeur -= 2; } } } } </script><canvas></canvas> </body> </html>
expiredninja Dec 11 '10 at 21:54 2010-12-11 21:54
source share