View Full Version : lines follow cursor
crtvgrndwrks
07-24-2005, 06:55 AM
some of you have probably seen something like this on experimental websites... i got bored and decided to see if i could come up with it. here's the link and the code:
http://creativegroundworks.com/stuff/pointToCursor.swf
height = 5;
width = 5;
spacing = 100;
counter = 0;
this.onMouseMove = function() {
counter = 0;
for(i=0;i<width;i++) {
for(j=0;j<height;j++) {
counter++;
movieName = counter+"_mc";
this.createEmptyMovieClip(movieName,counter+100);
this[movieName].lineStyle(1,0xff0000,100);
this[movieName].moveTo(i*spacing,j*spacing);
this[movieName].lineTo((_xmouse+i*spacing)/2,(_ymouse+j*spacing)/2);
}
}
}
jerez_z
07-24-2005, 02:25 PM
thats actually really cool. Well done
crtvgrndwrks
07-24-2005, 02:59 PM
thanks!
been working alot with XML and Arrays, which is where getting the two for() loops came naturally.
i've made an option to where all the lines can be housed in one MovieClip as opposed to each being its own. Don't know if this is more efficient or not, let me know anyone if you have ideas. Here is the new code. Note the comment in line 1.
//set multiMC to true if you want every line to be an individual MovieClip, set to false if you just want one MC to hold all
multiMC = false;
height = 5;
width = 10;
spacing = 100;
counter = 0;
this.onMouseMove = function() {
if (!multiMC) {
this.createEmptyMovieClip("linesMC", 1);
}
counter = 0;
for (i=0; i<width; i++) {
for (j=0; j<height; j++) {
counter++;
if (multiMC) {
movieName = counter+"_mc";
this.createEmptyMovieClip(movieName, counter+100);
this[movieName].lineStyle(1, 0xff0000, 100);
this[movieName].moveTo(i*spacing, j*spacing);
this[movieName].lineTo((_xmouse+i*spacing)/2, (_ymouse+j*spacing)/2);
} else {
linesMC.lineStyle(1, 0xff0000, 100);
linesMC.moveTo(i*spacing, j*spacing);
linesMC.lineTo((_xmouse+i*spacing)/2, (_ymouse+j*spacing)/2);
}
}
}
};
crtvgrndwrks
07-24-2005, 03:43 PM
so i decided to add a randomColor option too, why not?!
//set multiMC to true if you want every line to be an individual MovieClip, set to false if you just want one MC to hold all
var multiMC:Boolean = false;
var randomColor:Boolean = true;
var height:Number = 5;
var width:Number = 10;
var lineWidth:Number = 3;
var spacing:Number = 100;
var counter:Number = 0;
var colorListStr:String = new String("0123456789ABCDEF");
var colorStr:String;
this.onMouseMove = function() {
//creates random color for singleMC
if (!multiMC) {
this.createEmptyMovieClip("linesMC", 1);
if(randomColor) {
colorStr = "";
for (i=0; i<6; i++) {
colorStr += colorListStr.charAt(Math.round(Math.random()*(colo rListStr.length-1)));
}
} else {
colorStr = "000000";
}
}
counter = 0;
for (i=0; i<width; i++) {
for (j=0; j<height; j++) {
counter++;
if (multiMC) {
/*
the following commented out lines freeze my computer up!
if(randomColor) {
colorStr = "";
for (i=0; i<6; i++) {
colorStr += colorListStr.charAt(Math.round(Math.random()*15));
}
} else {
colorStr = "000000";
}
*/
movieName = counter+"_mc";
this.createEmptyMovieClip(movieName, counter+100);
this[movieName].lineStyle(lineWidth, "0x"+colorStr, 100);
this[movieName].moveTo(i*spacing, j*spacing);
this[movieName].lineTo((_xmouse+i*spacing)/2, (_ymouse+j*spacing)/2);
} else {
linesMC.lineStyle(lineWidth, "0x"+colorStr, 100);
linesMC.moveTo(i*spacing, j*spacing);
linesMC.lineTo((_xmouse+i*spacing)/2, (_ymouse+j*spacing)/2);
}
}
}
};
thoriphes
07-25-2005, 01:47 AM
In Soviet Russia...cursor follows lines!
(what, a little late? did I already miss the end of that joke? oh well.)
In Soviet Russia... the joke never ends! (:P)
jerez_z
07-25-2005, 02:49 AM
in soviet russia joke never lets you end
owned you g_wing :lol:
EDIT: ... now that I read it over... it seemed a lot funnier when I first thought of it......
...yeah I don't get it. ;)
PS: it's GWing_02, or GWing. You don't see me calling you j_erez, now do you? ;)
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.