View Full Version : lines follow cursor
crtvgrndwrks
July 24th, 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
July 24th, 2005, 02:25 PM
thats actually really cool. Well done
crtvgrndwrks
July 24th, 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
July 24th, 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
July 25th, 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.)
GW02
July 25th, 2005, 02:47 AM
In Soviet Russia... the joke never ends! (:P)
jerez_z
July 25th, 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......
GW02
July 25th, 2005, 02:53 AM
...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? ;)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.