PDA

View Full Version : Sammo #3 - Trace Me



Sammo
January 16th, 2006, 05:22 PM
"Something I made earlier!"

Only recoded for the contest rules.


Simply draw a line and then press enter.

Stage.scaleMode = "noScale";//1
defaultVars = [_root.createEmptyMovieClip("line", 1).lineStyle(2, 0x000000, 100), _root.createEmptyMovieClip("pcLine", 2).lineStyle(2, 0x007037, 100), mX = [], mY = [], i = k = completed = 0]; //2
_root.onEnterFrame = function() {
_root.onMouseDown = function() {
if (!completed) { //3
line.moveTo(_xmouse, _ymouse); //4
_root.onMouseMove = function() {
mY[i] = _ymouse;//5
mX[i] = _xmouse;//6
i++;//7
line.lineTo(_xmouse, _ymouse);//8
}
}
}
if (Key.isDown(Key.ENTER) && completed) {//9
pcLine.moveTo(mX[0], mY[0]);//10
line.clear();//11
_root.onEnterFrame = function() {
if (_root.k < mY.length) {//12
pcLine.lineTo(mX[_root.k], mY[_root.k]);//13
dot._x = mX[_root.k], dot._y = mY[_root.k];//14 15
_root.k++;//16
}
}
}
}
_root.onMouseUp = function() {
this.onMouseMove = null;//17
completed = true;//18
}
MovieClip.prototype.drawCircle = function(x, y) {
this.beginFill(0x007037, 50);//19
this._x = x, this._y = y;//20 21
for (j = 0; j <= (Math.PI*2); j += (Math.PI*2) / 360) {//22
this.lineTo(10 * Math.cos(j), 10 * Math.sin(j));//23
this.lineTo(10 * Math.cos(j + Math.PI / 360), 10 * Math.sin(j + Math.PI / 360));//24
}
}
_root.createEmptyMovieClip("dot",1000).drawCircle(-20000,-20000)//25

Ben H
January 16th, 2006, 05:26 PM
fookin' incredible!

this could be a winner!

V. Different from the one you showed me on msn!

-Ben

Jeff Wheeler
January 16th, 2006, 05:27 PM
Got an swf?

Sammo
January 16th, 2006, 05:32 PM
Got an swf?
There's one attached?

and thanks ben :D

Jeff Wheeler
January 16th, 2006, 05:40 PM
Really neat :thumb:

I could've sworn it wasn't there…

ElectricGrandpa
January 16th, 2006, 05:43 PM
defaultVars = [_root.createEmptyMovieClip("line", 1).lineStyle(2, 0x000000, 100), _root.createEmptyMovieClip("pcLine", 2).lineStyle(2, 0x007037, 100), mX = [], mY = [], i = k = completed = 0]; //2

I'm pretty sure this is multiple lines, although I've found some other places where you could probably save yourself a few lines. For example(this is a little secret), to draw a circle you can simply use:


test_mc.lineStyle(50,0xFF6600,100);
test_mc.lineTo(0.2,0);

Sammo
January 16th, 2006, 05:48 PM
I'm pretty sure this is multiple lines, although I've found some other places where you could probably save yourself a few lines. For example(this is a little secret), to draw a circle you can simply use:


test_mc.lineStyle(50,0xFF6600,100);
test_mc.lineTo(0.2,0);

Holy cow that's helpful.

Since this contest started my function to draw circles has gone down from about 15 lines to 8 to 5 now to 2 :D

======================
Update:
Here's the script without that array 25 lines again:

Stage.scaleMode = "noScale";//1
_root.createEmptyMovieClip("line", 1).lineStyle(2, 0x000000, 100); //2
_root.createEmptyMovieClip("pcLine", 2).lineStyle(2, 0x007037, 100) //3
mX = []; //4
mY = []; //5
i = k = completed = 0; //6
_root.onEnterFrame = function() {
_root.onMouseDown = function() {
if (!completed) { //7
line.moveTo(_xmouse, _ymouse); //8
_root.onMouseMove = function() {
mY[i] = _ymouse;//9
mX[i] = _xmouse;//10
i++;//11
line.lineTo(_xmouse, _ymouse);//12
}
}
}
if (Key.isDown(Key.ENTER) && completed) {//13
pcLine.moveTo(mX[0], mY[0]);//14
line.clear();//15
_root.onEnterFrame = function() {
if (_root.k < mY.length) {//16
pcLine.lineTo(dot._x = mX[_root.k], dot._y = mY[_root.k]);//17
_root.k++;//18
}
}
}
}
_root.onMouseUp = function() {
this.onMouseMove = null;//19
completed = true;//20
}
MovieClip.prototype.drawCircle = function(x, y) {
this._x = x, this._y = y;//21 22
this.lineStyle(20,0x007037,50); //23
this.lineTo(0.2,0); //24
}
_root.createEmptyMovieClip("dot",1000).drawCircle(-20000,-20000)//25

Here's another (secret) shortcut I just found:

pcLine.lineTo(mX[_root.k], mY[_root.k]);
dot._x = mX[_root.k];
dot._y = mY[_root.k];
can be displayed as:

pcLine.lineTo(dot._x = mX[_root.k], dot._y = mY[_root.k]);
:)

Seb Hughes
January 16th, 2006, 05:53 PM
Intresting.

ElectricGrandpa
January 16th, 2006, 05:59 PM
:) Yeah it's a little Flash trick that I learned somewhere on the web, can't remember where exactly... It basically takes advantage of the fact that Flash rounds the ends of lines, so if you make a really wide and short line, it actually becomes a circle. I have a feeling it's also the most processor friendly way to create a circle too, as it only uses *ONE* line segment.

The only disadvantage is that you can't have a border or anything(without using a flash 8 stroke).

Krilnon
January 16th, 2006, 07:09 PM
Yeah it's a little Flash trick that I learned somewhere on the web, can't remember where exactly...

http://www.kirupa.com/developer/actionscript/tricks/drawing_api.htm

That tutorial has been up for years, so maybe it was that.

Jeff Wheeler
January 16th, 2006, 09:43 PM
The only disadvantage is that you can't have a border or anything(without using a flash 8 stroke).

You could have one circle below another, and still have fewer lines than before. :)

ElectricGrandpa
January 17th, 2006, 12:14 AM
yeah, that would work too :) I'm pretty sure I didn't get the info from the kirupa thing, but it's possible.

kookaburra
January 17th, 2006, 01:33 AM
One suggestion..
Do not waste a line for i++ OR _root.k++

Write the previous lines as
mX = _xmouse;//6
AND
dot._x = mX[_root.k], dot._y = mY[_root.k++];//14 15

ans save two lines


Holy cow that's helpful.

Since this contest started my function to draw circles has gone down from about 15 lines to 8 to 5 now to 2 :D

======================
Update:
Here's the script without that array 25 lines again:
ActionScript Code:

Stage.scaleMode = "noScale";[I]//1
_root.createEmptyMovieClip("line", 1).lineStyle(2, 0x000000, 100); //2
_root.createEmptyMovieClip("pcLine", 2).lineStyle(2, 0x007037, 100) //3
mX = []; //4
mY = []; //5
i = k = completed = 0; //6
_root.onEnterFrame = function() {
&nbsp;&nbsp;&nbsp;&nbsp;_root.onMouseDown = function() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!completed) { //7
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line.moveTo(_xmouse, _ymouse); //8
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_root.onMouseMove = function() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mY = _ymouse;[I]//9
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mX = _xmouse;[I]//10
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i++;//11
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line.lineTo(_xmouse, _ymouse);//12
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;if (Key.isDown(Key.ENTER) && completed) {//13
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pcLine.moveTo(mX[0], mY[0]);//14
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line.clear();//15
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_root.onEnterFrame = function() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (_root.k < mY.length) {//16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pcLine.lineTo(dot._x = mX[_root.k], dot._y = mY[_root.k]);//17
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_root.k++;//18
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
}
_root.onMouseUp = function() {
&nbsp;&nbsp;&nbsp;&nbsp;this.onMouseMove = null;//19
&nbsp;&nbsp;&nbsp;&nbsp;completed = true;//20
}
MovieClip.prototype.drawCircle = function(x, y) {
&nbsp;&nbsp;&nbsp;&nbsp;this._x = x, this._y = y;//21 22
&nbsp;&nbsp;&nbsp;&nbsp;this.lineStyle(20,0x007037,50); //23
&nbsp;&nbsp;&nbsp;&nbsp;this.lineTo(0.2,0); //24
}
_root.createEmptyMovieClip("dot",1000).drawCircle(-20000,-20000)//25






Here's another (secret) shortcut I just found:
ActionScript Code:

pcLine.lineTo(mX[_root.k], mY[_root.k]);
dot._x = mX[_root.k];
dot._y = mY[_root.k];




can be displayed as:
ActionScript Code:

pcLine.lineTo(dot._x = mX[_root.k], dot._y = mY[_root.k]);




:)