# Drawing simulation

**URL:** https://forum.kirupa.com/t/drawing-simulation/22806
**Category:** flash
**Created:** [June 9, 2003, 3:23am UTC](https://forum.kirupa.com/t/drawing-simulation/22806 "2003-06-09T03:23:51Z")
**Posts on this page:** 4
**Page:** 3

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 10, 2003, 3:49am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/41 "2003-06-10T03:49:53Z")

</div>

Ok I commented my code… lemme know if there is anything specific you need me to go more into detail with…

[AS]//declare trigger variable originally set to false  
trigger = false;  
//create the 3 clips used…  
//box is the grey box in the background (created on level 1)  
//line is the uhhh line (created on level 2)  
//dot is the dot (created on level 3)  
//++depth sets each one on a new level (only 1 clip can exist on a level)  
this.createEmptyMovieClip(“box”, ++depth);  
this.createEmptyMovieClip(“line”, ++depth);  
this.createEmptyMovieClip(“dot”, ++depth);  
//use drawing API to draw dot  
//3 is line width, 0xFF0000 is hex for red, 100 is alpha  
dot.lineStyle(3, 0xFF0000, 100);  
dot.lineTo(.15, .45);  
//set dot clip to be invisible  
dot.\_visible = false;  
//set lineStyle of line you will be drawing with  
//.25 is the line width, 0 (short for black), is the color, 100 is the alpha  
line.lineStyle(.25, 0, 100);  
line.onMouseDown = function() {  
//if when the mouse is pressed it is also over the box clip  
if (box.hitTest(\_xmouse, \_ymouse, true)) {  
//if trigger is false  
if (!trigger) {  
//move the line clip the current mouse position  
this.moveTo(\_xmouse, \_ymouse);  
//make the dot clip visible  
dot.\_visible = true;  
//move the dot clip to the current mouse position  
dot.\_x=\_xmouse, dot.\_y=\_ymouse;  
//set trigger to true (so this stays in original position)  
trigger = true;  
//else… (meaning else if trigger was true)  
} else {  
//draw a line to the current mouse position  
this.lineTo(\_xmouse, \_ymouse);  
//make the dot clip invisible again  
dot.\_visible = false;  
//reset the trigger back to false  
trigger = false;  
}  
//else if the mouse is pressed when it is not over the box clip  
} else {  
//hide the dot clip again  
dot.\_visible = false;  
//reset trigger to false  
trigger = false;  
}  
};  
//draw box… same as before  
box.lineStyle(.25, 0x000000, 50);  
box.beginFill(0xEEEEEE, 50);  
box.moveTo(20, 0);  
box.lineTo(20, 420);  
box.lineTo(400, 420);  
box.lineTo(400, 0);  
box.lineTo(20, 0);  
box.endFill();[/AS]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 10, 2003, 4:01am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/42 "2003-06-10T04:01:59Z")

</div>

I was taking a look at your site and remembered that I had visited it once on the beginning of this year, if I`m right 😕  
I love the “Pixel Explosion” experiment!

Thanks for the code comments!  
Would u mind if I ask you where did you learn so much about AS?  
🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 10, 2003, 4:03am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/43 "2003-06-10T04:03:50Z")

</div>

The pixel explosion was mostly Ilyas’ coding, I did modify it to do different things though.

As for where I learned so much about AS… I answered that earlier today in another thread 😛

[http://www.kirupaforum.com/forums/showthread.php?s=&threadid=25479](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=25479)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 22, 2003, 10:37pm UTC](https://forum.kirupa.com/t/drawing-simulation/22806/44 "2003-06-22T22:37:06Z")

</div>

sorry to post in an old topic… but i just came up with a better way to limit the drawing between certain coordinates:

```auto
minX = 5;
minY = 5;
maxX = 250;
maxY = 250;
createEmptyMovieClip("line", ++depth);
line.lineStyle(0);
line.onMouseDown = function() {
    this.moveTo(_xmouse, _ymouse);
    this.onMouseMove = function() {
       **x = (_xmouse>maxX) ? maxX : ((_xmouse<minX) ? minX : _xmouse);
        y = (_ymouse>maxY) ? maxY : ((_ymouse<minY) ? minY : _ymouse);**
        this.lineTo(x, y);
    };
};
line.onMouseUp = function() {
    delete this.onMouseMove;
};

```

[Previous page](https://forum.kirupa.com/t/drawing-simulation/22806.md?page=2)
