# Help on drawing API

**URL:** <https://forum.kirupa.com/t/help-on-drawing-api/857>\
**Category:** Uncategorized\
**Created:** [July 31, 2002, 11:26pm UTC](https://forum.kirupa.com/t/help-on-drawing-api/857 "2002-07-31T23:26:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kateamen](https://avatars.discourse-cdn.com/v4/letter/k/fbc32d/32.png) [@kateamen](https://forum.kirupa.com/u/kateamen)\
**Post date:** [July 31, 2002, 11:26pm UTC](https://forum.kirupa.com/t/help-on-drawing-api/857/1 "2002-07-31T23:26:15Z")

</div>

hey peeps… need help again regarding the drawing API…

if you’d look at my old posts recently I encountered a problem regarding drawing API… well actually, ilyaslamasse (thanks again) helped me come up with a way to draw a square in the screen… it’s not me drawing it actually… he ended up giving me a script wherein it writes itself on the screen…

okay… so I have the square and all… I ended up being able to draw a triangle also but that’s the same as the square coz you just end up manipulating the array values… the real prob is how to draw a circle using the same method…

can anyone help please???

just leave me a message for further questions…

thanks!!! 🙂

---

<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:** [August 1, 2002, 7:09am UTC](https://forum.kirupa.com/t/help-on-drawing-api/857/2 "2002-08-01T07:09:19Z")

</div>

one might expect the curveTo method to produce a circle. initially it seems that the circles it produces are a little wonky, but as these smart folks have shown, with a little tweaking you can get a pretty good circle.

[http://chattyfig.figleaf.com/flashcoders-wiki/index.php?CodeOnlyCircle](http://chattyfig.figleaf.com/flashcoders-wiki/index.php?CodeOnlyCircle)

---

<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:** [August 1, 2002, 7:19am UTC](https://forum.kirupa.com/t/help-on-drawing-api/857/3 "2002-08-01T07:19:24Z")

</div>

hi… thanks for posting back…

I tried putting the code in through the expert mode coz i figure it wouldn’t matter which way I inputed it but then nothing turns out… do I do anything to the keyframe first before putting an action into the frame???

thanks… :nerd:

Movieclip.prototype.drawCircle(r, x, y) {  
var rx = r+x, ry = r + y, xr = x - r, yr = y - r;  
var r07 = r \* 0.7071, r04 = r \* 0.4142;

```
	this.moveTo(rx, y);
	this.curveTo(rx, r04 + y, r07 + x, r07 + y);
	this.curveTo(r04 + x, ry, x, ry);
	this.curveTo(x - r04 , ry, x - r07 , r07 + y);
	this.curveTo(xr, r04 + y, xr, y);
	this.curveTo(xr, y - r04 , x - r07 , y - r07 );
	this.curveTo(x - r04 , yr, x, yr);
	this.curveTo(r04 + x, yr, r07 + x, y - r07 );
	this.curveTo(rx, y - r04 , rx, y);

```

}

---

<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:** [August 1, 2002, 7:57am UTC](https://forum.kirupa.com/t/help-on-drawing-api/857/4 "2002-08-01T07:57:47Z")

</div>

did you set a lineStyle before drawing the circle?

this in frame 1 will draw a circle:

```auto

MovieClip.prototype.drawCircle = function(r, x, y){
	this.moveTo(x+r, y);
	this.curveTo(r+x, -0.4142*r+y, 0.7071*r+x, -0.7071*r+y);
	this.curveTo(0.4142*r+x, -r+y, x, -r+y);
	this.curveTo(-0.4142*r+x, -r+y, -0.7071*r+x, -0.7071*r+y);
	this.curveTo(-r+x, -0.4142*r+y, -r+x, y);
	this.curveTo(-r+x, 0.4142*r+y, -0.7071*r+x, 0.7071*r+y);
	this.curveTo(-0.4142*r+x, r+y, x, r+y);
	this.curveTo(0.4142*r+x, r+y, 0.7071*r+x, 0.7071*r+y);
	this.curveTo(r+x, 0.4142*r+y, r+x, y);
}

_root.lineStyle(0);
_root.drawCircle(50,100,100);

```

---

<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:** [August 1, 2002, 8:02am UTC](https://forum.kirupa.com/t/help-on-drawing-api/857/5 "2002-08-01T08:02:23Z")

</div>

Argh! Too fast! But these guys are amazing. I did a little thinggy with that prototype: put this in the first frame of your movie, then press, drag and release

```auto
MovieClip.prototype.drawCircle = function(r, x, y){
		this.moveTo(x+r, y);
		this.curveTo(r+x, -0.4142*r+y, 0.7071*r+x, -0.7071*r+y);
		this.curveTo(0.4142*r+x, -r+y, x, -r+y);
		this.curveTo(-0.4142*r+x, -r+y, -0.7071*r+x, -0.7071*r+y);
		this.curveTo(-r+x, -0.4142*r+y, -r+x, y);
		this.curveTo(-r+x, 0.4142*r+y, -0.7071*r+x, 0.7071*r+y);
		this.curveTo(-0.4142*r+x, r+y, x, r+y);
		this.curveTo(0.4142*r+x, r+y, 0.7071*r+x, 0.7071*r+y);
		this.curveTo(r+x, 0.4142*r+y, r+x, y);
}

_root.lineStyle(2,0x000000,100);
_root.onMouseDown=function(){
	x=_xmouse;
	y=_ymouse;
	}
_root.onMouseUp=function(){
	var dx=_xmouse-x;
	var dy=_ymouse-y;
	this.drawCircle(Math.sqrt(dx*dx+dy*dy),x,y);
}

```

pom :asian:

---

<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:** [August 1, 2002, 8:08am UTC](https://forum.kirupa.com/t/help-on-drawing-api/857/6 "2002-08-01T08:08:55Z")

</div>

or just slightly different, the prototype then:

```auto

_root.onMouseDown=function(){
	x=_xmouse;
	y=_ymouse;
	this.onMouseMove = function(){
		var dx=_xmouse-x;
		var dy=_ymouse-y;
		this.clear();
		this.lineStyle(2);
		this.drawCircle(Math.sqrt(dx*dx+dy*dy),x,y);
	}
}
_root.onMouseUp=function(){
	this.onMouseMove = null;
}

```

---

<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:** [August 1, 2002, 12:28pm UTC](https://forum.kirupa.com/t/help-on-drawing-api/857/7 "2002-08-01T12:28:42Z")

</div>

😛 Nice! And you can do pretty much the same with all kinds of forms… I can see there’s even the code for an ellipse on that site. Lots of fun in perspective 🙂

pom :asian:

---

<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:** [August 1, 2002, 12:36pm UTC](https://forum.kirupa.com/t/help-on-drawing-api/857/8 "2002-08-01T12:36:55Z")

</div>

Oh, but I just noticed: with your code, you can only have 1 circle at a time, contrary to my example. Gnark gnark gnark:P

```auto
i=1;
_root.onMouseDown=function(){
	this.createEmptyMovieClip("holder"+i,i);
	x=_xmouse;
	y=_ymouse;
	_root["holder"+i].onMouseMove = function(){
		var dx=_xmouse-x;
		var dy=_ymouse-y;
		this.clear();
		this.lineStyle(2);
		this.drawCircle(Math.sqrt(dx*dx+dy*dy),x,y);
	}
}
_root.onMouseUp=function(){
	_root["holder"+i].onMouseMove = null;
	i++;
}

```

pom :asian:
