Avatar billede nc85 Nybegynder
27. december 2004 - 15:11 Der er 4 kommentarer

random lines

Hey eksperter!

Hvordan laver man de linier der bevæger sig med forskellig fart og placering! Man ser det tit på bannere og lign.
Avatar billede mobius6 Juniormester
27. december 2004 - 15:28 #1
der er utallige metoder, de fleste rimeligt simple
kig her og find et par stykker du kan lære noget af ;)
http://www.flashkit.com/movies/
Avatar billede alexander_j Nybegynder
02. januar 2005 - 15:16 #2
Læg det her i frame 1 - så får du linier der bevæger sig med forskellig fart og placering!

n = 0; //name
cds = 10; //change direction speed
maxs = 10; //max speed
ss = 400; //screen size
nl = 10; //number of lines
function makeline(n){
    this.createEmptyMovieClip(n, n);
    this[n].f = Math.round( Math.random()*0xFFFFFF );
    this[n].x1 = random(400); this[n].y1 = random(400); this[n].r1 = random(360); this[n].s1 = random(maxs);
    this[n].x2 = random(400); this[n].y2 = random(400); this[n].r2 = random(360); this[n].s2 = random(maxs);
    this[n].onEnterFrame = function(){
        this.c++;
        if (this.c>=cds) {
            this.c = random(cds);
            this.r1 += random(3)-1;
            this.r2 += random(3)-1;
            temp = random(3)-1; if(this.s1+temp>1 and this.s1+temp<=maxs) this.s1 += temp;
            temp = random(3)-1; if(this.s2+temp>1 and this.s2+temp<=maxs) this.s2 += temp;
        }
        this.x1 = findxy(this, this.x1, 1);
        this.y1 = findxy(this, this.y1, 1);
        this.x2 = findxy(this, this.x2, 2);
        this.y2 = findxy(this, this.y2, 2);
        drawline(this, this.f, this.x1,this.y1,this.x2,this.y2);
    }
}
function drawline(mc, f, x1, y1, x2, y2){
    mc.clear();
    mc.lineStyle(1, f, 100);
    mc.moveTo(x1,y1);
    mc.lineTo(x2,y2);
}
function findxy(mc, xy, t){
    temp = Math.cos(Math.PI/180 * mc["r"+t])*mc["s"+t];
    if(xy+temp>0 and xy+temp<ss){
        xy += temp;
    } else {
        mc["r"+t] -= 180;
        temp = Math.cos(Math.PI/180 * mc["r"+t])*mc["s"+t];
        xy += temp;
    }
    return xy;
}
for(i=0;i<nl;i++) makeline(i);
Avatar billede alexander_j Nybegynder
02. januar 2005 - 16:28 #3
Hmm der var lige lidt fejl på nogle x og y værdier, så her er der en der virker korrekt:

n = 0; //name
cds = 10; // change direction speed
mins = 3; //min speed 0-9 (men altid mindre end maxs)
maxs = 10; //max speed 2-10
ss = 400; //screen size
nl = 10; //number of lines
function makeline(n){
    this.createEmptyMovieClip(n, n);
    this[n].f = Math.round( Math.random()*0xFFFFFF );
    this[n].x1 = random(400); this[n].y1 = random(400); this[n].r1 = random(360); this[n].s1 = mins + random(maxs-mins);
    this[n].x2 = random(400); this[n].y2 = random(400); this[n].r2 = random(360); this[n].s2 = mins + random(maxs-mins);
    this[n].onEnterFrame = function(){
        this.c++;
        if (this.c>=cds) {
            this.c = random(cds);
            this.r1 += random(3)-1; if(this.r1<0) this.r1 += 360; if(this.r1>360) this.r1 -= 360;
            this.r2 += random(3)-1; if(this.r2<0) this.r2 += 360; if(this.r2>360) this.r2 -= 360;
            temp = random(3)-1; if(this.s1+temp>mins and this.s1+temp<=maxs) this.s1 += temp;
            temp = random(3)-1; if(this.s2+temp>mins and this.s2+temp<=maxs) this.s2 += temp;
        }
        this.x1 = findx(this, this.x1, 1);
        this.y1 = findy(this, this.y1, 1);
        this.x2 = findx(this, this.x2, 2);
        this.y2 = findy(this, this.y2, 2);
        drawline(this, this.f, this.x1,this.y1,this.x2,this.y2);
    }
}
function drawline(mc, f, x1, y1, x2, y2){
    mc.clear();
    mc.lineStyle(1, f, 100);
    mc.moveTo(x1,y1);
    mc.lineTo(x2,y2);
}
function findx(mc, x, t){
    temp = Math.cos(Math.PI/180 * mc["r"+t])*mc["s"+t];
    if(x+temp<=0 or x+temp>=ss) mc["r"+t] = 180 - mc["r"+t];
    x += Math.cos(Math.PI/180 * mc["r"+t])*mc["s"+t];
    return x;
}
function findy(mc, y, t){
    temp = Math.sin(Math.PI/180 * mc["r"+t])*mc["s"+t];
    if(y+temp<=0 or y+temp>=ss) mc["r"+t] = -mc["r"+t];
    y += Math.sin(Math.PI/180 * mc["r"+t])*mc["s"+t];
    return y;
}
for(i=0;i<nl;i++) makeline(i);
Avatar billede alexander_j Nybegynder
02. januar 2005 - 17:28 #4
Og nu også med farveskift :-D:

n = 0; //name
cds = 10; // change direction speed
mins = 3; //min speed 0-9 (men altid mindre end maxs)
maxs = 10; //max speed 2-10
fs = 5; //fade speed low=fast high=slow
ss = 400; //screen size
nl = 10; //number of lines
function makeline(n){
    this.createEmptyMovieClip(n, n);
    this[n].f1 = Math.round( Math.random()*0xFFFFFF );
    this[n].f2 = this[n].f1;
    this[n].x1 = random(400); this[n].y1 = random(400); this[n].r1 = random(360); this[n].s1 = mins + random(maxs-mins);
    this[n].x2 = random(400); this[n].y2 = random(400); this[n].r2 = random(360); this[n].s2 = mins + random(maxs-mins);
    this[n].onEnterFrame = function(){
        this.c++;
        if (this.c>=cds) {
            this.c = random(cds);
            this.f2 = Math.round( Math.random()*0xFFFFFF );
            this.r1 += random(3)-1; if(this.r1<0) this.r1 += 360; if(this.r1>360) this.r1 -= 360;
            this.r2 += random(3)-1; if(this.r2<0) this.r2 += 360; if(this.r2>360) this.r2 -= 360;
            temp = random(3)-1; if(this.s1+temp>mins and this.s1+temp<=maxs) this.s1 += temp;
            temp = random(3)-1; if(this.s2+temp>mins and this.s2+temp<=maxs) this.s2 += temp;
        }
        this.f1 = colorfade(this.f1,this.f2);
        this.x1 = findx(this, this.x1, 1);
        this.y1 = findy(this, this.y1, 1);
        this.x2 = findx(this, this.x2, 2);
        this.y2 = findy(this, this.y2, 2);
        drawline(this, this.f1, this.x1,this.y1,this.x2,this.y2);
    }
}
function drawline(mc, f, x1, y1, x2, y2){
    mc.clear();
    mc.lineStyle(2, f, 100);
    mc.moveTo(x1,y1);
    mc.lineTo(x2,y2);
}
function findx(mc, x, t){
    temp = Math.cos(Math.PI/180 * mc["r"+t])*mc["s"+t];
    if(x+temp<=0 or x+temp>=ss) mc["r"+t] = 180 - mc["r"+t];
    x += Math.cos(Math.PI/180 * mc["r"+t])*mc["s"+t];
    return x;
}
function findy(mc, y, t){
    temp = Math.sin(Math.PI/180 * mc["r"+t])*mc["s"+t];
    if(y+temp<=0 or y+temp>=ss) mc["r"+t] = -mc["r"+t];
    y += Math.sin(Math.PI/180 * mc["r"+t])*mc["s"+t];
    return y;
}
function colorfade(f1,f2){
    r = ((f1 & 0xFF0000) >> 16) - Math.round(( ((f1 & 0xFF0000) >> 16) - ((f2 & 0xFF0000) >> 16) )/fs);
    g = ((f1 & 0xFF00) >> 8) - Math.round(( ((f1 & 0xFF00) >> 8) - ((f2 & 0xFF00) >> 8) )/fs);
    b = (f1 & 0xFF) - Math.round( ( (f1 & 0xFF) - (f2 & 0xFF) )/fs);
    return r << 16 | g << 8 | b;
}
for(i=0;i<nl;i++) makeline(i);
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
IT-kurser om Microsoft 365, sikkerhed, personlig vækst, udvikling, digital markedsføring, grafisk design, SAP og forretningsanalyse.

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester