Code Sketch
Playa
By: Soham Dabral
Category: Art
2


0




def mountains(n: Int) = Picture { beginShape() curveVertexRt(-300, 0) curveVertexRt(-300, 0) curveVertexRt(n, 100) curveVertexRt(n, 0) curveVertexRt(n, 0) endShape() } def trunk(size: Double) = Picture { setPenThickness(15) setPenColor(cm.hsl(120, 1.00, 0.07)) forward(size) } def leftbranch(size: Double): Picture = { rot(30) -> trunk(size) } def rightbranch(size: Double): Picture = { rot(-30) -> trunk(size) } def tree(size: Double): Picture = { setPenColor(cm.hsl(204, 1.00, 0.50)) picStack( trunk(size), trans(0, size) -> leftbranch(size), trans(0, size) -> rightbranch(size), ) } def lefttree(size: Double): Picture = { rot(30) -> tree(size) } def righttree(size: Double): Picture = { rot(-30) -> tree(size) } def finaltree(n: Int, size: Double): Picture = { if (n == 1) { trunk(size) } else { picStack( tree(size - 10), trans(42, 162) -> righttree(size), trans(-42, 162) -> lefttree(size), rot(30) * trans(-5, 348) -> finaltree(n - 1, size - 10), rot(-30) * trans(5, 348) -> finaltree(n - 1, size - 10), rot(10) * trans(5, 148) -> finaltree(n - 1, size - 10), rot(-10) * trans(5, 148) -> finaltree(n - 1, size - 10) ) } } def bird(n: Double) = Picture { setPenColor(black) setPenThickness(4) right() right(60, n) left(120) right(60, n) } def scenery(n: Int, size: Double): Picture = { if (n == 1) { mountains(150) .withFillColor(mountainclr) .withPenColor(noColor) } else { picStack( mountains(120) .withPenColor(noColor) .withFillColor(mountainclr), scenery(n - 1, size) .withTranslation(200, 0) ) } } def birds(num: Int, size: Double): Picture = { if (num == 1) { bird(size) } else { picStack( bird(size), birds(num - 1, size + 2) .withTranslation(size * 1.1, size - 5) ) } } cleari() val assetsDir = "C:/Users/Soham/Downloads" val bg = Picture.image(s"$assetsDir/camel.jpg") val camel = scale(0.06) -> bg val sky = cm.linearGradient(0, 100, cm.hsl(202, 1.00, 0.50), 0, 200, cm.blue, false) val sunclr = cm.radialGradient(0, 0, cm.hsl(20, 1.00, 0.54), 70, cm.blue, false) val sunclr2 = cm.radialGradient(0, 0, cm.hsl(20, 1.00, 0.68), 70, cm.hsl(168, 1.00, 0.48), false) val mountainclr = cm.linearGradient(-55, 40, cm.hsl(28, 0.60, 0.40), 0, 0, cm.hsl(6, 1.00, 0.33), false) val pic = picStack( picStack( picStack( Picture.rectangle(850, 380) .withTranslation(-300, -380) .withPenColor(noColor) .withFillColor(cm.hsl(168, 1.00, 0.48)), Picture.rectangle(850, 380) .withTranslation(-300, 0) .withPenColor(noColor) .withFillColor(sky) ), scenery(3, 10) .withTranslation(0, -4) .withPenColor(noColor) .withPenThickness(0) .withBlurring(10) .withFading(150) .withFlippedY ), Picture.circle(75) .withPenColor(noColor) .withTranslation(0, 239) .withFillColor(sunclr2) .withFading(220) .withFlippedY ) val pic2 = picStack( picStack( picStack( pic, Picture.circle(75) .withPenColor(noColor) .withTranslation(0, 285) .withFillColor(sunclr), ), scenery(3, 10) ), birds(3, 25) .withTranslation(50, 180) .withPenThickness(1.5), camel .withTranslation(1000, 0), camel .withFlippedY .withBlurring(10) .withTranslation(60, 0), ) val birdsref = picStack( pic2, birds(3, 25) .withPenThickness(1.5) .withBlurring(8) .withFading(90) .withFlippedY .withTranslation(50, 180) ) val finalpic = picStack( finaltree(4, 110), finaltree(4, 110) .withPenThickness(2) .withTranslation(4, 0) .withBlurring(30) .withFlippedY ) val desert = picStack( birdsref, trans(-120, 0) * scale(0.13) -> finalpic ) scale(0.5) -> drawCentered(desert)





Your Comment:





Login to post a comment