From b94c66293616eea576437fed01194697bd6eb62a Mon Sep 17 00:00:00 2001 From: Bartosz Hejduk Date: Sat, 17 Apr 2021 21:03:48 +0200 Subject: [PATCH] Added chaber task --- .../Assets/LSystem/Chaber.txt | 6 ++++ .../Assets/LSystem/Chaber.txt.meta | 7 ++++ .../Assets/Scripts/Chaber.cs | 34 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 cw1/unity_artifitial_world-st/Assets/LSystem/Chaber.txt create mode 100644 cw1/unity_artifitial_world-st/Assets/LSystem/Chaber.txt.meta create mode 100644 cw1/unity_artifitial_world-st/Assets/Scripts/Chaber.cs diff --git a/cw1/unity_artifitial_world-st/Assets/LSystem/Chaber.txt b/cw1/unity_artifitial_world-st/Assets/LSystem/Chaber.txt new file mode 100644 index 00000000..b1d05b74 --- /dev/null +++ b/cw1/unity_artifitial_world-st/Assets/LSystem/Chaber.txt @@ -0,0 +1,6 @@ +#axiom +L +#rules +L -> L[/+L\L]L +K -> K +#end rules \ No newline at end of file diff --git a/cw1/unity_artifitial_world-st/Assets/LSystem/Chaber.txt.meta b/cw1/unity_artifitial_world-st/Assets/LSystem/Chaber.txt.meta new file mode 100644 index 00000000..06d4194d --- /dev/null +++ b/cw1/unity_artifitial_world-st/Assets/LSystem/Chaber.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 140af9b67d1a79d4fae241962ed88b7d +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/cw1/unity_artifitial_world-st/Assets/Scripts/Chaber.cs b/cw1/unity_artifitial_world-st/Assets/Scripts/Chaber.cs new file mode 100644 index 00000000..34ae9cd3 --- /dev/null +++ b/cw1/unity_artifitial_world-st/Assets/Scripts/Chaber.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +public class Turtle3D : TurtleLSystem +{ + public GameObject leaf; + public GameObject flower; + + public float angle; + + protected override void initLiteralInterpretation() + { + turtleInterpretation = new Dictionary>>(); + //turtleInterpretation + var transformation = Matrix4x4.Translate(new Vector3(0.0f, 0.1f, 0.0f)) * Matrix4x4.Scale(new Vector3(0.05f, 0.1f, 0.05f)); + var ltransformation = Matrix4x4.Translate(new Vector3(0.0f, 0.1f, 0.0f)) * Matrix4x4.Scale(new Vector3(1.0f, 1.3f, 1.0f)); + + turtleInterpretation.Add("&", (float[] args) => new Tuple(null, Matrix4x4.Rotate(Quaternion.Euler(angle, 0, 0)))); + turtleInterpretation.Add("^", (float[] args) => new Tuple(null, Matrix4x4.Rotate(Quaternion.Euler(-angle, 0, 0)))); + + turtleInterpretation.Add("\\", (float[] args) => new Tuple(null, Matrix4x4.Rotate(Quaternion.Euler(0, -angle, 0)))); + turtleInterpretation.Add("/", (float[] args) => new Tuple(null, Matrix4x4.Rotate(Quaternion.Euler(0, angle, 0)))); + + + turtleInterpretation.Add("+", (float[] args) => new Tuple(null, Matrix4x4.Rotate(Quaternion.Euler(0, 0, -angle)))); + turtleInterpretation.Add("-", (float[] args) => new Tuple(null, Matrix4x4.Rotate(Quaternion.Euler(0, 0, angle)))); + + turtleInterpretation.Add("C", (float[] args) => new Tuple(null, Matrix4x4.identity)); + //Wildcard how to represent any other symbol + turtleInterpretation.Add("L", (float[] args) => new Tuple(leaf, ltransformation)); + turtleInterpretation.Add("F", (float[] args) => new Tuple(flower, transformation)); + } +}