-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlaetter.scala.script
175 lines (147 loc) · 4.34 KB
/
Blaetter.scala.script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
implicit def float2int(f:Float):Int = f.intValue
implicit def double2float(d:Double):Float = d.floatValue
def choice[T](a:Array[T]):T =
a(random(0,a.length).floor)
import java.awt._
import java.awt.geom._
class Turtle(x0:Float,y0:Float) {
var pos:Point = new Point(x0,y0);
var phi:Float = 0;
var parent:Turtle = null
def this(p:Turtle) = {
this(p.pos.x,p.pos.y)
phi = p.phi
parent = p
}
def shape(s: Shape) {
g2d.draw(s)
}
def advance(len:Float) =
new Point(
pos.x + len * Math.cos(phi)
,pos.y + len * Math.sin(phi))
def line(length:Float):Unit = {
val newPos = advance(length)
shape(new Line2D.Float(pos,newPos))
pos = newPos
this
}
def move(length: Float): Unit = {
pos = advance(length)
this
}
def quad(length: Float)(ctrl: Turtle => Turtle): Unit = {
val t2 = push
val end = advance(length)
val ctrlPos = ctrl(t2).pos
shape(new QuadCurve2D.Float(pos.x, pos.y, ctrlPos.x, ctrlPos.y, end.x, end.y))
pos = end
}
def rotate(grad:Float) = {
phi = phi + 2*Math.PI*grad/360
this
}
def pop:Turtle = parent
def push:Turtle = new Turtle(this)
def asPath: PathTurtle = new PathTurtle(this, new Path2D.Float)
}
class PathTurtle(t: Turtle, val path: Path2D.Float) extends Turtle(t.pos.x, t.pos.y) {
phi = t.phi
def this(p: PathTurtle) = {
this(p, p.path)
}
override def shape(s: Shape) {
path.append(s, false)
}
def stroke {
g2d.draw(path)
}
def fill {
g2d.fill(path)
}
override def push: Turtle = new PathTurtle(this)
}
def times(i: Int)(x: => Unit) {
for (a <- 0 until i)
x
}
def baum(depth:Int,length:Float,t:Turtle):Unit =
if (depth > 0 ){
g2d.setStroke(new java.awt.BasicStroke(depth,1,1));
hsb(0.6,0.7,0.4,depth.floatValue/10);
t.line(length)
//t.rotate(-15)
val r = (10-depth).floatValue/10f*arg("winkel",0f,360f,70)
baum(depth-1,length * arg("krumm",0f,1f,0.9f),t.rotate(random(-r,r)).push)
baum(depth-1,length * arg("gerade",0f,1f,0.8f),t.push)
}
g2d.setPaint(new java.awt.RadialGradientPaint(width/2,height/2,width/2
,Array(0f,1f)
,Array(hsb(0.33,0.1,1,0.2),hsb(0.33,0.1,1,0.8))))
rect(0,0,width,height)
val w = arg("winkel", 0f, 180f, 45f)
val l = arg("length", 0f, 300f, 100f)
val l2 = arg("length2", 0f, 300f, 200f)
val staengel = arg("staengel", 0f, 100f, 0f)
val colorDev = arg("colorDev", 0.05f, 0.4f, 0.1)
val baseColor = arg("color", 0f, 1f, 0.33f)
val saturation = arg("saturation", 0f, 1f, 0.8)
val brightness = arg("brightness", 0f, 1f, 0.8)
def painter(color: Float) = Array(hsb(color,saturation,brightness,0.9+random(-0.25,0.25)),hsb(color,saturation*0.8,brightness*0.8,0.6))
def blatt(w: Float, color: Float, inputT: Turtle) = {
hsb(0.33,0.8,0.5, 0.7)
g2d.setStroke(new java.awt.BasicStroke(1f,1,1));
inputT.line(staengel)
val t = inputT.asPath
val other = t.push
val rl = l + random(-l/3f, + l/3f)
val rl2 = l2 + random(-l2/8f, + l2/8f)
t.quad(rl2) { t =>
t.rotate(-w)
t.move(rl)
t
}
t.rotate(180f)
t.quad(rl2) { t =>
other.rotate(w)
other.move(rl)
other
}
val half = inputT.push
half.move(l2/2)
g2d.setPaint(new RadialGradientPaint(half.pos.x,half.pos.y,l2/2
,Array(0f,1f)
,painter(color)))
t.fill
hsb(0.33,0.8,0.5, 0.7)
g2d.setStroke(new java.awt.BasicStroke(1f,1,1));
t.stroke
}
def blume(x: Float, colorAdjust: Float) {
val t = new Turtle(x,height);
t.rotate(-90)
times(15) {
val bl = random(0,1) < 0.12
if (bl) {
val blT = t.push
blT.rotate(-30)
blatt(w, 0.33, blT.push)
blT.rotate(60)
blatt(w, 0.33, blT.push)
}
hsb(0.33,0.7,0.4, 1);
g2d.setStroke(new java.awt.BasicStroke(5,1,1));
t.line(30f + random(-20f,20f))
t.rotate(random(-10, 10))
}
val count = arg("count", 1f, 100f, 10)
val winki = 360f / count
times(count) {
blatt(w, colorAdjust + baseColor + random(-colorDev,colorDev), t.push)
t.rotate(winki)
}
}
val blumen = arg("blumen", 0, 10, 3)
for (x <- 0 until width by (width/blumen))
blume(x+width/blumen/2, random(0,0.3))
//baum(arg("Stufen",0f,10f,10f),arg("Stammlaenge",0f,200f,100f),t)