Code Sketch
Mandala - 1
Category: Art
cleari()
clearOutput()
val lightFilter = new com.jhlabs.image.LightFilter
lightFilter.getLights.clear()
val lg2 = effect(lightFilter)
val light = new lightFilter.DistantLight()
light.setAzimuth(90.toRadians)
light.setElevation(0.toRadians)
lightFilter.addLight(light)
val bg = lg2 -> Picture.rectangle(cwidth, cheight)
.withTranslation(-cwidth / 2, -cheight / 2)
.withFillColor(cm.linearGradient(0, 0, ColorMaker.hsl(214, 1.00, 0.35), -150, 225, cm.white, false))
drawCentered(bg)
//Linear Gradient Color
val lg = cm.linearGradient(-5, -5, cm.black, 1, 50, cm.white, false)
//Center of mandala
val center = Picture.circle(25)
.withPenColor(lg)
//Circle outside the centres
val pattern = Picture.circle(107)
.withPenColor(cm.linearGradient(-10, -5, cm.black, -100, 50, cm.white, false))
val pattern2 = Picture.circle(50)
.withPenColor(lg)
//Pattern no: 1 Semi Circular pattern
def semiCircularPetal(radius: Double, theta: Double, thetaExtent: Double) = Picture.fromVertexShape { s =>
val tDelta = thetaExtent / 2
import s._
beginShape()
curveVertexRt(radius, theta - tDelta)
curveVertexRt(radius, theta - tDelta)
curveVertexRt(radius + (0.7010526 * thetaExtent), theta - tDelta / 2)
curveVertexRt(radius + (0.93333 * thetaExtent), theta)
curveVertexRt(radius + (0.7010526 * thetaExtent), theta + tDelta / 2)
curveVertexRt(radius, theta + tDelta)
curveVertexRt(radius, theta + tDelta)
endShape()
}
val pattern3 = semiCircularPetal(50, 0, 50)
//Recursive semi circular pattern
def patterns(n: Int): Picture = {
if (n == 1) {
pattern3
.withPenColor(lg)
}
else {
val rotation = 360 / 8
picStack(
pattern3
.withPenColor(lg),
patterns(n - 1)
.withRotation(rotation)
.withPenColor(lg)
)
}
}
//Another circle
val pattern4 = Picture.circle(100)
.withPenColor(cm.linearGradient(-10, -5, cm.black, 10, 50, cm.white, false))
//Lotus petal
def lotusPetal(radius: Double, radiusOuter: Double,
theta: Double, thetaExtent: Double) = Picture.fromVertexShape { s =>
import s._
val tDelta = thetaExtent / 2
beginShape()
curveVertexRt(radius, theta - tDelta)
curveVertexRt(radius, theta - tDelta)
val rExtent = radiusOuter / radius
curveVertexRt(mathx.lerp(radius, radius * rExtent, 0.6), theta - tDelta * 22 / 30)
curveVertexRt(mathx.lerp(radius, radius * rExtent, 0.7), theta - tDelta * 2 / 30)
curveVertexRt(radius * rExtent, theta)
curveVertexRt(mathx.lerp(radius, radius * rExtent, 0.7), theta + tDelta * 2 / 30)
curveVertexRt(mathx.lerp(radius, radius * rExtent, 0.6), theta + tDelta * 22 / 30)
curveVertexRt(radius, theta + tDelta)
curveVertexRt(radius, theta + tDelta)
endShape()
}
val pic = lotusPetal(175, 200, 8 * 40, 45)
.withRotation(-50)
.withScaling(0.7)
//Recursive lotus petal
def pattern5(n: Int): Picture = {
if (n == 1) {
pic
.withPenColor(cm.linearGradient(0, -5, cm.black, 0, 50, cm.white, false))
}
else {
val rotation = 360 / 8
picStack(
pic
.withPenColor(cm.linearGradient(0, -5, cm.black, 0, 50, cm.white, false)),
pattern5(n - 1)
.withRotation(rotation)
.withPenColor(cm.linearGradient(0, -5, cm.black, 0, 50, cm.white, false))
)
}
}
//Diya
def diya(radius: Double, radiusOuter: Double,
theta: Double, thetaExtent: Double) = Picture.fromVertexShape { s =>
import s._
val tDelta = thetaExtent / 2
val rExtent = radiusOuter / radius
beginShape()
curveVertexRt(radius, theta)
curveVertexRt(radius, theta)
curveVertexRt(mathx.lerp(radius, radius * rExtent, 0.5), theta - tDelta / 4)
curveVertexRt(radius * rExtent, theta)
curveVertexRt(radius * rExtent, theta)
endShape()
beginShape()
curveVertexRt(radius * rExtent, theta)
curveVertexRt(radius * rExtent, theta)
curveVertexRt(mathx.lerp(radius, radius * rExtent, 0.5), theta + tDelta / 4)
curveVertexRt(radius, theta)
curveVertexRt(radius, theta)
endShape()
}
val p = diya(170, 250, 0, 50)
.withScaling(0.95)
//Recursive diya pattern
def pattern6(n: Int): Picture = {
if (n == 1) {
p
}
else {
picStack(
p
.withPenColor(lg),
pattern6(n - 1)
.withRotation(360 / 8)
.withPenColor(lg)
)
}
}
draw(pattern6(8))
draw(pattern5(8))
drawCentered(pattern4)
drawCentered(pattern)
drawCentered(pattern2)
draw(patterns(8))
drawCentered(center)