-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoodle.script
92 lines (75 loc) · 2.63 KB
/
Doodle.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
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)
class Turtle (x0:Float,y0:Float){
import java.awt._
import java.awt.geom._
var pos:Point = new Point(x0,y0);
var phi:Float = 0;
var parent:Turtle = null
var path = {
val res = new Path2D.Float()
res.moveTo(x0,y0)
res
}
def this(p:Turtle) = {
this(p.pos.x,p.pos.y)
phi = p.phi
parent = p
path = parent.path
}
def advance(len:Float) =
new Point(
pos.x + len * Math.cos(phi)
,pos.y + len * Math.sin(phi))
def line(length:Float):Turtle = {
val newPos = advance(length)
//g2d.draw(new Line2D.Float(pos,newPos))
path.lineTo(newPos.x:Float,newPos.y:Float)
pos = newPos
this
}
def circle(radius:Float):Turtle = {
path.append(new Ellipse2D.Float(
pos.x-radius,pos.y-radius
,radius*2,radius*2),false);
this
}
def rotate(grad:Float) = {
phi = phi + 2*Math.PI*grad/360
this
}
def pop:Turtle = {
if (parent != null)
parent.path.moveTo(parent.pos.x:Float,parent.pos.y:Float)
parent
}
def push:Turtle = new Turtle(this)
def draw = g2d.draw(path)
}
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 t = new Turtle(width/2,height);
t.rotate(-90)
hsb(0.6,0.7,0.4,1);
val schritte = 50
def m(i:Int)={
def v(von:Float,bis:Float) =
von + (bis - von) * (i%schritte) / schritte
val t3 = new Turtle(width/2 + (i/schritte)*Math.cos(2*Math.Pi*35)*15,height)
t3.rotate(-90);
t3.rotate(v(-35,35));
t3.line(15);
t3.push.rotate(v(-110,-250)).line(15).pop
t3.rotate(v(35,-35));
t3.line(10);
t3.push.rotate(v(-135,-225)).line(10).pop
t3.push.rotate(v(135,225)).line(10).pop
t3.line(10)
t3.circle(5);
t3.draw
}
m(arg("schritt",0,schritte*4,0))