PDA

View Full Version : Drag 'n' Drop Paint



E-Slayer
January 12th, 2006, 11:16 PM
Evolved from my other entry, this one is kind of a simple paint tool. It's a little hard to use, but is about as good a balance between tediousness to use and using little code as I can do. (Ultimately, I could convert the last function to use the first, but I don't feel the need, since I'm still within the limit)


_root.createEmptyMovieClip("artist", 1);
function drawnew(i, j) {
colour = (Math.floor(_root._xmouse/20)/19*4095 << 12)+Math.floor(_root._ymouse/20)/19*4095;
_root.artist.moveTo(i*20, j*20);
_root.artist.beginFill(colour, 100);
_root.artist.lineTo(i*20+20, j*20);
_root.artist.lineTo(i*20+20,j*20+20);
_root.artist.lineTo(i*20, j*20+20);
}
function onMouseDown() {
_root.tx = Math.floor(_root._xmouse/20);
_root.ty = Math.floor(_root._ymouse/20);
_root.cset = false;
}
function onEnterFrame() {
if (!_root.cset) {
drawnew(_root.tx, _root.ty);
}
}
function onMouseUp(){
_root.cset = true;
}
function palette() {
for (i=0; i<20; i++) {
for (j=0; j<20; j++) {
colour = (Math.floor(i)/19*4095 << 12)+Math.floor(j)/19*4095;
_root.artist.moveTo(i*20, j*20);
_root.artist.beginFill(colour, 100);
_root.artist.lineTo(i*20+20, j*20);
_root.artist.lineTo(i*20+20, j*20+20);
_root.artist.lineTo(i*20, j*20+20);
}
}
}
palette();
To use it, simply click and hold on the tile you want to colour, then move the mouse until it becomes the colour you want. Release the mouse to lock the colour. I have it set to display all possible colours from the start.

NiñoScript
January 13th, 2006, 01:40 AM
looks good ;)

btw.. what the heck is this line?? :puzzle:

colour = (Math.floor(i)/19*4095 << 12)+Math.floor(j)/19*4095;
never seen something like that before :P

Seb Hughes
January 14th, 2006, 02:10 PM
It wierd :D

NiñoScript
January 14th, 2006, 02:31 PM
i doubt a profesional will buy something like this :shifty: its just too slow :lol:

i spent like 10 minutes drawing this :P
http://img515.imageshack.us/img515/7065/imagen83kk.png (http://www.photobucket.com/)
(-:

MTsoul
January 14th, 2006, 11:25 PM
looks good ;)

btw.. what the heck is this line?? :puzzle:

colour = (Math.floor(i)/19*4095 << 12)+Math.floor(j)/19*4095;
never seen something like that before :P
Seems like a bitwise operation. Is there such thing in AS? I haven't touched AS in a while.

TheCanadian
January 14th, 2006, 11:35 PM
Yes, it's a bitwise shift operator.

NiñoScript
January 15th, 2006, 12:55 AM
and what is it for?
i know it is a bitwise operator, but its the first time i actually see someone using it, i have no idea if they are usefull in any way... :puzzle:

E-Slayer
January 15th, 2006, 01:41 AM
i doubt a profesional will buy something like this :shifty: its just too slow :lol:

i spent like 10 minutes drawing this :P


I know it's slow, but I wasn't sure how else to get that many colours without coding a toolbar of some sort, which (I believe) would put me over 25 lines

ElectricGrandpa
January 15th, 2006, 01:42 AM
You can use bit shift operators to set/get hex colour values easily. Check out this tutorial: http://www.macromedia.com/devnet/flash/articles/bitwise_operators.html

E-Slayer
January 15th, 2006, 01:46 AM
You can use bit shift operators to set/get hex colour values easily. Check out this tutorial: http://www.macromedia.com/devnet/flash/articles/bitwise_operators.html

Wow...I wish I had that tutorial when I made this...would've made it so much easier. I've never played with bitshifts before...