Archive for the 'sketches' Category

Imperfect Boxes

Wednesday, April 7th, 2010

Today I was thinking about a simple way to draw imperfect boxes and this is what I came up with:

This technique is pretty straight forward and just uses lerp and a random offset:

Actionscript:
  1. graphics.lineStyle(0,0x000000);
  2. rect(this.graphics, new Rectangle(100,100,200,200));
  3. rect(this.graphics, new Rectangle(320, 100, 50, 200), 3);
  4. rect(this.graphics, new Rectangle(390, 100, 50, 200));
  5. rect(this.graphics, new Rectangle(460, 100, 100, 100));
  6. rect(this.graphics, new Rectangle(460, 210, 100, 120));
  7.  
  8. var g0:Shape = makeGrid();
  9. g0.x = 200;
  10. g0.y = 120;
  11.  
  12. var g1:Shape = makeGrid(15, 9, 31);
  13. g1.x = 100;
  14. g1.y = 320;
  15.  
  16.  
  17. function makeGrid(num:int = 9, cols:Number=3, size:Number=30):Shape{
  18.     var grid:Shape = new Shape();
  19.     grid.graphics.lineStyle(0,0x000000);
  20.     
  21.     addChild(grid);
  22.     var smallSize:Number = size - 10;
  23.     for (var i:int = 0; i<num; i++){
  24.         var xp:Number = (i % cols) * size;
  25.         var yp:Number = int(i / cols) * size;
  26.         rect(grid.graphics, new Rectangle(xp,yp,smallSize,smallSize), 3);
  27.     }
  28.     return grid;
  29. }
  30.  
  31. function rect(g:Graphics, rect:Rectangle, res:Number = 8):void{
  32.     var a:Point = new Point(rect.left, rect.top);
  33.     var b:Point = new Point(rect.right, rect.top);
  34.     var c:Point = new Point(rect.right, rect.bottom);
  35.     var d:Point = new Point(rect.left, rect.bottom);
  36.  
  37.     var diff:Number = ( b.x - a.x);
  38.     var dab:Number = int(diff/res);
  39.     var xp:Number, yp:Number;
  40.     var action:String;
  41.     trace(dab);
  42.     for (var i:int = 0; i<dab; i++){
  43.         action = "lineTo";
  44.         if (i == 0){
  45.             xp = a.x;
  46.             yp = a.y;
  47.             action = "moveTo"
  48.         }
  49.         xp = a.x + (diff) * (i/dab);
  50.         yp = a.y + Math.random() * 5 - 2;
  51.         g[action](xp, yp);
  52.     }
  53.     diff = c.y - b.y;
  54.     dab = int(diff / res);
  55.     for (i = 0; i<dab; i++){
  56.         xp = b.x + Math.random() * 5 - 2;
  57.         yp = b.y + (diff) * (i/dab);
  58.         g.lineTo(xp, yp);
  59.     }
  60.     diff = d.x - c.x;
  61.     dab = Math.abs(int(diff / res));
  62.     for (i = 0; i<dab; i++){
  63.         xp = c.x + (diff) * (i/dab);
  64.         yp = c.y + Math.random() * 5 - 2;
  65.         g.lineTo(xp, yp);
  66.     }
  67.     diff = a.y - d.y;
  68.     dab = Math.abs(int(diff / res));
  69.     for (i = 0; i<dab; i++){
  70.         xp = d.x + Math.random() * 5 - 2;
  71.         yp = d.y + (diff) * (i/dab);
  72.         g.lineTo(xp, yp);
  73.     }
  74. }

Znode

Monday, March 15th, 2010

I'm working on a node based editor for brainstorming. I often find myself drawing psuedo-UML on whiteboards and inside the flash IDE. I like UML but it's often more than i need so I've slowly been developing Znode... which will allow the creation of super simple diagrams like these:

I hope to have Znode finished and open sourced in a week or two. The code is all pretty simple. Here is a short feature list:

Add nodes with text
Resize nodes
Connect nodes to other nodes
Zoom in and out
Pan
Save and Load Node structures (XML format)

And for phase two of the project:
Undo and Redo functionality

Gesture Capture

Thursday, March 11th, 2010

Gesture Capture is a mini-drawing program that allows the user to draw single gestures (shapes, letters etc...) - the program then randomly scales, rotates, tints and translates these gestures repeatedly on the canvas. The user may continue to draw as it does this, the more gesture drawn, the more the program will have to randomly choose from.


Try Gesture Capture:

I created Gesture Capture as an entry for actionsnippet and something made me think of it today. I was playing with it for awhile and decided it was worth mentioning here.

The original post and code can be found here