Skip to content

Commit

Permalink
deploy: 3e14cd4
Browse files Browse the repository at this point in the history
  • Loading branch information
noelwelsh committed Oct 25, 2024
1 parent e61d65d commit c3935fa
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 150 deletions.
10 changes: 5 additions & 5 deletions animation/easing.html
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,12 @@ <h1 id="easing-functions" class="title">Easing Functions</h1>
.</span><span class="identifier">withRender</span><span>(</span><span class="identifier">r</span><span> =&gt; </span><span class="type-name">Image</span><span>.</span><span class="identifier">circle</span><span>(</span><span class="identifier">r</span><span>))
</span><span class="comment">// bubble: Reactor[Double] = Reactor(
// initial = 0.0,
// onMouseClickHandler = doodle.reactor.Reactor$$$Lambda$14668/0x00000001039ab840@3503c16e,
// onMouseMoveHandler = doodle.reactor.Reactor$$$Lambda$14669/0x00000001039ac040@544e12e4,
// onTickHandler = doodle.reactor.Reactor$$$Lambda$14673/0x00000001039af040@90012fc,
// onMouseClickHandler = doodle.reactor.Reactor$$$Lambda$14840/0x0000000103a3c040@4c26819f,
// onMouseMoveHandler = doodle.reactor.Reactor$$$Lambda$14841/0x0000000103a3d040@b352d9c,
// onTickHandler = doodle.reactor.Reactor$$$Lambda$14845/0x0000000103a40040@33d457f,
// tickRate = 100 milliseconds,
// renderHandler = repl.MdocSession$MdocApp$$Lambda$14675/0x00000001039b9040@1190cd1,
// stopHandler = doodle.reactor.Reactor$$$Lambda$14674/0x00000001039b8840@2a3aa52d
// renderHandler = repl.MdocSession$MdocApp$$Lambda$14847/0x0000000103a42040@4bd4cdf9,
// stopHandler = doodle.reactor.Reactor$$$Lambda$14846/0x0000000103a41040@33869765
// )</span></code></pre>
<div class="flex flex-row justify-between">
<a class="pageNavigation" href="index.html">←Animation and Fireworks</a> <a class="pageNavigation" href="../collections/paths.html">Drawing Paths→</a>
Expand Down
5 changes: 2 additions & 3 deletions cycles/fun.html
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,10 @@ <h1 id="fun-with-composition" class="title">Fun with Composition</h1>
</span><span class="type-name">Image</span><span>.</span><span class="identifier">circle</span><span>(</span><span class="number-literal">100</span><span> + </span><span class="number-literal">24</span><span>*</span><span class="identifier">n</span><span>).</span><span class="identifier">strokeColor</span><span>(</span><span class="type-name">Color</span><span>.</span><span class="identifier">red</span><span>)

</span><span class="keyword">val</span><span> </span><span class="identifier">redCircles</span><span>: </span><span class="type-name">Image</span><span> =
</span><span class="identifier">concentricShapes</span><span>(</span><span class="number-literal">10</span><span>, </span><span class="identifier">redCircle</span><span> </span><span class="identifier">_</span><span>)</span></code></pre>
</span><span class="identifier">concentricShapes</span><span>(</span><span class="number-literal">10</span><span>, </span><span class="identifier">redCircle</span><span>)</span></code></pre>
<p><img src="./red-black-circles.svg" alt="Black and Red Concentric Circles" title="Figure Some(#fig:cycles:red-black-circles): caption"></p>
<p>You might notice two things about this example: we&#39;re not using function composition, and we duplication in the definitions.
<p>You might notice two things about this example: we&#39;re not using function composition, and we have duplication in the definitions.
In both cases we draw circles, but they differ in color.
No problem.
This feels like a problem we can solve with function composition.
Let&#39;s give it a go.</p>
<p>In both cases the radius of the circle is <code>100 + 24*n</code>, where <code>n</code> is the iteration count.
Expand Down
6 changes: 3 additions & 3 deletions flowers/functions.html
Original file line number Diff line number Diff line change
Expand Up @@ -500,17 +500,17 @@ <h4 id="exercise-function-literals">Exercise: Function Literals</h4>
<div class="solution-body">
<p>The first function is</p>
<pre><code class="nohighlight"><span>(</span><span class="identifier">x</span><span>: </span><span class="type-name">Int</span><span>) =&gt; </span><span class="identifier">x</span><span> * </span><span class="identifier">x</span><span>
</span><span class="comment">// res10: Function1[Int, Int] = repl.MdocSession$MdocApp0$$Lambda$14978/0x0000000103ab5040@7451dd8b</span></code></pre>
</span><span class="comment">// res10: Function1[Int, Int] = repl.MdocSession$MdocApp0$$Lambda$15145/0x0000000103ae1840@5e1fdbb5</span></code></pre>
<p>The second is</p>
<pre><code class="nohighlight"><span>(</span><span class="identifier">c</span><span>: </span><span class="type-name">Color</span><span>) =&gt; </span><span class="identifier">c</span><span>.</span><span class="identifier">spin</span><span>(</span><span class="number-literal">15</span><span>.</span><span class="identifier">degrees</span><span>)
</span><span class="comment">// res11: Function1[Color, HSLA] = repl.MdocSession$MdocApp0$$Lambda$14979/0x0000000103ab4040@234316b5</span></code></pre>
</span><span class="comment">// res11: Function1[Color, HSLA] = repl.MdocSession$MdocApp0$$Lambda$15146/0x0000000103ae0840@7562c63</span></code></pre>
<p>The third is</p>
<pre><code class="nohighlight"><span>(</span><span class="identifier">image</span><span>: </span><span class="type-name">Image</span><span>) =&gt;
</span><span class="identifier">image</span><span>.</span><span class="identifier">beside</span><span>(</span><span class="identifier">image</span><span>.</span><span class="identifier">rotate</span><span>(</span><span class="number-literal">90</span><span>.</span><span class="identifier">degrees</span><span>))
.</span><span class="identifier">beside</span><span>(</span><span class="identifier">image</span><span>.</span><span class="identifier">rotate</span><span>(</span><span class="number-literal">180</span><span>.</span><span class="identifier">degrees</span><span>))
.</span><span class="identifier">beside</span><span>(</span><span class="identifier">image</span><span>.</span><span class="identifier">rotate</span><span>(</span><span class="number-literal">270</span><span>.</span><span class="identifier">degrees</span><span>))
.</span><span class="identifier">beside</span><span>(</span><span class="identifier">image</span><span>.</span><span class="identifier">rotate</span><span>(</span><span class="number-literal">360</span><span>.</span><span class="identifier">degrees</span><span>))
</span><span class="comment">// res12: Function1[Image, Image] = repl.MdocSession$MdocApp0$$Lambda$14980/0x0000000103ab3840@f51cb0f</span></code></pre>
</span><span class="comment">// res12: Function1[Image, Image] = repl.MdocSession$MdocApp0$$Lambda$15147/0x0000000103b30040@16c8f00a</span></code></pre>
</div>
</div>
<div class="exercise">
Expand Down
16 changes: 8 additions & 8 deletions generative/flatmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -501,15 +501,15 @@ <h4 id="randomness-and-randomness" class="section">Randomness and Randomness {-}
// c = FlatMapped(
// c = FlatMapped(
// c = Suspend(a = RDouble),
// f = cats.free.Free$$Lambda$15058/0x0000000103ae8040@20ff6639
// f = cats.free.Free$$Lambda$15225/0x0000000103af3040@7eb0f4ef
// ),
// f = cats.free.Free$$Lambda$15058/0x0000000103ae8040@27ef4eec
// f = cats.free.Free$$Lambda$15225/0x0000000103af3040@61b85210
// ),
// f = cats.free.Free$$Lambda$15058/0x0000000103ae8040@1f057c94
// f = cats.free.Free$$Lambda$15225/0x0000000103af3040@29ec77c9
// ),
// f = repl.MdocSession$MdocApp5$$Lambda$15075/0x0000000103af1040@3b86e385
// f = repl.MdocSession$MdocApp5$$Lambda$15242/0x0000000103b65040@20da50e
// ),
// f = repl.MdocSession$MdocApp5$$Lambda$15078/0x0000000103af3840@60938462
// f = repl.MdocSession$MdocApp5$$Lambda$15245/0x0000000103b71840@7b633e2c
// )</span></code></pre>
<p>which makes it clearer that we&#39;re generating three different circles.
&lt;/div&gt;</p>
Expand All @@ -530,17 +530,17 @@ <h4 id="colored-boxes" class="section">Colored Boxes {-}</h4>
</span><span class="type-name">Random</span><span>.</span><span class="identifier">double</span><span>.</span><span class="identifier">map</span><span>(</span><span class="identifier">x</span><span> =&gt; </span><span class="identifier">x</span><span>.</span><span class="identifier">turns</span><span>)
</span><span class="comment">// randomAngle: Free[[A &gt;: Nothing &lt;: Any] =&gt; RandomOp[A], Angle] = FlatMapped(
// c = Suspend(a = RDouble),
// f = cats.free.Free$$Lambda$15058/0x0000000103ae8040@3dd62eb2
// f = cats.free.Free$$Lambda$15225/0x0000000103af3040@58e8cb82
// )
</span><span>
</span><span class="keyword">val</span><span> </span><span class="identifier">randomColor</span><span>: </span><span class="type-name">Random</span><span>[</span><span class="type-name">Color</span><span>] =
</span><span class="identifier">randomAngle</span><span>.</span><span class="identifier">map</span><span>(</span><span class="identifier">hue</span><span> =&gt; </span><span class="type-name">Color</span><span>.</span><span class="identifier">hsl</span><span>(</span><span class="identifier">hue</span><span>, </span><span class="number-literal">0.7</span><span>, </span><span class="number-literal">0.7</span><span>))
</span><span class="comment">// randomColor: Free[[A &gt;: Nothing &lt;: Any] =&gt; RandomOp[A], Color] = FlatMapped(
// c = FlatMapped(
// c = Suspend(a = RDouble),
// f = cats.free.Free$$Lambda$15058/0x0000000103ae8040@3dd62eb2
// f = cats.free.Free$$Lambda$15225/0x0000000103af3040@58e8cb82
// ),
// f = cats.free.Free$$Lambda$15058/0x0000000103ae8040@9831440
// f = cats.free.Free$$Lambda$15225/0x0000000103af3040@1270bd69
// )
</span><span>
</span><span class="keyword">def</span><span> </span><span class="declaration-name">coloredRectangle</span><span>(</span><span class="identifier">color</span><span>: </span><span class="type-name">Color</span><span>): </span><span class="type-name">Image</span><span> =
Expand Down
16 changes: 8 additions & 8 deletions generative/generative.html
Original file line number Diff line number Diff line change
Expand Up @@ -345,29 +345,29 @@ <h1 id="generative-art" class="title">Generative Art</h1>
</tbody>
</table>
<pre><code class="nohighlight"><span class="identifier">math</span><span>.</span><span class="identifier">random</span><span>
</span><span class="comment">// res0: Double = 0.6921757107960387
</span><span class="comment">// res0: Double = 0.4924912839975709
</span><span class="identifier">math</span><span>.</span><span class="identifier">random</span><span>
</span><span class="comment">// res1: Double = 0.5710932291367746</span></code></pre>
</span><span class="comment">// res1: Double = 0.14922498513097637</span></code></pre>
<p>Given <code>math.random</code> we could produce a method that returns a random <code>Angle</code> like so.</p>
<pre><code class="nohighlight"><span class="keyword">def</span><span> </span><span class="declaration-name">randomAngle</span><span>: </span><span class="type-name">Angle</span><span> =
</span><span class="identifier">math</span><span>.</span><span class="identifier">random</span><span>.</span><span class="identifier">turns</span><span>

</span><span class="identifier">randomAngle</span><span>
</span><span class="comment">// res2: Angle = Angle(2.0715309336454704)
</span><span class="comment">// res2: Angle = Angle(4.460463406624684)
</span><span class="identifier">randomAngle</span><span>
</span><span class="comment">// res3: Angle = Angle(3.9566930757933254)</span></code></pre>
</span><span class="comment">// res3: Angle = Angle(5.332355554721024)</span></code></pre>
<p>Why might we not want to do this? What principle does this break?</p>
<p>&lt;div class=&quot;solution&quot;&gt;
Generating random numbers in this way breaks substitution. Remember substitution says wherever we see an expression we should be able to substitute the value it evaluates to without changing the meaning of the program. Concretely, this means</p>
<pre><code class="nohighlight"><span class="keyword">val</span><span> </span><span class="identifier">result1</span><span> = </span><span class="identifier">randomAngle</span><span>
</span><span class="comment">// result1: Angle = Angle(5.526650364190744)
</span><span class="comment">// result1: Angle = Angle(5.201155181755512)
</span><span class="keyword">val</span><span> </span><span class="identifier">result2</span><span> = </span><span class="identifier">randomAngle</span><span>
</span><span class="comment">// result2: Angle = Angle(6.1676242236421235)</span></code></pre>
</span><span class="comment">// result2: Angle = Angle(2.4967518527825985)</span></code></pre>
<p>and </p>
<pre><code class="nohighlight"><span class="keyword">val</span><span> </span><span class="identifier">result1</span><span> = </span><span class="identifier">randomAngle</span><span>
</span><span class="comment">// result1: Angle = Angle(3.5072370264718846)
</span><span class="comment">// result1: Angle = Angle(1.1029717333920994)
</span><span class="keyword">val</span><span> </span><span class="identifier">result2</span><span> = </span><span class="identifier">result1</span><span>
</span><span class="comment">// result2: Angle = Angle(3.5072370264718846)</span></code></pre>
</span><span class="comment">// result2: Angle = Angle(1.1029717333920994)</span></code></pre>
<p>should be the same program and clearly they are not.
&lt;/div&gt;</p>
<p>What should we do? Suffer the slings and arrows of outrageous computational models, or take arms against a sea of side-effects, and by opposing end them! There&#39;s really only one choice.</p>
Expand Down
6 changes: 3 additions & 3 deletions generative/random.html
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ <h1 id="randomness-without-effect" class="title">Randomness without Effect</h1>
// )</span></code></pre>
<p>No random numbers are actually created until we call the <code>run</code> method.</p>
<pre><code class="nohighlight"><span class="identifier">randomDouble</span><span>.</span><span class="identifier">run</span><span>
</span><span class="comment">// res0: Double = 0.06444266176689717</span></code></pre>
</span><span class="comment">// res0: Double = 0.5113098551608625</span></code></pre>
<p>The type <code>Random[Double]</code> indicates we have something that will produce a random <code>Double</code> when we <code>run</code> it. Just like with <code>Image</code> and <code>draw</code>, substitution holds with <code>Random</code> up until the point we call <code>run</code>.</p>
<p>Table Table generative:random shows some of the ways to construct <code>Random</code> values.</p>
<hr>
Expand Down Expand Up @@ -368,9 +368,9 @@ <h3 id="composing-random" class="section">Composing Random</h3>
</span><span class="type-name">Random</span><span>.</span><span class="identifier">double</span><span>.</span><span class="identifier">map</span><span>(</span><span class="identifier">x</span><span> =&gt; </span><span class="identifier">x</span><span>.</span><span class="identifier">turns</span><span>)</span></code></pre>
<p>When we <code>run</code> <code>RandomAngle</code> we can generate randomly created <code>Angle</code></p>
<pre><code class="nohighlight"><span class="identifier">randomAngle</span><span>.</span><span class="identifier">run</span><span>
</span><span class="comment">// res1: Angle = Angle(3.2526161745953837)
</span><span class="comment">// res1: Angle = Angle(4.703122344504545)
</span><span class="identifier">randomAngle</span><span>.</span><span class="identifier">run</span><span>
</span><span class="comment">// res2: Angle = Angle(0.9902212420837117)</span></code></pre>
</span><span class="comment">// res2: Angle = Angle(1.2369067933139868)</span></code></pre>

<h3 id="exercises" class="section">Exercises {-}</h3>

Expand Down
Loading

0 comments on commit c3935fa

Please sign in to comment.