Posted By

publicbroadcast on 07/16/09


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

SmpleJohn
Demian


drawing


 / Published in: ActionScript 3
 

  1. var loc:Vector.<Point> = new Vector.<Point>();
  2. var lifts:Vector.<int> = new Vector.<int>();
  3. var index:int = 0;
  4. var resolution:int = 1;
  5. var down:Boolean;
  6. stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
  7. stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
  8. stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyReleased);
  9. addEventListener(Event.ENTER_FRAME, onLoop);
  10. function onKeyReleased(evt:KeyboardEvent):void{
  11. if (evt.keyCode == Keyboard.RIGHT){
  12. resolution -= 1;
  13. if (resolution <1) resolution = 1;
  14. }else
  15. if (evt.keyCode == Keyboard.LEFT){
  16. resolution += 1;
  17. }
  18. }
  19. function onDown(evt:MouseEvent):void{
  20. down = true;
  21. lifts.push(index);
  22. }
  23. function onUp(evt:MouseEvent):void{
  24. down = false;
  25. }
  26. function onLoop(evt:Event):void {
  27. if (down){
  28. loc[index] = new Point(mouseX, mouseY);
  29. index++;
  30. }
  31. graphics.clear();
  32. graphics.lineStyle(0,0x000000);
  33. var j:int = 0;
  34. var lift:int;
  35. var liftLength:int = lifts.length;
  36. var lastLoc:int = loc.length - 1;
  37. for (var i:int = 0; i<liftLength; i++){
  38. j = lifts[i];
  39. graphics.moveTo(loc[j].x, loc[j].y);
  40. if (i <liftLength - 1){
  41. lift = lifts[i + 1] - 1;
  42. }else{
  43. lift = lastLoc;
  44. }
  45. while (j <lift){
  46. j++;
  47. if (j % resolution == 1 || resolution == 1){
  48. graphics.lineTo(loc[j].x, loc[j].y);
  49. }
  50. }
  51. graphics.lineTo(loc[j].x, loc[j].y);
  52. }
  53. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: SmpleJohn on July 17, 2009

Just a tid-bit. For those wanting smoother lines, bump up the frame rate. Had mine at 60 for good results.

You need to login to post a comment.