-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ou-An Chuang
authored and
Ou-An Chuang
committed
Nov 17, 2022
1 parent
98ab349
commit 298c64b
Showing
7 changed files
with
159 additions
and
57 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "templates"] | ||
path = templates | ||
url = https://github.com/junqi108/functional-structural-model-templates.git | ||
url = https://github.com/junqi108/functional-structural-model-templates |
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,52 @@ | ||
/** | ||
* The base module for all organs. | ||
* | ||
* @author James Bristow | ||
* @version 1.0 | ||
* @since 04-08-2022 | ||
*/ | ||
abstract module Organ(float len) extends Sphere(0.1) | ||
{ | ||
{setShader(GREEN);} | ||
} | ||
|
||
/** | ||
* The bud organ. | ||
* | ||
* @author James Bristow | ||
* @version 1.0 | ||
* @since 04-08-2022 | ||
*/ | ||
module Bud extends Organ(0.1) { | ||
|
||
protected int ID; | ||
import static light.*; | ||
import static organs.*; | ||
|
||
/** | ||
* Gets a plant ID value. | ||
* | ||
* @return The organ ID. | ||
*/ | ||
public int getID() { | ||
return ID; | ||
} | ||
} | ||
const float GOLDEN_ANGLE = 137.5; | ||
const float BRANCH_ANGLE = 50; | ||
const float LEAF_ANGLE = 70; | ||
const int PHYLLOCHRON = 1; | ||
|
||
/** | ||
* Initialise the model. | ||
* | ||
*/ | ||
protected void init () | ||
protected void init() | ||
[ | ||
Axiom ==> Bud; | ||
Axiom ==> Bud(1, PHYLLOCHRON, 1); | ||
// light source is placed | ||
// above the scene | ||
==>> ^ M(50) RU(180) MyLight; | ||
] | ||
|
||
/** | ||
* Runs each time step of the simulation. | ||
*/ | ||
public void run () | ||
public void run() | ||
[ | ||
Bud ==> F(0.5) [RU(30) RH(90) Bud] [RU(-30) RH(90) Bud]; | ||
Bud(r, p, o), (p > 0) ==> Bud(r, p-1, o); | ||
b:Bud(r, p, o), (r < 10 && p == 0 && o < 4) ==> if (forall(distance(b, (* Internode *)) > 0.6)) ( | ||
RV(-0.1) Internode Node | ||
[ RL(BRANCH_ANGLE) Bud(r, PHYLLOCHRON, o+1) ] | ||
[ RL(LEAF_ANGLE) Leaf(0f) ] | ||
RH(GOLDEN_ANGLE) RV(-0.1) Internode Bud(r+1, PHYLLOCHRON, o) | ||
); | ||
|
||
Bud(r, p, o), (r == 10) ==> RV(-0.1) Internode RV(-0.1) Internode Flower; | ||
] | ||
|
||
// light model instance | ||
// 100000: number of random rays | ||
// 5: recursion depth (nb. of reflections) | ||
LightModel lm = new LightModel(100000, 5); | ||
|
||
public void grow() { | ||
// apply growth rules | ||
run(); | ||
// compute light | ||
lm.compute(); | ||
// calculate the amount of light | ||
// (integrated over the whole spectrum), | ||
// absorbed by a leaf | ||
absorb(); | ||
} | ||
|
||
protected void absorb() [ | ||
lf:Leaf ::> { | ||
// 2.25 - conversion factor W -> PAR | ||
// (photosynthetically active radiation [mikro mol/m^2/s]) | ||
lf[al] = lm.getAbsorbedPower3d(lf).integrate() * 2.25; | ||
//println(lf[al]); | ||
} | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// the light source | ||
module MyLamp extends SpotLight { | ||
{ | ||
setPower(200.0); // power in W | ||
setAttenuationDistance(50.0); // in m | ||
setAttenuationExponent(0.0); | ||
setInnerAngle(22.5 * Math.PI/180.0); | ||
setOuterAngle(30.0 * Math.PI/180.0); | ||
} | ||
} | ||
// light specification with colour (R, G, B) | ||
module MyLight extends LightNode(1.0, 1.0, 1.0) { | ||
{ setLight(new MyLamp()); } | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const ShaderRef leafmat = new ShaderRef("Leafmat"); | ||
const ShaderRef petalmat = new ShaderRef("Petalmat"); | ||
const ShaderRef internodemat = new ShaderRef("Internodemat"); | ||
const ShaderRef nodemat = new ShaderRef("Nodemat"); | ||
|
||
// buds are red spheres | ||
module Bud(int rank, int phyllo, int order) extends Sphere(0.1) { | ||
{ setShader(nodemat); } | ||
} | ||
module Node extends Sphere(0.07) { | ||
{ setShader(nodemat); } | ||
} | ||
module Internode extends Cylinder(1, 0.05) { | ||
{ setShader(internodemat); } | ||
} | ||
module Leaf(float al) extends Parallelogram(2, 1) { | ||
{ setShader(leafmat); } | ||
} | ||
module Flower ==> | ||
RU(180) Cone(0.3, 0.3).(setShader(internodemat)) | ||
M(-0.25) RL(90) | ||
[ | ||
for (int i = 1; i <= 5;i++) ( | ||
[ RU(i*360/5) RL(20) Parallelogram(2, 1).(setShader(petalmat)) ] | ||
) | ||
] | ||
RU(45) | ||
[ | ||
for (int i = 1; i <= 5; i++) ( | ||
[ RU(i*360/5) RL(40) F(0.3, 0.1, 14) | ||
RV(-0.3) F(0.3, 0.1, 14) RV(-0.3) F(0.3, 0.1, 14) ] | ||
) | ||
] | ||
RU(-45) | ||
[ | ||
for (int i = 1; i <= 5; i++) ( | ||
[ RU(i*360/5) RL(70) Frustum(0.7, 0.2, 0.05).(setColor(0x8DAF58)) ] | ||
) | ||
] | ||
; |
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