Random-function

Code Actionscript 2.0

Frame action

// initialize drawing createEmptyMovieClip("drawing", 1); drawing.lineStyle(0, 0x000000, 100); drawing.moveTo(0, 200); // go from left to right // and calculate function values for (px = 0; px < 400; px = px + 1) { py = graph(px); drawing.lineTo(px, py); } function graph(px) { py = random(400); return (py); }

Code Actionscript 3.0

// initialize drawing var drawing:MovieClip = new MovieClip(); drawing.graphics.lineStyle(0, 0x000000, 1); drawing.graphics.moveTo(0, 0); this.addChild(drawing); // go from left to right // and calculate function values for (var px = 0; px < 400; px = px + 1) { var py = graph(px); drawing.graphics.lineTo(px, py); } function graph(px:int) { py = int(Math.random()*400); return (py); }

Description

This script draws a wild zigzag-shaped curve. The function random(400) (Math.random(400) in Actionscript 3) returns a random value between 0 and 400.

Download

Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File


Share