Orllewin home
Drawing that used to be at the Orllewin homepage
import coracle.*
class OrllewinDrawing: Drawing() {
private var maxSpeed = 1.46f
private var familyHopCycles = 250
private val familyA = 0
private val familyB = 1
private val familyC = 2
private val bodies = mutableListOf()
private lateinit var wellA: Vector
private lateinit var wellB: Vector
private lateinit var wellC: Vector
private var bodyColour = 0x205F77
private var backgroundColour = 0xf5f2f0
override fun setup() {
(450, 350)
size= Vector((width/6) * 1.5, height/2)
wellA = Vector(width/2, height/2)
wellB = Vector((width/6) * 4.5, height/2)
wellC val minBodies = 4
val maxBodies = 8
(random(minBodies, maxBodies).toInt()) { bodies.add(Body(familyA)) }
repeat(random(minBodies, maxBodies).toInt()) { bodies.add(Body(familyB)) }
repeat(random(minBodies, maxBodies).toInt()) { bodies.add(Body(familyC)) }
repeat}
override fun draw() {
()
matchWindow.x = (width/6f) * 1.5f
wellA.x = (width/2f)
wellB.x = (width/6) * 4.5f
wellC
.y = height/2f
wellA.y = height/2f
wellB.y = height/2f
wellC(backgroundColour)
background()
noStroke
.forEach { body -> body.update().draw() }
bodies}
class Body(var family: Int){
inner private var velocity = Vector(0f, 0f)
private var location: Vector = Vector.randomPosition(width, height)
private var inFamilyCycles = 0
fun update(): Body{
val gravityWell = when (family) {
-> wellA
familyA -> wellB
familyB -> wellC
familyC else -> null
}
?.let{
gravityWellvar direction = gravityWell - location
.normalize()
direction*= 0.02f
direction
+= direction
velocity += velocity
location }
.forEach { body ->
bodiesif(body != this && body.family == family){
var bodyDirection = body.location - location
.normalize()
bodyDirection*= 0.01f
bodyDirection
+= bodyDirection
velocity .limit(maxSpeed)
velocity+= velocity
location }
}
if(inFamilyCycles > familyHopCycles){
when (family) {
-> {
familyA if(random(100) < 1 || location.distance(wellB) < location.distance(wellA)){
this.family = familyB
= 0
inFamilyCycles }
}
-> {
familyB if(random(100) < 10 || location.distance(wellC) < location.distance(wellB)){
this.family = familyC
= 0
inFamilyCycles }else if(random(100) < 10 || location.distance(wellA) < location.distance(wellB)){
this.family = familyA
= 0
inFamilyCycles }
}
-> {
familyC if(random(100) < 1 || location.distance(wellB) < location.distance(wellC)){
this.family = familyB
= 0
inFamilyCycles }
}
}
}
++
inFamilyCycles
return this
}
fun draw(){
()
noStroke
(bodyColour, 0.2f)
fill(location.x, location.y, 25)
circle
(bodyColour)
fill(location.x, location.y, 4)
circle}
}
}