Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package;
- // 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 PlantOutput {
- public var length:Int;
- public var diameter:Int;
- public var branchCount:Int;
- public var leavesOnBranchCount:Int;
- public var plantColorRGB:Int;
- public function new(length:Int, diameter:Int, branchCount:Int, leavesOnBranchCount:Int, plantColorRGB:Int) {
- this.length = length;
- this.diameter = diameter;
- this.branchCount = branchCount;
- this.leavesOnBranchCount = leavesOnBranchCount;
- this.plantColorRGB = plantColorRGB;
- }
- }
- class PlantOutputRangeManager {
- @:isVar public var lengthRange(default, null):Range;
- @:isVar public var diameterRange(default, null):Range;
- @:isVar public var branchCountRange(default, null):Range;
- @:isVar public var leavesOnBranchCountRange(default, null):Range;
- @:isVar public var plantColorRGBRange(default, null):Range;
- public function new(lengthRange:Range, diameterRange:Range, branchCountRange:Range, leavesOnBranchCountRange:Range, plantColorRGBRange:Range) {
- this.lengthRange = lengthRange;
- this.diameterRange = diameterRange;
- this.branchCountRange = branchCountRange;
- this.leavesOnBranchCountRange = leavesOnBranchCountRange;
- this.plantColorRGBRange = plantColorRGBRange;
- }
- }
- class PlantInputManager {
- @:isVar public var soilAcidity(default, null):Int;
- @:isVar public var hotTimeInSecs(default, null):Int;
- @:isVar public var coldTimeInSecs(default, null):Int;
- @:isVar public var rainGramsPerSecond(default, null):Int;
- @:isVar public var midHotTimeSunRadiation(default, null):Int;
- @:isVar public var midColdTimeSunRadiation(default, null):Int;
- public function new(soilAcidityRange:Range, hotTimeInSecsRange:Range, coldTimeInSecsRange:Range, rainGramsPerSecondRange:Range,
- midHotTimeSunRadiationRange:Range, midColdTimeSunRadiationRange:Range) {
- Random.init(100);
- trace(soilAcidityRange.from);
- trace(soilAcidityRange.to);
- this.soilAcidity = Random.getIn(soilAcidityRange.from, soilAcidityRange.to);
- this.hotTimeInSecs = Random.getIn(hotTimeInSecsRange.from, hotTimeInSecsRange.to);
- this.coldTimeInSecs = Random.getIn(coldTimeInSecsRange.from, coldTimeInSecsRange.to);
- this.rainGramsPerSecond = Random.getIn(rainGramsPerSecondRange.from, rainGramsPerSecondRange.to);
- this.midHotTimeSunRadiation = Random.getIn(midHotTimeSunRadiationRange.from, midHotTimeSunRadiationRange.to);
- this.midColdTimeSunRadiation = Random.getIn(midColdTimeSunRadiationRange.from, midColdTimeSunRadiationRange.to);
- }
- }
- class Plant {
- var secPercent:Int;
- var intHotTime:Bool = true;
- private var pim:PlantInputManager;
- private var porm:PlantOutputRangeManager;
- public function new(secPercent:Int, intHotTime:Bool = true, pim:PlantInputManager, porm:PlantOutputRangeManager, seed:Int = 1212) {
- if (secPercent < 0 || secPercent > 100) {
- throw "secPercent must be in range of [0, 100]";
- }
- this.secPercent = secPercent;
- this.intHotTime = intHotTime;
- this.pim = pim;
- this.porm = porm;
- }
- public function outputPlantData():PlantOutput {
- return new PlantOutput(this.pim.soilAcidity * 22, 1, 1, 1, 1); // dummy
- }
- }
- class Main {
- /*static function update():Void {}
- static function render(frames:Array<Framebuffer>):Void {
- }*/
- public static function main() {
- var pim = new PlantInputManager(new Range(0, 100), new Range(31557600, 31557600 * 5), new Range(31557600, 31557600 * 5), new Range(0, 1000), new Range
- (0, 1000), new Range(0, 1000));
- var porm = new PlantOutputRangeManager(new Range(0, 1000), new Range(0, 100), new Range(0, 10000), new Range(0, 1000), new Range(0, 16777216));
- var p = new Plant(20, true, pim, porm);
- trace(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