Modulo-operator

Code Actionscript 2.0

Frame action

// initialize drawing createEmptyMovieClip("drawing", 1); drawing.lineStyle(0, 0x000000, 100); drawing.moveTo(0, 0); // 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 = px % 100; 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 = px % 100; return (py); }

Description

With this script, you can draw a sawtooth curve. The modulo-operator % returns the remainder of a division. It returns the first operand number, if the designated value (e.g. 100) has not been exceeded.

Download

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


Share