Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Draw a "Wavy Line" Using the Cursor / Mouse
    primarykey
    data
    text
    <p>I have now been asked by a client to draw a wavy line with the cursor/mouse such as the following:</p> <p><a href="http://www.endeavoursportsgroup.com/images/WavyLine.png" rel="nofollow noreferrer">Wavy Line http://www.endeavoursportsgroup.com/images/WavyLine.png</a></p> <p>I have the following code below which draws a line with the cursor/mouse, but I am stuck on how to make the line "wavy". This is actually modified code from drawing a dashed line I was working on earlier, so there may be some left over code from that which I will remove later.</p> <p>Can someone help me achieve the Wavy Line that I have been asked to create with my code below or suggest another way to achieve this?</p> <p>Thanks in advance!</p> <pre><code>package { import flash.display.BitmapData; import flash.display.Graphics; import flash.events.Event; import flash.events.MouseEvent; import flash.geom.Point; import flash.net.FileReference; import flash.utils.ByteArray; import mx.core.UIComponent; import mx.events.FlexEvent; import mx.graphics.codec.PNGEncoder; public class DrawingArea extends UIComponent { private var isDrawing:Boolean = false; private var x1:int; private var y1:int; private var x2:int; private var y2:int; private var LastX:int = 0; private var LastY:int = 0; public var drawColor:uint = 0x0000FF; public function DrawingArea() { super(); var p1:Point = new Point(); var p2:Point = new Point(); p1.x = 0; p1.y = 0; p2.x = 200; p2.y = 200; addEventListener(FlexEvent.CREATION_COMPLETE, function(event:FlexEvent):void { graphics.clear(); graphics.beginFill(0xffffff, 0.00001); graphics.drawRect(0, 0, width, height); graphics.endFill(); }); addEventListener( MouseEvent.MOUSE_DOWN, mouseDown ); addEventListener( MouseEvent.MOUSE_MOVE, mouseMove ); addEventListener( MouseEvent.MOUSE_UP, mouseUp); } private function mouseDown(event:MouseEvent):void { x1 = mouseX; y1 = mouseY; isDrawing = true; } private function mouseMove(event:MouseEvent):void { if (!event.buttonDown) { isDrawing = false; } x2 = mouseX; y2 = mouseY; if (isDrawing ) { var p1:Point = new Point(); var p2:Point = new Point(); p1.x = x1; p1.y = y1; p2.x = x2; p2.y = y2; graphics.lineStyle(2,0x00FF00,2); graphics.lineStyle(1, drawColor); graphics.moveTo(x1, y1); graphics.lineTo(x2, y2); x1 = x2; y1 = y2; LastX = x2; LastY = y2; } } private function mouseUp(event:MouseEvent):void { isDrawing = false; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload