Advertisement
Guest User

Untitled

a guest
Oct 10th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 4.15 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 from;
  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.     private var lengthRange:Range;
  50.     private var diameterRange:Range;
  51.     private var branchCountRange:Range;
  52.     private var leavesOnBranchCountRange:Range;
  53.     private var plantColorRGBRange: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 var soilAcidity(default, null):Int;
  66.     @:isVar var hotTimeInSecs(default, null):Int;
  67.     @:isVar var coldTimeInSecs(default, null):Int;
  68.     @:isVar var rainGramsPerSecond(default, null):Int;
  69.     @:isVar var midHotTimeSunRadiation(default, null):Int;
  70.     @:isVar var midColdTimeSunRadiation(default, null):Int;
  71.  
  72.     public function new(soilAcidityRange:Range, hotTimeInSecsRange:Range, coldTimeInSecsRange:Range, rainGramsPerSecondRange:Range,
  73.             midHotTimeSunRadiationRange:Range, midColdTimeSunRadiationRange:Range) {
  74.         this.soilAcidity = Random.getIn(soilAcidityRange.from, soilAcidityRange.to);
  75.         this.hotTimeInSecs = Random.getIn(hotTimeInSecsRange.from, hotTimeInSecsRange.to);
  76.         this.coldTimeInSecs = Random.getIn(coldTimeInSecsRange.from, coldTimeInSecsRange.to);
  77.         this.rainGramsPerSecond = Random.getIn(rainGramsPerSecondRange.from, rainGramsPerSecondRange.to);
  78.         this.midHotTimeSunRadiation = Random.getIn(midHotTimeSunRadiationRange.from, midHotTimeSunRadiationRange.to);
  79.         this.midColdTimeSunRadiation = Random.getIn(midColdTimeSunRadiationRange.from, midColdTimeSunRadiationRange.to);
  80.     }
  81. }
  82.  
  83. class Plant {
  84.     var secPercent:Int;
  85.     var intHotTime:Bool = true;
  86.  
  87.     public function new(secPercent:Int, intHotTime:Bool = true, pim:PlantInputManager, pom:PlantOutputRangeManager, seed:Int = 22) {
  88.         if (secPercent < 0 || secPercent > 100) {
  89.             throw "secPercent must be in range of [0, 100]";
  90.         }
  91.  
  92.         this.secPercent = secPercent;
  93.         this.intHotTime = intHotTime;
  94.     }
  95.  
  96.     public function outputPlantData():PlantOutput {
  97.         return new PlantOutput(1, 1, 1, 1, 1); // dummy
  98.     }
  99. }
  100.  
  101. class Main {
  102.     /*static function update():Void {}
  103.  
  104.         static function render(frames:Array<Framebuffer>):Void {
  105.     }*/
  106.     public static function main() {
  107.         var pim = new PlantInputManager(new Range(0, 100), new Range(31557600, 31557600 * 5), new Range(31557600, 31557600 * 5), new Range(0, 1000), new Range
  108.             (0, 1000), new Range(0, 1000));
  109.         var porm = new PlantOutputRangeManager(new Range(0, 1000), new Range(0, 100), new Range(0, 10000), new Range(0, 1000), new Range(0, 16777216));
  110.  
  111.         var p = new Plant(20, true, pim, porm);
  112.         trace(p.outputPlantData());
  113.  
  114.         /*System.start({title: "Project", width: 1024, height: 768}, function(_) {
  115.             // Just loading everything is ok for small projects
  116.             Assets.loadEverything(function() {
  117.                 // Avoid passing update/render directly,
  118.                 // so replacing them via code injection works
  119.                 Scheduler.addTimeTask(function() {
  120.                     update();
  121.                 }, 0, 1 / 60);
  122.                 System.notifyOnFrames(function(frames) {
  123.                     render(frames);
  124.                 });
  125.             });
  126.         });*/
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement