# 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:** 20
**Page:** 2

<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 9, 2003, 5:25am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/21 "2003-06-09T05:25:26Z")

</div>

I got it!  
The depth of the mask should be line`s +1.  
But I cant understand the code to create the mask.

```auto
mask.beginFill(0x000000, 10);
mask.moveTo(0, -14);
mask.lineTo(0, -380);
mask.lineTo(720, 0);
mask.lineTo(720, -14);

```

This creates a triangule and not a retangule!

---

<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 9, 2003, 5:27am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/22 "2003-06-09T05:27:27Z")

</div>

[AS]createEmptyMovieClip(“line”, ++depth);  
createEmptyMovieClip(“mask”, ++depth);  
mask.beginFill(0x000000, 100);  
mask.moveTo(20, 0);  
mask.lineTo(20, 420);  
mask.lineTo(400, 420);  
mask.lineTo(400, 0);  
mask.lineTo(20, 0);  
line.setMask(mask);  
line.lineStyle(0);  
line.onMouseDown = function() {  
this.moveTo(\_xmouse, \_ymouse);  
this.onEnterFrame = function() {  
this.lineTo(\_xmouse, \_ymouse);  
};  
};  
line.onMouseUp = function() {  
delete this.onEnterFrame;  
};[/AS]

That should work…

Ahmed: Sorry about the same level statement, I just realized what it does… 'doh

---

<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 9, 2003, 5:31am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/23 "2003-06-09T05:31:07Z")

</div>

lol… kinda tricky eh 😛

---

<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 9, 2003, 5:37am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/24 "2003-06-09T05:37:40Z")

</div>

The mask is ok now, but when I do the first click, a line is created from x=0 and y=0 to x and y mouse positions! Kind of strange!

---

<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 9, 2003, 5:58am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/25 "2003-06-09T05:58:12Z")

</div>

This is the code I remixed:

```auto
// 1. SETTING THINGS
this.createEmptyMovieClip("line", 1)
this.createEmptyMovieClip("mask", 2)
mask.beginFill(0x000000, 100);
mask.moveTo(0, -14);
mask.lineTo(0, -380);
mask.lineTo(720, -380);
mask.lineTo(720, -14);
mask.lineTo(0, -14);
line.setMask(mask);
line.lineStyle(2, 0xFF0000, 80);
line.onMouseDown = function() {
	line.lineTo(_xmouse,_ymouse);
	line.lineStyle(2,0xFF0000,100);
		this.onMouseMove = function(){
			line.lineTo(_xmouse,_ymouse);
			updateAfterEvent();
       }
}
line.onMouseUp = function() {
	this.onMouseMove = null;
}

```

Now I just want to solve the problem about the first click I reported in the last post.

---

<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 9, 2003, 6:19am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/26 "2003-06-09T06:19:07Z")

</div>

I`m kind of confusing everything. I was testing the lineTo and moveTo onMouseDown event. There are two ways of drawing. If I use lineTo, it creates a line from the last mouseUp event. So there will be just one continuous line. But if I use moveTo, everytime the mouse is up and down again, it will break up the line. I`m getting confused in my own explanation. Need to sleep!  
Thanks very much for helping me! :thumb:

see u

---

<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 9, 2003, 6:27pm UTC](https://forum.kirupa.com/t/drawing-simulation/22806/27 "2003-06-09T18:27:32Z")

</div>

Here is my new question:  
[color=red]Is it possible to do a first click to set the x and y position and on the second click a line is drawn from the first x and y position? And on third click is sets again x and y positions…thsi way I could draw separate lines?[/color]

---

<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 9, 2003, 7:04pm UTC](https://forum.kirupa.com/t/drawing-simulation/22806/28 "2003-06-09T19:04:24Z")

</div>

this might be related … not sure  
Math.max(-200, Math.min( \_xmouse , 200) );  
this gives a value between -200 and +200 that is sometimes the mouse position

---

<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 9, 2003, 7:09pm UTC](https://forum.kirupa.com/t/drawing-simulation/22806/29 "2003-06-09T19:09:27Z")

</div>

onMouseDown=function(){ lineTo(\_xmouse,\_ymouse);};

---

<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 9, 2003, 7:13pm UTC](https://forum.kirupa.com/t/drawing-simulation/22806/30 "2003-06-09T19:13:09Z")

</div>

but looking at the above code, where should I put it?

---

<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, 1:20am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/31 "2003-06-10T01:20:04Z")

</div>

linestyle(1);  
onMouseDown=function(){ this.lineTo(\_xmouse,\_ymouse);};

these two lines all by themselves in a movieclip give you the results you want. Is there any thing on top of that you want to add? I think the tough part will be restricting it to within certain bounds.

---

<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:11am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/32 "2003-06-10T03:11:56Z")

</div>

Hey clownstaples!  
This code I`ve already used in my code! :thumb: What I`m looking for is more advanced tool for drawing straigh lines.  
I`ll try to explain: ** I`m trying to draw a line just in two clicks. But when I press the mouse down again, for the third time, it does not continue drawing, but iniciate a new line. So this way I could draw separate lines! Did u get it?\*\*

Thanks anyway 🙂

---

<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:14am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/33 "2003-06-10T03:14:29Z")

</div>

every other click will start a line and every other click will finish one?

---

<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:15am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/34 "2003-06-10T03:15:39Z")

</div>

Heres a rather “simplified” method…

[AS]trigger = false;  
this.createEmptyMovieClip(“box”, ++depth);  
this.createEmptyMovieClip(“line”, ++depth);  
this.createEmptyMovieClip(“dot”, ++depth);  
dot.lineStyle(3, 0xFF0000, 100);  
dot.lineTo(.15, .45);  
dot.\_visible = false;  
line.lineStyle(.25, 0, 100);  
line.onMouseDown = function() {  
if (box.hitTest(\_xmouse, \_ymouse, true)) {  
if (!trigger) {  
this.moveTo(\_xmouse, \_ymouse);  
dot.\_visible = true;  
dot.\_x=\_xmouse, dot.\_y=\_ymouse;  
trigger = true;  
} else {  
this.lineTo(\_xmouse, \_ymouse);  
dot.\_visible = false;  
trigger = false;  
}  
} else {  
dot.\_visible = false;  
trigger = false;  
}  
};  
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]

Drop that on a frame.

[edit]made a few slight adjustments[/edit]

---

<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:16am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/35 "2003-06-10T03:16:49Z")

</div>

linestyle(1);  
onMouseDown=function(){  
if(drawing){  
this.lineTo(\_xmouse,\_ymouse);  
drawing=false;  
}  
else{  
this.moveTo(\_xmouse,\_ymouse);  
drawing=true;  
}  
};

---

<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:32am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/36 "2003-06-10T03:32:49Z")

</div>

Thats it lostinbeta :thumb:  
You are fantastic!!!  
LOVE YOU

Could u take a look at my [new thread?](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=25543)

---

<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:36am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/37 "2003-06-10T03:36:58Z")

</div>

I replied to your other thread, but considering what you want there I don’t know how much I can help, I just don’t have the time.

That is one gigantic project you are after, and from the looks of it you may be getting ahead of yourself if you don’t know much about the drawing API in Flash.

---

<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:40am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/38 "2003-06-10T03:40:49Z")

</div>

I would love to have some explanation about your code!  
If you dont mind and have some time to spend?! 🙂

Thanks to [color=red] **clownstaples** [/color] too!

---

<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:42am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/39 "2003-06-10T03:42:22Z")

</div>

Ok! No problem. I apreciate.  
Do you know about some book or tutorial that could help me?

---

<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:44am UTC](https://forum.kirupa.com/t/drawing-simulation/22806/40 "2003-06-10T03:44:41Z")

</div>

What does “trigger” do?

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

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