Filters.hx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import hxd.Key in K;
  2. class Filters extends hxd.App {
  3. var obj : h2d.Object;
  4. var bmp : h2d.Bitmap;
  5. var mask : h2d.Graphics;
  6. var disp : h2d.Tile;
  7. override function init() {
  8. engine.backgroundColor = 0x002000;
  9. mask = new h2d.Graphics(s2d);
  10. mask.beginFill(0xFF0000, 0.5);
  11. mask.drawCircle(0, 0, 60);
  12. mask.x = s2d.width*0.5-20;
  13. mask.y = s2d.height*0.5-50;
  14. obj = new h2d.Object(s2d);
  15. obj.x = s2d.width * 0.5;
  16. obj.y = s2d.height * 0.5;
  17. bmp = new h2d.Bitmap(hxd.Res.hxlogo.toTile(), obj);
  18. bmp.colorKey = 0xFFFFFF;
  19. disp = hxd.Res.normalmap.toTile();
  20. setFilters(6);
  21. var help = new h2d.Text(hxd.Res.customFont.toFont(), s2d);
  22. help.x = help.y = 5;
  23. help.text = "0:Disable 1:Blur 2:Glow 3:DropShadow 4:Displacement 5:Glow(Knockout) 6:Mix 7:ColorMatrix 8:Mask +/-:Scale";
  24. }
  25. override function update(dt:Float) {
  26. for( i in 0...10 )
  27. if( K.isPressed(K.NUMBER_0 + i) || K.isPressed(K.NUMPAD_0+i) )
  28. setFilters(i);
  29. if( K.isPressed(K.NUMPAD_ADD) ) {
  30. obj.scale(1.25);
  31. bmp.scale(1 / 1.25);
  32. }
  33. if( K.isPressed(K.NUMPAD_SUB) ) {
  34. obj.scale(1 / 1.25);
  35. bmp.scale(1.25);
  36. if( obj.scaleX < 1 ) {
  37. obj.setScale(1);
  38. bmp.setScale(1);
  39. }
  40. }
  41. bmp.x = -bmp.tile.width * 0.5 * bmp.scaleX;
  42. bmp.y = -bmp.tile.height * 0.5 * bmp.scaleY;
  43. disp.scrollDiscrete(1.2 * dt, 2.4 * dt);
  44. }
  45. function setFilters(i) {
  46. switch( i ) {
  47. case 0:
  48. obj.filter = null;
  49. case 1:
  50. obj.filter = new h2d.filter.Blur(5);
  51. case 2:
  52. obj.filter = new h2d.filter.Glow(0xFFFFFF, 100, 5);
  53. case 3:
  54. obj.filter = new h2d.filter.DropShadow(8,Math.PI/4);
  55. case 4:
  56. obj.filter = new h2d.filter.Displacement(disp,4,4);
  57. case 5:
  58. var g = new h2d.filter.Glow(0xFFFFFF, 100, 2);
  59. g.knockout = true;
  60. obj.filter = g;
  61. case 6:
  62. var g = new h2d.filter.Glow(0xFFA500, 50, 2);
  63. g.knockout = true;
  64. obj.filter = new h2d.filter.Group([g, new h2d.filter.Displacement(disp, 3, 3), new h2d.filter.Blur(3), new h2d.filter.DropShadow(8, Math.PI / 4)]);
  65. case 7:
  66. var m = new h3d.Matrix();
  67. m.identity();
  68. m.colorContrast(0.5);
  69. m.colorHue(Math.PI / 4);
  70. m.colorSaturate(-0.5);
  71. obj.filter = new h2d.filter.ColorMatrix(m);
  72. case 8:
  73. obj.filter = new h2d.filter.Mask(mask);
  74. }
  75. }
  76. static function main() {
  77. hxd.Res.initEmbed();
  78. new Filters();
  79. }
  80. }