From f580d57ee6536b61dea78de7023a16414274b131 Mon Sep 17 00:00:00 2001 From: Noel Welsh Date: Wed, 29 Nov 2023 22:47:58 +0000 Subject: [PATCH] Fix assorted problems in Writing Methods - Build is updated to versions that work with JVM 21 - Fix errors in styling content - Generate missing image Problem reported by Kim Morgan --- book/src/main/scala/All.scala | 1 + book/src/main/scala/methods/All.scala | 6 +++++ .../main/scala/methods/WritingMethods.scala | 27 +++++++++++++++++++ book/src/pages/foreword-2.md | 2 ++ book/src/pages/methods/writing-methods.md | 19 ++++++------- build.sbt | 2 +- project/build.properties | 2 +- 7 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 book/src/main/scala/methods/All.scala create mode 100644 book/src/main/scala/methods/WritingMethods.scala diff --git a/book/src/main/scala/All.scala b/book/src/main/scala/All.scala index 7573ec28..159ce760 100644 --- a/book/src/main/scala/All.scala +++ b/book/src/main/scala/All.scala @@ -5,6 +5,7 @@ object All extends App { expressive.All flowers.All fractals.All + methods.All programs.All recursion.All } diff --git a/book/src/main/scala/methods/All.scala b/book/src/main/scala/methods/All.scala new file mode 100644 index 00000000..859805e7 --- /dev/null +++ b/book/src/main/scala/methods/All.scala @@ -0,0 +1,6 @@ +package creativescala +package methods + +object All { + WritingMethods +} diff --git a/book/src/main/scala/methods/WritingMethods.scala b/book/src/main/scala/methods/WritingMethods.scala new file mode 100644 index 00000000..0609e99b --- /dev/null +++ b/book/src/main/scala/methods/WritingMethods.scala @@ -0,0 +1,27 @@ +package creativescala +package methods + +import doodle.core._ +import doodle.image._ +import doodle.syntax.all._ +import doodle.image.syntax.all._ +import doodle.java2d._ + +object WritingMethods { + def box(color: Color, spin: Angle): Image = + Image + .rectangle(40, 40) + .strokeWidth(5.0) + .strokeColor(color.spin(spin + 30.degrees)) + .fillColor(color.spin(spin)) + + def gradientBoxes(color: Color): Image = { + box(color, 0.degrees) + .beside(box(color, 15.degrees)) + .beside(box(color, 20.degrees)) + .beside(box(color, 45.degrees)) + .beside(box(color, 60.degrees)) + } + + gradientBoxes(Color.royalBlue).save("methods/gradient-boxes") +} diff --git a/book/src/pages/foreword-2.md b/book/src/pages/foreword-2.md index f5f1d1fb..d9866198 100644 --- a/book/src/pages/foreword-2.md +++ b/book/src/pages/foreword-2.md @@ -25,3 +25,5 @@ One more thing: the name may change as well! I'm not sure Creative Scala fits th The members of ScalaBridge London, with particular mention to the following for reporting bugs and suggesting improvements: - Jess Gordon +- Kim Morgan + diff --git a/book/src/pages/methods/writing-methods.md b/book/src/pages/methods/writing-methods.md index c546e6d4..1ca06599 100644 --- a/book/src/pages/methods/writing-methods.md +++ b/book/src/pages/methods/writing-methods.md @@ -84,10 +84,10 @@ import doodle.java2d.* ``` ```scala mdoc:silent def box(color: Color, spin: Angle): Image = - Image.rectangle(40, 40). - strokeWidth(5.0). - strokeColor(color.spin(spin + 30.degrees)). - fillColor(color.spin(spin)) + Image.rectangle(40, 40) + .strokeWidth(5.0) + .strokeColor(color.spin(spin + 30.degrees)) + .fillColor(color.spin(spin)) def gradientBoxes(color: Color): Image = { box(color, 0.degrees) beside @@ -100,14 +100,15 @@ def gradientBoxes(color: Color): Image = { @:@ -#### Gradient Concentric Circles {-} +@:exercise(Gradient Concentric Circles) Now implement methods to draw a picture similar to @:fref(methods:gradient-concentric-circles). -You should follow a design similar to `gradientBoxes` to reduce the amount of code you write, but we're not going to give the method skeletons this time---you have to work it out yourself. +You should follow a design similar to `gradientBoxes` to reduce the amount of code you write, but we're not going to give the method skeletons this time; you have to work it out yourself. -@:figure{ img = "./src/pages/recursion/gradient-concentric-circles.pdf+svg", key = "#fig:methods:gradient-concentric-circles", caption = "Five concentric circles filled with a gradient starting from Royal Blue" } +@:figure{ img = "gradient-concentric-circles.svg", key = "#fig:methods:gradient-concentric-circles", caption = "Five concentric circles filled with a gradient starting from Royal Blue" } +@:@ -
+@:solution There are a number of different ways to write this. We expect you would have two methods, `circle` and `gradientConcentricCircles` mirroring the design of `box` and `gradientBoxes` above. The exact implementation of these two methods, particularly `circle` is where we'll see the most difference. @@ -131,4 +132,4 @@ def concentricCircles(color: Color): Image = { We could have made `circle` have separate parameters for the size and spin, but we decided to compute the size and spin from a single number. This gives us less flexibility (they cannot vary independently) but more compact code. -
+@:@ diff --git a/build.sbt b/build.sbt index 3d9d6e4f..f93db089 100644 --- a/build.sbt +++ b/build.sbt @@ -3,7 +3,7 @@ import laika.config.LaikaKeys import laika.theme.Theme val scala213 = "2.13.11" -val scala3 = "3.3.0" +val scala3 = "3.3.1" ThisBuild / organization := "org.creativescala" ThisBuild / organizationName := "Creative Scala" diff --git a/project/build.properties b/project/build.properties index f344c148..b19d4e1e 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version = 1.8.2 +sbt.version = 1.9.7