Circle contains
Check if a point is inside the bounds of a circle
import coracle.Drawing
import coracle.Math
import coracle.TWO_PI
import coracle.random
import coracle.shapes.Circle
import coracle.shapes.Point
import kotlin.math.cos
import kotlin.math.sin
import kotlin.math.sqrt
class CircleBoundaryDrawing: Drawing() {
var boundary: Boundary
lateinit
val cells = mutableListOf()
val cellRadius = 12
override fun setup() {
(450, 450)
size
= Boundary(width/2, height/2, (width * 0.75f)/2)
boundary
()
noStroke}
override fun draw() {
(0xf5f2f0)
background.drawBoundary()
boundary
()
noStroke
val point = randomPoint()
val cell = Cell(point.x, point.y)
if(boundary contains cell) cell.colour = 0x33aa33
.add(cell)
cells
.forEach(Cell::drawCell)
cells
if(cells.size > 250) cells.clear()
}
private fun randomPoint(): Point {
val a = random(0f, 1f) * TWO_PI
val r = (width * 0.85f)/2 * sqrt(random(0f, 1f))
val x = r * cos(a)
val y = r * sin(a)
return Point(width/2 + x.toFloat(), height/2 + y.toFloat())
}
class Cell(x: Float, y: Float): Point(x, y) {
inner var colour = 0xa9a9a9
fun drawCell(){
(colour, 0.2f)
fill(x, y, 10)
circle}
}
class Boundary(x: Int, y: Int, r: Float): Circle(x, y, r) {
inner
fun drawBoundary(){
()
noFill(0x1d1d1d)
stroke(boundary.x, boundary.y, r)
circle}
}
}