Advertisement
Guest User

Untitled

a guest
Oct 10th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 4.53 KB | None | 0 0
  1. package;
  2.  
  3. // import kha.Assets;
  4. // import kha.Framebuffer;
  5. // import kha.Scheduler;
  6. // import kha.System;
  7. import kha.math.Random;
  8.  
  9. interface IRange {
  10.     public var from(get, null):Int;
  11.     public var to(get, null):Int;
  12. }
  13.  
  14. class Range implements IRange {
  15.     @:isVar public var from(get, null):Int;
  16.     @:isVar public var to(get, null):Int;
  17.  
  18.     public function new(from:Int, to:Int) {
  19.         this.from = from;
  20.         this.to = to;
  21.     }
  22.  
  23.     function get_from() {
  24.         return from;
  25.     }
  26.  
  27.     function get_to() {
  28.         return to;
  29.     }
  30. }
  31.  
  32. class PlantOutput {
  33.     public var length:Int;
  34.     public var diameter:Int;
  35.     public var branchCount:Int;
  36.     public var leavesOnBranchCount:Int;
  37.     public var plantColorRGB:Int;
  38.  
  39.     public function new(length:Int, diameter:Int, branchCount:Int, leavesOnBranchCount:Int, plantColorRGB:Int) {
  40.         this.length = length;
  41.         this.diameter = diameter;
  42.         this.branchCount = branchCount;
  43.         this.leavesOnBranchCount = leavesOnBranchCount;
  44.         this.plantColorRGB = plantColorRGB;
  45.     }
  46. }
  47.  
  48. class PlantOutputRangeManager {
  49.     @:isVar public var lengthRange(default, null):Range;
  50.     @:isVar public var diameterRange(default, null):Range;
  51.     @:isVar public var branchCountRange(default, null):Range;
  52.     @:isVar public var leavesOnBranchCountRange(default, null):Range;
  53.     @:isVar public var plantColorRGBRange(default, null):Range;
  54.  
  55.     public function new(lengthRange:Range, diameterRange:Range, branchCountRange:Range, leavesOnBranchCountRange:Range, plantColorRGBRange:Range) {
  56.         this.lengthRange = lengthRange;
  57.         this.diameterRange = diameterRange;
  58.         this.branchCountRange = branchCountRange;
  59.         this.leavesOnBranchCountRange = leavesOnBranchCountRange;
  60.         this.plantColorRGBRange = plantColorRGBRange;
  61.     }
  62. }
  63.  
  64. class PlantInputManager {
  65.     @:isVar public var soilAcidity(default, null):Int;
  66.     @:isVar public var hotTimeInSecs(default, null):Int;
  67.     @:isVar public var coldTimeInSecs(default, null):Int;
  68.     @:isVar public var rainGramsPerSecond(default, null):Int;
  69.     @:isVar public var midHotTimeSunRadiation(default, null):Int;
  70.     @:isVar public var midColdTimeSunRadiation(default, null):Int;
  71.  
  72.     public function new(soilAcidityRange:Range, hotTimeInSecsRange:Range, coldTimeInSecsRange:Range, rainGramsPerSecondRange:Range,
  73.             midHotTimeSunRadiationRange:Range, midColdTimeSunRadiationRange:Range) {
  74.         Random.init(100);
  75.  
  76.         trace(soilAcidityRange.from);
  77.         trace(soilAcidityRange.to);
  78.  
  79.         this.soilAcidity = Random.getIn(soilAcidityRange.from, soilAcidityRange.to);
  80.         this.hotTimeInSecs = Random.getIn(hotTimeInSecsRange.from, hotTimeInSecsRange.to);
  81.         this.coldTimeInSecs = Random.getIn(coldTimeInSecsRange.from, coldTimeInSecsRange.to);
  82.         this.rainGramsPerSecond = Random.getIn(rainGramsPerSecondRange.from, rainGramsPerSecondRange.to);
  83.         this.midHotTimeSunRadiation = Random.getIn(midHotTimeSunRadiationRange.from, midHotTimeSunRadiationRange.to);
  84.         this.midColdTimeSunRadiation = Random.getIn(midColdTimeSunRadiationRange.from, midColdTimeSunRadiationRange.to);
  85.     }
  86. }
  87.  
  88. class Plant {
  89.     var secPercent:Int;
  90.     var intHotTime:Bool = true;
  91.     private var pim:PlantInputManager;
  92.     private var porm:PlantOutputRangeManager;
  93.  
  94.     public function new(secPercent:Int, intHotTime:Bool = true, pim:PlantInputManager, porm:PlantOutputRangeManager, seed:Int = 1212) {
  95.         if (secPercent < 0 || secPercent > 100) {
  96.             throw "secPercent must be in range of [0, 100]";
  97.         }
  98.  
  99.         this.secPercent = secPercent;
  100.         this.intHotTime = intHotTime;
  101.  
  102.         this.pim = pim;
  103.         this.porm = porm;
  104.     }
  105.  
  106.     public function outputPlantData():PlantOutput {
  107.         return new PlantOutput(this.pim.soilAcidity * 22, 1, 1, 1, 1); // dummy
  108.     }
  109. }
  110.  
  111. class Main {
  112.     /*static function update():Void {}
  113.  
  114.         static function render(frames:Array<Framebuffer>):Void {
  115.     }*/
  116.     public static function main() {
  117.         var pim = new PlantInputManager(new Range(0, 100), new Range(31557600, 31557600 * 5), new Range(31557600, 31557600 * 5), new Range(0, 1000), new Range
  118.             (0, 1000), new Range(0, 1000));
  119.         var porm = new PlantOutputRangeManager(new Range(0, 1000), new Range(0, 100), new Range(0, 10000), new Range(0, 1000), new Range(0, 16777216));
  120.  
  121.         var p = new Plant(20, true, pim, porm);
  122.         trace(p.outputPlantData());
  123.  
  124.         /*System.start({title: "Project", width: 1024, height: 768}, function(_) {
  125.             // Just loading everything is ok for small projects
  126.             Assets.loadEverything(function() {
  127.                 // Avoid passing update/render directly,
  128.                 // so replacing them via code injection works
  129.                 Scheduler.addTimeTask(function() {
  130.                     update();
  131.                 }, 0, 1 / 60);
  132.                 System.notifyOnFrames(function(frames) {
  133.                     render(frames);
  134.                 });
  135.             });
  136.         });*/
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement