Tag Archives: as3

QuickBox2D Revolute Ragdoll

Actionscript:
  1. import com.actionsnippet.qbox.*;
  2. import Box2D.Common.Math.*;
  3.  
  4. [SWF (backgroundColor=0x000000, width=700, height=600, frameRate=60)]
  5.  
  6. var sim:QuickBox2D = new QuickBox2D(this,{debug:false, frim:true, gravityY:1});
  7.  
  8. sim.setDefault({fillColor:0x113366, fillAlpha:0.8, lineColor:0x3355AA});
  9.  
  10. sim.createStageWalls();
  11.  
  12. var circle:QuickObject = sim.addCircle({x:10, y:10, radius:3});
  13. var head:QuickObject = sim.addCircle({x:5, y:5, radius:0.5});
  14. var torsoA:QuickObject = sim.addBox({x:5, y:6, width:1.5, height:0.8})
  15. var torsoB:QuickObject = sim.addBox({x:5, y:6.5, width:1.25, height:0.8})
  16. var torsoC:QuickObject = sim.addBox({x:5, y:7, width:1.0, height:0.8})
  17. var pelvis:QuickObject = sim.addBox({x:5, y:7.5, width:1.0, height:0.8})
  18. var leftLegA:QuickObject = sim.addBox({x:4.75, y:8.5, width:0.4, height:1.75});
  19. var leftLegB:QuickObject = sim.addBox({x:4.75, y:9.75, width:0.4, height:1.5});
  20. var rightLegA:QuickObject = sim.addBox({x:5.29, y:8.5, width:0.4, height:1.75});
  21. var rightLegB:QuickObject = sim.addBox({x:5.29, y:9.75, width:0.4, height:1.5});
  22. var leftArmA:QuickObject = sim.addBox({x:3.6, y:5.8, width:1.3, height:0.35});
  23. var leftArmB:QuickObject = sim.addBox({x:2.5, y:5.8, width:1.25, height:0.35});
  24. var rightArmA:QuickObject = sim.addBox({x:6.4, y:5.8, width:1.3, height:0.35});
  25. var rightArmB:QuickObject = sim.addBox({x:7.5, y:5.8, width:1.25, height:0.35});
  26.  
  27. torsoA.body.SetLinearVelocity(new b2Vec2(0, 50));
  28.  
  29. var anchor:b2Vec2 = new b2Vec2();
  30. function connect(a:QuickObject, b:QuickObject, lower:Number, upper:Number, offX:Number=0, offY:Number = 0):QuickObject{
  31.      var min:Number = Math.min(a.y, b.y);
  32.      var max:Number = Math.max(a.y, b.y);
  33.      anchor.y = min + (max - min) * 0.5 + offY;
  34.      min = Math.min(a.x, b.x);
  35.      max = Math.max(a.x, b.x);
  36.      anchor.x = min + (max - min) * 0.5 + offX;
  37.     return sim.addJoint({a:a.body, b:b.body, x1:anchor.x, y1:anchor.y, lowerAngle:lower, upperAngle:upper});
  38. }
  39.  
  40. sim.setDefault({type:"revolute", collideConnected:false, enableLimit:true, lineColor:0xFFFFFF});
  41.  
  42. connect(head, torsoA, -.2, .2);
  43. connect(torsoA, torsoB,-.2, .2);
  44. connect(torsoC, torsoB,-.2, .2);
  45. connect(torsoC, pelvis,-.2, .2);
  46.  
  47. connect(pelvis, leftLegA, -1, 1, 0, -0.5);
  48. connect(leftLegA, leftLegB, -1, 1);
  49.  
  50. connect(pelvis, rightLegA, -1, 1, 0, -0.5);
  51. connect(rightLegA, rightLegB, -1, 1);
  52.  
  53. connect(torsoA, leftArmA, -2, 1);
  54. connect(leftArmA, leftArmB, -2, 1);
  55.  
  56. connect(torsoA, rightArmA, -1, 2)
  57. connect(rightArmA, rightArmB, -1, 2)
  58.  
  59. sim.start();
  60. sim.mouseDrag();

QuickBox2D alpha 108 is finally finished and different types of joints are now possible. I'll be auto-posting joint demos over the next few days for each type of Box2D joint. Box2D joints are pretty confusing, I struggled a bit to decide on a good way to handle them in QuickBox2D, any suggestions are welcome.


Have a look at the swf:

Posted in Box2D, QuickBox2D, motion | Also tagged , , , | 1 Comment

Interesting Texture #3

Actionscript:
  1. var canvas:BitmapData = new BitmapData(1500,1000,false, 0x000000);
  2. addChild(new Bitmap(canvas));
  3. scaleX = scaleY = .5;
  4.  
  5. var w:int = canvas.width;
  6. var w10:int = w * 80;
  7. var convert:Number = Math.PI/180;
  8. var size:int = canvas.width * canvas.height;
  9. for (var i:int = 0; i<size; i++){
  10.     var xp:int = i % w;
  11.     var yp:int = int(i / w);
  12.     var xp2:int = xp * 2;
  13.     var c1:int = (255/8) * (Math.cos(xp2 * convert) - Math.sin(yp*(xp2 + 500)/w10));
  14.     if (c1 <0) c1 = 256 - c1;
  15.     c1 = (c1 <<2 | c1) ;
  16.     canvas.setPixel(xp, yp, c1 <<15 | c1 <<9 | c1 );
  17. }
  18. var m:Matrix = new Matrix();
  19. m.scale(1,-1);
  20. m.translate(0,canvas.height);
  21. var clone:BitmapData = canvas.clone();
  22. canvas.draw(clone, m, null, BlendMode.SUBTRACT);
  23. clone.draw(canvas);
  24. clone.applyFilter(clone, clone.rect, new Point(0,0), new BlurFilter(10,10,1));
  25. canvas.draw(clone, null, null, BlendMode.ADD);
  26. var gray:ColorMatrixFilter = new ColorMatrixFilter([1, 0.55, 0.55, 0,0,0.55, 0.9, 0.55, 0,0,0.55, 0.55, 0.550,0, 0,0,0,1,0]);
  27. canvas.applyFilter(canvas, canvas.rect, new Point(0,0), gray);

Soon I'll work on a real-time variation. For now, here is one more still...

Posted in BitmapData, pixel manipulation, setPixel | Also tagged , | Leave a comment

Interesting Texture #2

Actionscript:
  1. var canvas:BitmapData = new BitmapData(1000,1000,false, 0x000000);
  2. addChild(new Bitmap(canvas));
  3. scaleX = scaleY = .5;
  4.  
  5. var w:int = canvas.width;
  6. var w10:int = w * 40;
  7. var size:int = canvas.width * canvas.height;
  8. for (var i:int = 0; i<size; i++){
  9.     var xp:int = i % w;
  10.      
  11.     var yp:int = int(i / w);
  12.     var c1:int = (255/8) * (Math.cos(xp* Math.PI/180 * 2) + Math.sin(yp*(xp + 200)/w10));
  13.     if (c1 <0) c1 = 256 - c1;
  14.     c1 = (c1 <<1 | c1) ;
  15.     canvas.setPixel(xp, yp, c1 <<15 | c1 <<7 | c1 );
  16. }
  17. var m:Matrix = new Matrix();
  18. m.scale(1,-1);
  19. m.translate(0,canvas.height);
  20. var clone:BitmapData = canvas.clone();
  21. canvas.draw(clone, m, null, BlendMode.SUBTRACT);
  22. clone.draw(canvas);
  23. clone.applyFilter(clone, clone.rect, new Point(0,0), new BlurFilter(10,10,1));
  24. canvas.draw(clone, null, null, BlendMode.ADD);

Randomly bit shifting on this one is actually getting a good deal of millage.. I know I can easily optimize so that it works in realtime - could even be done in pixelbender... but going to play a bit more first before I optimize....

Posted in BitmapData, misc, pixel manipulation, setPixel | Also tagged , | Leave a comment

Interesting Texture

Actionscript:
  1. var canvas:BitmapData = new BitmapData(1000,1000,false, 0x000000);
  2. addChild(new Bitmap(canvas));
  3. scaleX = scaleY = .5;
  4.  
  5. var w:int = canvas.width;
  6. var w10:int = w * 60;
  7. var size:int = canvas.width * canvas.height;
  8. for (var i:int = 0; i<size; i++){
  9.     var xp:int = i % w;
  10.      
  11.     var yp:int = int(i / w);
  12.     var c1:int = (255/8) * (Math.cos(xp* Math.PI/180 * 2) + Math.sin(yp*yp/w10));
  13.     if (c1 <0) c1 = 256 - c1;
  14.     c1 = (c1 <<1 | c1) ;
  15.     canvas.setPixel(xp, yp, c1 <<16 | c1 <<8 | c1 );
  16. }
  17. var m:Matrix = new Matrix();
  18. m.scale(1,-1);
  19. m.translate(0,canvas.height);
  20. var clone:BitmapData = canvas.clone();
  21. canvas.draw(clone, m, null, BlendMode.SUBTRACT);
  22. clone.draw(canvas);
  23. clone.applyFilter(clone, clone.rect, new Point(0,0), new BlurFilter(10,10,1));
  24. canvas.draw(clone, null, null, BlendMode.ADD);

Having one of those days where everything I code doesn't look right to me... took a little break from other work and created this very unoptimized abstract texture... no animation so here is a bitmap:

Posted in BitmapData, pixel manipulation, setPixel | Also tagged , | Leave a comment