PDA

View Full Version : Experiment: Shape Points.



λ
July 27th, 2003, 04:56 PM
This is my first posted flash experiment, other than my footers... Source code
below :)

Also, feel free to move this if it isn't in the right place. I wasn't sure where to post this in the in the first place.

this.createEmptyMovieClip("drawing_mc", 1000);
drawing_mc._x = 0; drawing_mc._y = 0;
var xArray_array = [0];
var yArray_array = [0];
for (var i = 0; i<(random(10)+10); i++) {
xArray_array.push(random(401));
yArray_array.push(random(401));
}
drawing_mc.lineStyle(1, 0x000000, 100);
drawing_mc.moveTo(xArray_array[0], yArray_array[0]);
this.onMouseDown = function() {
drawing_mc.removeMovieClip();
this.createEmptyMovieClip("drawing_mc", 1000);
drawing_mc._x = 0; drawing_mc._y = 0;
var xArray_array = [0];
var yArray_array = [0];
for (var i = 0; i<(random(10)+10); i++) {
xArray_array.push(random(401));
yArray_array.push(random(401));
}
drawing_mc.lineStyle(1, 0x000000, 100);
for (var i = 0; i<xArray_array.length; i++) {
for (var h = 0; h<yArray_array.length; h++) {
drawing_mc.lineTo(xArray_array[h], yArray_array[h]);
drawing_mc.moveTo(xArray_array[i], yArray_array[i]);
}
}
};
for (var i = 0; i<xArray_array.length; i++) {
for (var h = 0; h<yArray_array.length; h++) {
drawing_mc.lineTo(xArray_array[h], yArray_array[h]);
drawing_mc.moveTo(xArray_array[i], yArray_array[i]);
}
}

July 27th, 2003, 05:00 PM
Ok nice, but there isn't something "crazy", you're just connecting lines from what I'm seeing, njs, I would instead make it more "interactive" and add events and such...

Anyhow, Good Job. :)

senocular
July 27th, 2003, 05:01 PM
it would be nice if you could add a refresh on like a mouse click or with a button or something :)

mdipi
July 27th, 2003, 05:08 PM
thats cool but i agree with the refresh thing.

λ
July 27th, 2003, 05:20 PM
Done. ;)

You might have to clear your cache though. (Tools->Internet Options->Clear Files)

Also, when I post swfs I don't see the file, all I see is blank space the size of the swf. If I right-click the space, I see "Movie not loaded" and the rest of the flash player menu.

July 27th, 2003, 05:24 PM
njs,

Add this instead,

[<i></i>swf="http://www.skehin.com/misc/points.swf height=400 width=400"][/swf]

pom
July 27th, 2003, 07:06 PM
How about
NUM_DOTS = 10 ;
dot_arr = [] ;
this.createEmptyMovieClip ( "drawing", -1 ) ;

MovieClip.prototype.moveRandom = function () {
var dx = this.targx - this._x ;
var dy = this.targy - this._y ;
this._x += dx / 5 ;
this._y += dy / 5 ;
if ( Math.abs(dx) + Math.abs(dy) < 10 ) {
this.targx = random (400) ;
this.targy = random (400) ;
}
}
function generatePoints () {
for ( var i = 0 ; i < NUM_DOTS ; i++ ) {
dot_arr.push ( this.createEmptyMovieClip ( "d" + i, i ) ) ;
dot_arr[i].targx = dot_arr[i]._x = random (400) ;
dot_arr[i].targy = dot_arr[i]._y = random (400) ;
dot_arr[i].onEnterFrame = moveRandom ;
}
}
function renderLines () {
drawing.clear () ;
drawing.lineStyle ( 0 ) ;
for ( var j = 0 ; j < NUM_DOTS ; j++ ) {
for ( var k = j+1 ; k < NUM_DOTS ; k++ ) {
drawing.moveTo ( dot_arr[j]._x, dot_arr[j]._y ) ;
drawing.lineTo ( dot_arr[k]._x, dot_arr[k]._y ) ;
}
}
}
generatePoints () ;
this.onEnterFrame = renderLines ;pom :)

kirupa
July 27th, 2003, 07:08 PM
Pretty cool animation there njs ;)

λ
July 28th, 2003, 06:25 AM
Wow Ilyas, that code is amazing! I could never write something like that! I hope one day I'm as good at scripting as you.

senocular
July 28th, 2003, 06:27 AM
its a lot like lost's random points in kirupa-lab. Have you seen that njs?

http://www.kirupa.com/lab/randompoints.htm

TheOrangeOne
July 28th, 2003, 06:28 AM
would be nice if the lines eased into new shape instead of just appearing in new position. Other than that, very nice work!

(and yes, i think i will join you on the 'wanting to script like Ilyas' thought)

λ
July 28th, 2003, 06:35 AM
Orange, yeah, that's what Ilyas's one does.

Yeah, I've seen that experiment before. It's a pretty nice script (although coming from Lost, you would expect it to be).

pom
July 28th, 2003, 07:42 AM
Yep, it looks a bit like Lost's experiment. I guess the functions look a bit alike, the main difference being in the number of lines drawn :)

And the code is not really complicated. All you have to do, really, is to use complicated names, like render, or generate instead of draw and make... ;)