-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircles.script
71 lines (55 loc) · 1.82 KB
/
Circles.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
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
def this(p:Turtle) = {
this(p.pos.x,p.pos.y)
phi = p.phi
parent = p
}
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)
g2d.draw(new Line2D.Float(pos,newPos))
pos = newPos
this
}
def rotate(grad:Float) = {
phi = phi + 2*Math.PI*grad/360
this
}
def pop:Turtle = parent
def push:Turtle = new Turtle(this)
}
def kugeln = {
def v(w:Int) = (w%360.f)/360.f
val hs:Float = random(0,90)
val colors = Array(hs,hs+180,hs+175,hs+185,hs+5,hs-5).map(v(_))
List.range(0,30).map (i=>{
//val h = choice(Array(0.86,0.6,0.1))
val h = choice(colors)
val s = random(0.3,0.9)
val b = random(0.6,1.)
var x = random(0,width-100)
var y = random(0,height-100)
val r = random(15,50)
val grad = new java.awt.RadialGradientPaint(x+r,y+r,r
,Array(0f,1f)
,Array(hsb(h,s,b,0.9),hsb(h,s,b,0.7)))
g2d.setPaint(grad)
oval(x,y,2*r,2*r)
})}
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)
kugeln