Skip to content

Commit

Permalink
Fix assorted problems in Writing Methods
Browse files Browse the repository at this point in the history
- Build is updated to versions that work with JVM 21

- Fix errors in styling content

- Generate missing image

Problem reported by Kim Morgan
  • Loading branch information
noelwelsh committed Nov 29, 2023
1 parent e7307c1 commit f580d57
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 11 deletions.
1 change: 1 addition & 0 deletions book/src/main/scala/All.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ object All extends App {
expressive.All
flowers.All
fractals.All
methods.All
programs.All
recursion.All
}
6 changes: 6 additions & 0 deletions book/src/main/scala/methods/All.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package creativescala
package methods

object All {
WritingMethods
}
27 changes: 27 additions & 0 deletions book/src/main/scala/methods/WritingMethods.scala
Original file line number Diff line number Diff line change
@@ -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")
}
2 changes: 2 additions & 0 deletions book/src/pages/foreword-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

19 changes: 10 additions & 9 deletions book/src/pages/methods/writing-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" }
@:@

<div class="solution">
@: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.
Expand All @@ -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.
</div>
@:@
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.8.2
sbt.version = 1.9.7

0 comments on commit f580d57

Please sign in to comment.