A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Gradually adjust thickness of dynamically created curve

  1. #1
    Senior Member
    Join Date
    Feb 2004
    Posts
    133

    Gradually adjust thickness of dynamically created curve

    Hi, guys!

    I´ve been using the following code to dynamically create curves inside my movie.


    ***********************************************
    /*
    set up vars
    p = number of points along the line; more = smoother curve
    sx = start position of the wave
    ex end of the wave
    by = size of area
    wl = the water level
    wh = height of waves
    ws = speed of wave; negative numbers make it go right
    */
    for (var i = 0; i < 6; i++) {
    this.createEmptyMovieClip("wave" + i, i);
    var w:MovieClip = this["wave" + i];
    w.p = 45;
    w.sx = 0;
    w.ex = Stage.width;
    w.by = 1;
    w.wl = 10;
    w.wh = 35;
    w.ws = -(0 + ((random(10) / 2) + .1) / 5000);
    var Ld:String = String(i / 2);
    if (Ld.length > 0) {
    w.lh = 1;
    } else {
    w.lh = 0;
    }
    w.id = i;
    w.sy = w.lh + w.wh + w.wl;
    PI2 = Math.PI * 2;
    //w._alpha = random(45) + 25;
    //don't use alpha to CPU instensive try random colors instead
    w.linecolor = 0xBBBBBB
    //w.linecolor = random(255) << 16 | random(255) << 8 | random(200);
    w.onEnterFrame = function() {
    //begin with a clean canvas
    this.clear();
    this.lineStyle(this.lh,this.linecolor);
    for (x = 0; x < this.p; x++) {
    var r:Number = x / (this.p - 1);
    var px:Number = this.sx + r * (this.ex - this.sx);
    var py:Number = this.sy + this.wh * Math.sin(r * r * PI2 + getTimer() * this.ws);
    if (x == 0) {
    this.moveTo(px, py);
    }
    this.lineTo(px, py);
    }
    };
    }
    ***********************************************

    I was wandering if there is any way to make it produce curves which thickness decrease from left to right, for instance... Is it possible?

    Thanks in advance!

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe try something like this...

    Code:
    /*
    set up vars
    p = number of points along the line; more = smoother curve
    sx = start position of the wave
    ex end of the wave
    by = size of area
    wl = the water level
    wh = height of waves
    ws = speed of wave; negative numbers make it go right
    */
    for (var i = 0; i < 6; i++) {
    	this.createEmptyMovieClip("wave" + i, i);
    	var w:MovieClip = this["wave" + i];
    	w.p = 45;
    	w.sx = 0;
    	w.ex = Stage.width;
    	w.by = 1;
    	w.wl = 10;
    	w.wh = 35;
    	w.ws = -(0 + ((random(10) / 2) + .1) / 5000);
    	var Ld:String = String(i / 2);
    	if (Ld.length > 0) {
    		w.lh = 30;
    	} else {
    		w.lh = 0;
    	}
    	w.id = i;
    	w.sy = w.lh + w.wh + w.wl;
    	PI2 = Math.PI * 2;
    	//w._alpha = random(45) + 25;
    	//don't use alpha to CPU instensive try random colors instead
    	w.linecolor = 0xBBBBBB;
    	//w.linecolor = random(255) << 16 | random(255) << 8 | random(200);
    	w.onEnterFrame = function() {
    		//begin with a clean canvas
    		this.clear();
    		this.lineStyle(this.lh, this.linecolor);
    		for (x = 0; x < this.p; x++) {
    			var r:Number = x / (this.p - 1);
    			var px:Number = this.sx + r * (this.ex - this.sx);
    			var py:Number = this.sy + this.wh * Math.sin(r * r * PI2 + getTimer() * this.ws);
    			if (x == 0) {
    				this.moveTo(px, py);
    			}
    			if (this.lh - x > 1) {
    				this.lineStyle(this.lh - x, this.linecolor);
    			}
    			this.lineTo(px, py);
    		}
    	};
    }

  3. #3
    Senior Member
    Join Date
    Feb 2004
    Posts
    133
    That´s exactly it! Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center