Code Sketch
Example of picture graphics
By: Soham Dabral
Category: Art
4


0




def mountain(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 mountains(n: Int, size: Double): Picture = { if (n == 1) { mountain(150) .withFillColor(mountainclr) .withPenColor(noColor) } else { picStack( mountain(120) .withPenColor(noColor) .withFillColor(mountainclr), mountains(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/E2.png") val E1 = scale(0.3) -> bg val finalpic = picStack( finaltree(4, 110), finaltree(4, 110) .withPenThickness(2) .withTranslation(4, 0) .withBlurring(30) .withFlippedY ) 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, ColorMaker.hsl(194, 0.68, 0.56), false) val mountainclr = cm.linearGradient(-55, 40, ColorMaker.hsl(120, 1.00, 0.38), 0, 0, ColorMaker.hsl(120, 1.00, 0.19), false) val scenery = picStack( Picture.rectangle(850, 380) .withTranslation(-300, -380) .withPenColor(noColor) .withFillColor(ColorMaker.hsl(194, 0.68, 0.56)), Picture.rectangle(850, 380) .withTranslation(-300, 0) .withPenColor(noColor) .withFillColor(sky), mountains(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, Picture.circle(75) .withPenColor(noColor) .withTranslation(0, 285) .withFillColor(sunclr), mountains(3, 10), birds(3, 20) .withTranslation(50, 180), trans(-120, 0) * scale(0.13) -> finalpic, trans(20, 0) * scale(0.08) -> finalpic, trans(220, 0) * scale(0.12) -> finalpic, trans(320, 0) * scale(0.07) -> finalpic, trans(450, 0) * scale(0.15) -> finalpic, E1 .withTranslation(-60, -100), E1 .withFlippedY .withBlurring(10) .withTranslation(-20, -5), pic, birds(3, 20) .withPenThickness(1.5) .withBlurring(8) .withFading(90) .withFlippedY .withTranslation(50, 180) ) drawCentered(scenery)





Your Comment:





Login to post a comment