Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package;
- import haxe.ds.Map;
- // import kha.Assets;
- // import kha.Framebuffer;
- // import kha.Scheduler;
- // import kha.System;
- import kha.math.Random;
- interface IRange {
- public var from(get, null):Int;
- public var to(get, null):Int;
- }
- class Range implements IRange {
- @:isVar public var from(get, null):Int;
- @:isVar public var to(get, null):Int;
- public function new(from:Int, to:Int) {
- this.from = from;
- this.to = to;
- }
- function get_from() {
- return from;
- }
- function get_to() {
- return to;
- }
- }
- class ThingByFactor {
- @:isVar public var factorMap(default, null):Map<String, Range> = new Map();
- @:isVar public var factorValueMap(default, null):Map<String, Int> = new Map();
- @:isVar public var reducers(default, null):Map<String, Float> = new Map();
- public function new() {}
- public function addFactor(indent:String, range:Range, getReducer:Range->Int->ThingByFactor->Float) {
- this.factorMap[indent] = range;
- this.factorValueMap[indent] = Random.getIn(range.from, range.to);
- this.reducers[indent] = getReducer(range, this.factorValueMap[indent], this);
- }
- public function pipe(outIndent:String, factorIdent:String, range:Range, weight:Int, ?getReducer:Range->Int->ThingByFactor->Float) {
- if (Math.isNaN(this.factorValueMap[outIndent])) {
- this.factorValueMap[outIndent] = range.to;
- }
- var y = this.factorValueMap[outIndent];
- this.factorValueMap[outIndent] = this.factorValueMap[outIndent] - Math.round((this.reducers[factorIdent] * weight) * range.to);
- trace(this.factorValueMap[outIndent] + " = " + y + " - Math.round((" + this.reducers[factorIdent] + "("+this.factorValueMap[factorIdent]+")" + " * " + weight + ") * " + range.to + ")");
- this.reducers[outIndent] = getReducer(range, this.factorValueMap[outIndent], this);
- }
- public function getValueByIdent(outIndent:String){
- return this.factorValueMap[outIndent];
- }
- }
- class Plant {
- var secPercent:Int;
- var intHotTime:Bool = true;
- public function new(secPercent:Int, intHotTime:Bool = true, seed:Int = 111112) {
- if (secPercent < 0 || secPercent > 100) {
- throw "secPercent must be in range of [0, 100]";
- }
- this.secPercent = secPercent;
- this.intHotTime = intHotTime;
- }
- public function outputPlantData() {
- Random.init(2212222);
- var tbf = new ThingByFactor();
- //----------------------------------------------------------------------------------------------------
- tbf.addFactor("rainGramsPerSecond", new Range(0, 1000), function(range:Range, value:Int, tbf:ThingByFactor) {
- return (value / range.to);
- });
- tbf.addFactor("soilAcidity", new Range(0, 100), function(range:Range, value:Int, tbf:ThingByFactor) {
- return Math.abs((range.to / 2) -value) / (range.to / 2);
- });
- tbf.addFactor("coldTimeInSecs", new Range(31557600, 31557600 * 5), function(range:Range, value:Int, tbf:ThingByFactor) {
- return 1 - (value / range.to);
- });
- tbf.addFactor("hotTimeInSecs", new Range(31557600, 31557600 * 5), function(range:Range, value:Int, tbf:ThingByFactor) {
- return Math.abs((range.to / 2) -value) / (range.to / 2);
- });
- tbf.addFactor("midHotTimeSunRadiation", new Range(0, 1000), function(range:Range, value:Int, tbf:ThingByFactor) {
- return Math.abs((range.to / 2) -value) / (range.to / 2);
- });
- tbf.addFactor("midColdTimeSunRadiation", new Range(0, 1000), function(range:Range, value:Int, tbf:ThingByFactor) {
- return Math.abs((range.to / 2) -value) / (range.to / 2);
- });
- //----------------------------------------------------------------------------------------------------
- tbf.pipe("plantLength", "rainGramsPerSecond", new Range(0, 1000), 1, function(range:Range, value:Int, tbf:ThingByFactor) {
- return 1.0;
- });
- tbf.pipe("plantLength", "coldTimeInSecs", new Range(0, 1000), 1, function(range:Range, value:Int, tbf:ThingByFactor) {
- return 1.0;
- });
- tbf.pipe("plantLength", "hotTimeInSecs", new Range(0, 1000), 1, function(range:Range, value:Int, tbf:ThingByFactor) {
- return 1.0;
- });
- tbf.pipe("plantLength", "midHotTimeSunRadiation", new Range(0, 1000), 1, function(range:Range, value:Int, tbf:ThingByFactor) {
- return 1.0;
- });
- tbf.pipe("plantLength", "soilAcidity", new Range(0, 1000), 1, function(range:Range, value:Int, tbf:ThingByFactor) {
- return 1.0;
- });
- //----------------------------------------------------------------------------------------------------
- }
- }
- class Main {
- /*static function update():Void {}
- static function render(frames:Array<Framebuffer>):Void {
- }*/
- public static function main() {
- var p = new Plant(20, true);
- p.outputPlantData();
- /*System.start({title: "Project", width: 1024, height: 768}, function(_) {
- // Just loading everything is ok for small projects
- Assets.loadEverything(function() {
- // Avoid passing update/render directly,
- // so replacing them via code injection works
- Scheduler.addTimeTask(function() {
- update();
- }, 0, 1 / 60);
- System.notifyOnFrames(function(frames) {
- render(frames);
- });
- });
- });*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement