Category Archives: setPixel

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...

Also posted in BitmapData, pixel manipulation | 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....

Also posted in BitmapData, misc, pixel manipulation | 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:

Also posted in BitmapData, pixel manipulation | Tagged , , | Leave a comment

Another Perlin Texture

Actionscript:
  1. var canvas:BitmapData = new BitmapData(1200,1200,false, 0x000000);
  2. addChild(new Bitmap(canvas));
  3.  
  4. scaleX = scaleY = 0.5;
  5. var w:int = canvas.width
  6. var hw:int = w / 2;
  7. var hhw:int = hw / 2;
  8. var size:int = canvas.width * canvas.width;
  9.  
  10. canvas.perlinNoise(hhw,hhw,1,Math.random()*100,false, false, 1, true);
  11.  
  12. for (var i:int = 0; i<size; i++){
  13.     var xp:int = i % w;
  14.     var yp:int = int(i / w);
  15.     var col:uint =  canvas.getPixel(xp, yp) / (-20|i+xp)>> 8 & 0xFF
  16.     canvas.setPixel(xp, yp, col <<16 | col <<8 | col);
  17. }
  18.  
  19. canvas.applyFilter(canvas, canvas.rect, new Point(0,0), new BlurFilter(4,4,1));
  20. var blur:BitmapData = canvas.clone();
  21. blur.applyFilter(blur, blur.rect, new Point(0,0), new BlurFilter(10,10,1));
  22.  
  23. canvas.draw(blur, null, null, BlendMode.DARKEN);

This is a variation on yesterdays post. I think it's time to optimize this and see how it does in real time...

Here is what this snippet will draw:

Also posted in BitmapData, misc, pixel manipulation | Tagged , , | 2 Comments