Random lines

Code Actionscript 2.0

Frame action

createEmptyMovieClip("drawing", 1);
drawing.lineStyle(0, 0x000000, 100);
onMouseDown = function () {
mousepressed = 1;
px = _xmouse;
py = _ymouse;
drawing.moveTo(px, py);
};
onMouseUp = function () {
mousepressed = 0;
};
onEnterFrame = function () {
px = _xmouse + (random(40) - 20);
py = _ymouse + (random(40) - 20);
drawing.lineStyle(1, 0x000000, 100);
if (mousepressed == 1) {
drawing.lineTo(px, py);
}
};

Code Actionscript 3.0

addEventListener(Event.ENTER_FRAME, enterFrame); stage.addEventListener(MouseEvent.MOUSE_DOWN, press); stage.addEventListener(MouseEvent.MOUSE_UP, release); var drawing:MovieClip = new MovieClip(); drawing.graphics.lineStyle(0, 0x000000, 1); this.addChild(drawing); var mousepressed=0; function press(e:MouseEvent) { mousepressed = 1; var px = mouseX; var py = mouseY; drawing.graphics.moveTo(px, py); } function release(e:MouseEvent) { mousepressed = 0; } function enterFrame(e:Event) { var px = mouseX + (int(Math.random()*40) - 20); var py = mouseY + (int(Math.random()*40) - 20); drawing.graphics.lineStyle(1, 0x000000, 1); if (mousepressed == 1) { drawing.graphics.lineTo(px, py); } }

Description

In this example, the impact of the user only consists of setting the starting points with onMouseDown (function press in Actionscript 3). From that point on, the program continues to draw lines at random, as long as the mouse is pressed.

Download

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


Share