| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Registered User
|
I made a very simple code. One ball that runs away from mouse pointer when it comes near the ball.
[as] var dx:Number=random(9)-5; var dy:Number=random(9)-5; var positX:Number; var positY:Number; _root.createEmptyMovieClip("circle_mc", 1); circle_mc._x = 200; circle_mc._y = 200; circle_mc.lineStyle(100, 0x125543, 100); circle_mc.lineTo(1, 0); positX=this.circle_mc._x; positY=this.circle_mc._y; var distan:Number; onEnterFrame = function() { positX+=dx; positY+=dy; if (positX<48 || positX>500) {dx=-dx; positX+=dx}; if (positY<50 || positY>350) {dy=-dy; positY+=dy}; distan =Math.sqrt(Math.pow(_xmouse-positX,2) + Math.pow(_ymouse-positY,2)); if (distan<150) { if (positX < _xmouse) { dx-=20/Math.exp(distan/30)}; if (positX > _xmouse) { dx+=20/Math.exp(distan/30)}; if (positY < _ymouse) { dy-=20/Math.exp(distan/30)}; if (positY > _ymouse) { dy+=20/Math.exp(distan/30)}; if (dx>10) { dx=10}; if (dx<(-10)) { dx=(-10)}; if (dy>10) { dy=10}; if (dy<(-10)) { dy=(-10)}; }; dx*=.99; dy*=.99; this.circle_mc._x=positX; this.circle_mc._y=positY; } [as] Lets spice it a bit Cole |
|
|
|
|
|
#2 |
|
Registered User
Join Date: Mar 2004
Location: White Rock, BC, Canada
Posts: 12
|
How about this
ActionScript Code:
My answer to everything... If one is good, lots are better. ![]() |
|
|
|
|
|
|
|
|
#3 |
|
Registered User
|
Nice one...respect...
I am at work right now, so I found a little time to make something different. [as] iter=50; for (var i = 0; i<iter; i++) { this.createEmptyMovieClip ("circle"+i,i); var clip = this ["circle"+i]; var color=random(0xFFFFFF); clip.lineStyle(Math.random()*30+10, color , 100); clip.lineTo(1, 0); clip._x=Math.random()*550; clip._y=Math.random()*400; clip.ClipScale=clip._xscale; clip.opa=clip._alpha; clip.dScale=Math.random()*3; clip.dx=Math.random(10)*-5; clip.dy=Math.random(10)*-5; clip.onEnterFrame =function() { if (this.ClipScale <= 30) {this.ClipScale=30}; this._xscale = this.ClipScale; if (this.ClipScale==30) { this._x=Math.random()*550; this._y=Math.random()*400; this.ClipScale=100; this._alpha=100; }; this.ClipScale-=this.dScale; this._alpha=(this._xscale-30)*10/7; this._x-=this.dx; this._y-=this.dy; var dist:Number; dist=Math.sqrt(Math.pow(_xmouse-this._x, 2)+Math.pow(_ymouse-this._y, 2)); if (dist<150) { if (this._x<_xmouse) {this.dx += 20/Math.exp(this.dist/30);} if (this._x>_xmouse) {this.dx -= 20/Math.exp(this.dist/30);} if (this._y<_ymouse) {this.dy += 20/Math.exp(this.dist/30);} if (this._y>_ymouse) {this.dy -= 20/Math.exp(this.dist/30);} if (this.dx>10) {this.dx = 10;} if (this.dx<(-10)) {this.dx = (-10);} if (this.dy>10) {this.dy = 10;} if (this.dy<(-10)) {this.dy = (-10);} }; }; } [as] Cole Last edited by CnD; 03-31-2004 at 09:42 AM.. |
|
|
|
|
|
#4 |
|
Allez les Bleus!!!
Join Date: Oct 2002
Location: Paname
Posts: 2,495
|
Since large amounts of code seem to be allowed, here you go:
Code:
_global.root = this ;
this.createEmptyMovieClip("dot", -10) ;
this.dot.lineStyle(5, 0xffffff, 100) ;
this.dot.lineTo(.45, .15) ;
this.dot._visible = 0 ;
min_dist = 100 ;
max_clip = 8 ;
damp = 1 ;
k = .01 ;
left = 0 ;
right = 300 ;
up = 0 ;
down = 300 ;
n_arcs = 2 ;
MovieClip.prototype.electricArc = function (mc1, mc2, alpha, steps, off) {
for (var n=0; n < n_arcs; n++) {
this.lineStyle (random(3), 0xffffff, alpha) ;
this.moveTo (mc1._x, mc1._y) ;
var dx = (mc2._x - mc1._x) / steps ;
var dy = (mc2._y - mc1._y) / steps ;
for (var s=1; s < steps; s++) {
var x = mc1._x + s*dx + getRandom(off) ;
var y = mc1._y + s*dy + getRandom(off) ;
this.lineTo(x, y) ;
}
this.lineTo(mc2._x, mc2._y) ;
}
}
MovieClip.prototype.checkBoundaries = function () {
if (this._x < left) {
this._x = left ;
this.vx *= -1 ;
}
if (this._x > right) {
this._x = right ;
this.vx *= -1 ;
}
if (this._y < up) {
this._y = up ;
this.vy *= -1 ;
}
if (this._y > down) {
this._y = down ;
this.vy *= -1 ;
}
}
function getDistance ( mc1, mc2 ) {
var dx = mc2._x - mc1._x ;
var dy = mc2._y - mc1._y ;
return Math.sqrt ( dx*dx + dy*dy ) ;
}
function getRandom (inter) {
return random(inter) - inter / 2 ;
}
function move () {
this._x += this.vx ;
this._y += this.vy ;
this.checkBoundaries () ;
if (this.num == max_clip-1) root.clear() ;
for (var j=this.num+1; j < max_clip; j++) {
var cl = mcs[j] ;
var dx = cl._x - this._x ;
var dy = cl._y - this._y ;
var dist = Math.sqrt(dx*dx + dy*dy) ;
if (dist < min_dist) {
var angle = Math.atan2(dy, dx) ;
var tx = this._x + min_dist * Math.cos(angle) ;
var ty = this._y + min_dist * Math.sin(angle) ;
this.vx -= (tx - this._x) * k;
this.vy -= (ty - this._y) * k;
cl.vx += (tx - this._x) * k;
cl.vy += (ty - this._y) * k;
}
if ( dist <= min_dist*2 ) {
root.electricArc(this, cl, 100-dist/2, 5, 20) ;
}
}
this.vx *= damp;
this.vy *= damp;
}
mcs = [] ;
for (var i=0; i < max_clip; i++) {
var _mc = this.dot.duplicateMovieClip("d"+i, i) ;
mcs.push(_mc) ;
_mc.num = i ;
_mc._x = random(right) ;
_mc._y = random(down) ;
_mc.vx = getRandom(10) ;
_mc.vy = getRandom(10) ;
_mc.k = k * ( random(2) ? -1 : 1 ) ;
_mc.onEnterFrame = move ;
}
|
|
|
|
|
|
#5 |
|
Allez les Bleus!!!
Join Date: Oct 2002
Location: Paname
Posts: 2,495
|
Just a simple one, in 19 lines
![]() Code:
//pom
this.createEmptyMovieClip ("_mc", -5) ;
_mc.lineStyle (0, 0, 100) ;
_mc.moveTo (20, -5) ;
_mc.lineTo (20, 5) ;
_mc.onEnterFrame = rotate ;
for (var i = 0 ; i < 70 ; i++) {
var mc = _mc.duplicateMovieClip ("d" + i, i) ;
mc._x = random (200) ;
mc._y = random (100) ;
mc.onEnterFrame = rotate ;
}
function rotate () {
var dx = _xmouse - this._x ;
var dy = _ymouse - this._y ;
var an = Math.atan2 (dy, dx) ;
this._rotation = an * 180 / Math.PI + 45 ;
}
|
|
|
|
|
|
#6 |
|
Registered User
Join Date: Mar 2004
Location: White Rock, BC, Canada
Posts: 12
|
I really just modified the last line of the rotate function.
Any random number changes were just to spread the objects out a bit on a larger field. That last bit of [pom] code is sweet. Code:
this.createEmptyMovieClip ("_mc", -5) ;
_mc.lineStyle (0, 0, 100) ;
_mc.moveTo (20, -5) ;
_mc.lineTo (20, 5) ;
_mc.onEnterFrame = rotate ;
//
for (var i = 0 ; i < 270 ; i++) {
var mc = _mc.duplicateMovieClip ("d" + i, i) ;
mc._x = random (500) ;
mc._y = random (300) ;
mc.onEnterFrame = rotate ;
}
//
function rotate () {
var dx = _xmouse - this._x ;
var dy = _ymouse - this._y ;
var an = Math.atan2 (dy, dx) ;
this._rotation += ((an * 180 / Math.PI + 45)- this._rotation)/7 ;
}
|
|
|
|
|
|
#7 |
|
Allez les Bleus!!!
Join Date: Oct 2002
Location: Paname
Posts: 2,495
|
Nice
![]() |
|
|
|
|
|
#8 |
|
Registered User
Join Date: Aug 2003
Posts: 116
|
Hey POM
thats actually pretty good...tell me have you used flash before? |
|
|
|
|
|
#9 |
|
Super Moderator
Join Date: Jan 2002
Location: Centreville, VA
Posts: 24,879
|
Very nice... Love it... That reminds me of the play that I used to do with the magnet when I was young...
![]()
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer http://CyanBlue.FlashVacuum.com http://www.FlashVacuum.com http://tutorials.FlashVacuum.com Do NOT PM, Email or Call me... Your question belongs right in this forum...
|
|
|
|
|
|
#10 | |
|
Allez les Bleus!!!
Join Date: Oct 2002
Location: Paname
Posts: 2,495
|
Quote:
![]() |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|