PDA

View Full Version : Drag 'n' Drop Paint


E-Slayer
01-12-2006, 10: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
01-13-2006, 12: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
01-14-2006, 01:10 PM
It wierd :D

NiñoScript
01-14-2006, 01: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
01-14-2006, 10: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
01-14-2006, 10:35 PM
Yes, it's a bitwise shift operator.

NiñoScript
01-14-2006, 11:55 PM
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
01-15-2006, 12: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
01-15-2006, 12: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
01-15-2006, 12: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...