Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.45 KB | None | 0 0
  1. package;
  2.  
  3. import luxe.Draw;
  4. import luxe.Input;
  5. import luxe.Sprite;
  6. import luxe.Color;
  7. import luxe.Vector;
  8. import phoenix.Shader;
  9. import phoenix.Texture;
  10. import snow.utils.UInt8Array;
  11.  
  12. class Main extends luxe.Game
  13. {
  14.     var block:Sprite;
  15.    
  16.     var threshholds:Array<Float> = [0, 255 * 0.2, 255 * 0.3, 255 * 0.5, 255 * 0.8, 255 * 0.9, 255];
  17.    
  18.     override function ready() {
  19.        
  20.         genTex();
  21.        
  22.         block = new Sprite( {
  23.             name: 'a sprite',
  24.             pos: Luxe.screen.mid,
  25.             texture: Luxe.resources.find_texture("perlin")
  26.         });
  27.     }
  28.    
  29.     function genTex()
  30.     {
  31.         trace("genTex");
  32.         var _2darray:Array<Array<Int>> = PerlinNoise.makePerlinNoise(256, 128, 0, 0, 0, Std.int(Math.random() * 2000000));
  33.        
  34.         for (i in 0...128)
  35.         {
  36.             var newA = new Array<Int>();
  37.             for (ii in 0...256)
  38.             {
  39.                 newA[ii] = _2darray[i][ii];
  40.             }
  41.             _2darray[i] = newA;
  42.             for (x in 0...newA.length)
  43.             {
  44.                 var cur = newA[x];
  45.                 var col = -(new Color().rgb(cur).r) * 255;
  46.                
  47.                 for (t in 0...threshholds.length-1)
  48.                 {
  49.                     if (col < threshholds[t+1])
  50.                     {
  51.                         newA[x] = Std.int(threshholds[t]);
  52.                         break;
  53.                     }
  54.                 }
  55.             }
  56.         }
  57.         var pixels = Util.array2dToUInt8Array(_2darray);
  58.        
  59.         Texture.load_from_pixels("perlin", 256, 128, pixels);
  60.     }
  61.  
  62.     override function onkeyup(e:KeyEvent) {
  63.         if(e.keycode == Key.escape)
  64.             Luxe.shutdown();
  65.        
  66.         if (e.keycode == Key.key_r)
  67.         {
  68.             genTex();
  69.             block.texture = Luxe.resources.find_texture("perlin");
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement