Skip to content

Commit

Permalink
deploy: f1f6905
Browse files Browse the repository at this point in the history
  • Loading branch information
noelwelsh committed Nov 30, 2023
1 parent a4c8032 commit d0c7da4
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 52 deletions.
10 changes: 5 additions & 5 deletions animation/easing.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,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$15871/0x0000000104002840@41efa0fe,
// onMouseMoveHandler = doodle.reactor.Reactor$$$Lambda$15872/0x0000000104002040@7c794aa6,
// onTickHandler = doodle.reactor.Reactor$$$Lambda$15876/0x0000000104012040@4cad4da6,
// onMouseClickHandler = doodle.reactor.Reactor$$$Lambda$14500/0x0000000103bf9040@6a3d898,
// onMouseMoveHandler = doodle.reactor.Reactor$$$Lambda$14501/0x0000000103bfa040@3f4d5b53,
// onTickHandler = doodle.reactor.Reactor$$$Lambda$14505/0x0000000103bfd040@42236819,
// tickRate = 100 milliseconds,
// renderHandler = repl.MdocSession$MdocApp$$Lambda$15878/0x0000000104013840@753fcd78,
// stopHandler = doodle.reactor.Reactor$$$Lambda$15877/0x0000000104013040@5df25286
// renderHandler = repl.MdocSession$MdocApp$$Lambda$14507/0x0000000103bff040@2bf3a1c0,
// stopHandler = doodle.reactor.Reactor$$$Lambda$14506/0x0000000103bfe040@5743dec0
// )</span></code></pre>
<div class="flex flex-row justify-between">
<a class="pageNavigation" href="index.html">←Animation and Fireworks</a> <a class="pageNavigation" href="../adt/">Algebraic Data Types To Call Our Own→</a>
Expand Down
8 changes: 4 additions & 4 deletions expressive-expressions/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ <h1 id="expressive-expressions" class="title">Expressive Expressions</h1>
In this chapter we have a basic introduction.
In later chapters we&#39;ll learn much more about creating images alongside learning more advanced programming techniques.</p>
<p>To create image we will use a library called <a href="https://www.creativescala.org/doodle/">Doodle</a>.</p>
<p>@callout(info)
You will need to add the following to the worksheet to be able to use Doodle.</p>
<pre><code class="nohighlight"><span class="keyword">import</span><span> </span><span class="identifier">cats</span><span>.</span><span class="identifier">effect</span><span>.</span><span class="identifier">unsafe</span><span>.</span><span class="identifier">implicits</span><span>.</span><span class="identifier">global</span><span>
<div class="callout info">
<p>You will need to add the following to the worksheet to be able to use Doodle.</p>
<pre><code class="nohighlight"><span class="keyword">import</span><span> </span><span class="identifier">cats</span><span>.</span><span class="identifier">effect</span><span>.</span><span class="identifier">unsafe</span><span>.</span><span class="identifier">implicits</span><span>.</span><span class="identifier">global</span><span>
</span><span class="keyword">import</span><span> </span><span class="identifier">doodle</span><span>.</span><span class="identifier">core</span><span>.*
</span><span class="keyword">import</span><span> </span><span class="identifier">doodle</span><span>.</span><span class="identifier">image</span><span>.*
</span><span class="keyword">import</span><span> </span><span class="identifier">doodle</span><span>.</span><span class="identifier">syntax</span><span>.</span><span class="identifier">all</span><span>.*
</span><span class="keyword">import</span><span> </span><span class="identifier">doodle</span><span>.</span><span class="identifier">image</span><span>.</span><span class="identifier">syntax</span><span>.</span><span class="identifier">all</span><span>.*
</span><span class="keyword">import</span><span> </span><span class="identifier">doodle</span><span>.</span><span class="identifier">java2d</span><span>.*</span></code></pre>
<p>@:@</p>
</div>
<div class="flex flex-row justify-between">
<a class="pageNavigation" href="../expanding-expressions/05-exercises.html">←Exercises</a> <a class="pageNavigation" href="01-images.html">Images→</a>
</div>
Expand Down
6 changes: 3 additions & 3 deletions flowers/functions.html
Original file line number Diff line number Diff line change
Expand Up @@ -355,17 +355,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$16203/0x0000000104125040@7ebd817c</span></code></pre>
</span><span class="comment">// res10: Function1[Int, Int] = repl.MdocSession$MdocApp0$$Lambda$14832/0x0000000103d18840@14f021d4</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$16204/0x0000000104124040@61a527bc</span></code></pre>
</span><span class="comment">// res11: Function1[Color, HSLA] = repl.MdocSession$MdocApp0$$Lambda$14833/0x0000000103d19040@6e16e704</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$16205/0x0000000104123840@59b4a7d5</span></code></pre>
</span><span class="comment">// res12: Function1[Image, Image] = repl.MdocSession$MdocApp0$$Lambda$14834/0x0000000103d1a040@131049dd</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 @@ -364,15 +364,15 @@ <h4 id="randomness-and-randomness" class="section">Randomness and Randomness {-}
// c = FlatMapped(
// c = FlatMapped(
// c = Suspend(a = RDouble),
// f = cats.free.Free$$Lambda$16276/0x000000010414a040@4602a48b
// f = cats.free.Free$$Lambda$14905/0x0000000103d2d040@72cc3c4d
// ),
// f = cats.free.Free$$Lambda$16276/0x000000010414a040@2b464f75
// f = cats.free.Free$$Lambda$14905/0x0000000103d2d040@7aadb808
// ),
// f = cats.free.Free$$Lambda$16276/0x000000010414a040@1c8e8146
// f = cats.free.Free$$Lambda$14905/0x0000000103d2d040@1995883e
// ),
// f = repl.MdocSession$MdocApp5$$Lambda$16293/0x0000000104160840@5fb0584b
// f = repl.MdocSession$MdocApp5$$Lambda$14922/0x0000000103d3d040@20ea14ab
// ),
// f = repl.MdocSession$MdocApp5$$Lambda$16296/0x0000000104163040@c4589ca
// f = repl.MdocSession$MdocApp5$$Lambda$14925/0x0000000103d3b040@33576aaf
// )</span></code></pre>
<p>which makes it clearer that we&#39;re generating three different circles.
&lt;/div&gt;</p>
Expand All @@ -393,17 +393,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$16276/0x000000010414a040@15e142d0
// f = cats.free.Free$$Lambda$14905/0x0000000103d2d040@24ade935
// )
</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$16276/0x000000010414a040@15e142d0
// f = cats.free.Free$$Lambda$14905/0x0000000103d2d040@24ade935
// ),
// f = cats.free.Free$$Lambda$16276/0x000000010414a040@7d0d759b
// f = cats.free.Free$$Lambda$14905/0x0000000103d2d040@114c41e6
// )
</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 @@ -200,29 +200,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.8512883735380299
</span><span class="comment">// res0: Double = 0.20832799599325624
</span><span class="identifier">math</span><span>.</span><span class="identifier">random</span><span>
</span><span class="comment">// res1: Double = 0.19420231924963882</span></code></pre>
</span><span class="comment">// res1: Double = 0.7478937442305806</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(1.7507232842311664)
</span><span class="comment">// res2: Angle = Angle(1.7999491955145053)
</span><span class="identifier">randomAngle</span><span>
</span><span class="comment">// res3: Angle = Angle(1.379972434894668)</span></code></pre>
</span><span class="comment">// res3: Angle = Angle(4.298384675448248)</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(6.090844259111435)
</span><span class="comment">// result1: Angle = Angle(0.11680001056257192)
</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(3.086030749993199)</span></code></pre>
</span><span class="comment">// result2: Angle = Angle(1.7115052850116896)</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(1.8162496840288966)
</span><span class="comment">// result1: Angle = Angle(6.097248152056065)
</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(1.8162496840288966)</span></code></pre>
</span><span class="comment">// result2: Angle = Angle(6.097248152056065)</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 @@ -185,7 +185,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.6556639119999121</span></code></pre>
</span><span class="comment">// res0: Double = 0.34880604838838725</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 @@ -223,9 +223,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(4.071939185742735)
</span><span class="comment">// res1: Angle = Angle(2.2344059491598327)
</span><span class="identifier">randomAngle</span><span>.</span><span class="identifier">run</span><span>
</span><span class="comment">// res2: Angle = Angle(4.399750271628484)</span></code></pre>
</span><span class="comment">// res2: Angle = Angle(0.4627784152184933)</span></code></pre>

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

Expand Down
16 changes: 8 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13638,14 +13638,14 @@ $c_Lpolygons_Coordinates$.prototype.polar__T__V = (function(id) {
var runtime = $m_Lcats_effect_unsafe_IORuntime$().global__Lcats_effect_unsafe_IORuntime();
$f_Ldoodle_interact_animation_Transducer__animate__O__Ldoodle_interact_effect_AnimationRenderer__Ldoodle_effect_Renderer__Ldoodle_interact_algebra_Redraw__s_$less$colon$less__Lcats_effect_unsafe_IORuntime__V(this$3, frame, a, e, r, ev, runtime)
});
$c_Lpolygons_Coordinates$.prototype.cartesian = (function(arg) {
var prep0 = $as_T(arg);
this.cartesian__T__V(prep0)
});
$c_Lpolygons_Coordinates$.prototype.polar = (function(arg) {
var prep0 = $as_T(arg);
this.polar__T__V(prep0)
});
$c_Lpolygons_Coordinates$.prototype.cartesian = (function(arg) {
var prep0 = $as_T(arg);
this.cartesian__T__V(prep0)
});
var $d_Lpolygons_Coordinates$ = new $TypeData().initClass({
Lpolygons_Coordinates$: 0
}, false, "polygons.Coordinates$", {
Expand Down Expand Up @@ -14557,10 +14557,6 @@ $c_Lpolygons_Polygons$.prototype.polygonPointsExercise__T__V = (function(id) {
var this$11 = $m_Ldoodle_image_syntax_package$all$();
new $c_Ldoodle_image_syntax_AbstractImageSyntax$ImageOps(this$11, image).drawWithFrame__O__Ldoodle_effect_Renderer__Lcats_effect_unsafe_IORuntime__V($n($m_Ldoodle_svg_package$().Ldoodle_svg_package$__f_Frame).apply__T__Ldoodle_svg_effect_Frame(id), $m_Ldoodle_svg_package$().Ldoodle_svg_package$__f_svgRenderer, $m_Lcats_effect_unsafe_IORuntime$().global__Lcats_effect_unsafe_IORuntime())
});
$c_Lpolygons_Polygons$.prototype.points = (function(arg) {
var prep0 = $as_T(arg);
this.points__T__V(prep0)
});
$c_Lpolygons_Polygons$.prototype.polygonPointsExercise = (function(arg) {
var prep0 = $as_T(arg);
this.polygonPointsExercise__T__V(prep0)
Expand All @@ -14569,6 +14565,10 @@ $c_Lpolygons_Polygons$.prototype.vertices = (function(arg) {
var prep0 = $as_T(arg);
this.vertices__T__V(prep0)
});
$c_Lpolygons_Polygons$.prototype.points = (function(arg) {
var prep0 = $as_T(arg);
this.points__T__V(prep0)
});
var $d_Lpolygons_Polygons$ = new $TypeData().initClass({
Lpolygons_Polygons$: 0
}, false, "polygons.Polygons$", {
Expand Down
2 changes: 1 addition & 1 deletion main.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit d0c7da4

Please sign in to comment.