-
-
Save memilian/f7743ff5913ca11c4bc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package; | |
import haxe.Timer; | |
import haxe.PosInfos; | |
import kha.Key; | |
import kha.Game; | |
import libnoise.ModuleBase; | |
import libnoise.generator.Perlin; | |
class TexGen extends Game { | |
public function new() { | |
super("TexGen", false); | |
} | |
override public function loadFinished() { | |
init(); | |
} | |
override public function init() : Void { | |
#if js | |
haxe.Log.trace = function(o : Dynamic, ?pos : PosInfos){ | |
untyped console.log(Std.string(o)); | |
} | |
#end | |
var perlin = new Perlin(0.03, 1.0, 0.5, 8, 123, HIGH); | |
generateImage(perlin, 512, 512); | |
} | |
public override function keyUp(k : Key, c : String) { | |
var perlin = new Perlin(0.03, 1.0, 0.5, 8, 123, HIGH); | |
generateImage(perlin, 512, 512); | |
} | |
public function generateImage(module : ModuleBase, width : Int, height : Int) : Void { | |
var startTime = Timer.stamp(); | |
var data = new Array<Float>(); | |
for (y in 0...height) { | |
for (x in 0...width) { | |
var value = getGreyValue(module.getValue(x, y, 0)); | |
data.push(value); | |
} | |
} | |
var totalTime = Timer.stamp()-startTime; | |
trace('generated values in : $totalTime'); | |
} | |
public function getGreyValue(val : Float) { | |
var val = Std.int(128 * (val + 1)); | |
return val > 255 ? 255 : val < 0 ? 0 : val; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment