# Jupyter/pluto version of Processing

**URL:** <https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654>\
**Category:** Pluto\
**Created:** [March 21, 2021, 1:33pm UTC](https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654 "2021-03-21T13:33:53Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [March 21, 2021, 1:33pm UTC](https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654/1 "2021-03-21T13:33:53Z")

</div>

One of my favorite things about [Processing](https://processing.org/) is that you can interact with a simulation while it is running. [Here is an example](https://weymouth.github.io/fluid-dynamics/vortexpanel/index.html) where a swarm of particles are advecting continually in a flow, and changing the shape of the foil changes the underlying velocity field. It’s great for education and outreach activities.

Observables in Makie and Pluto seem tantalizingly close to realizing this capability, but I haven’t seen this done anywhere and my attempt today failed. Are there some examples of this I’ve missed? Any ideas for where to start?

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [March 21, 2021, 7:39pm UTC](https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654/2 "2021-03-21T19:39:23Z")

</div>

I only very quickly looked at Processing - as far as I have seen their central point is that the `draw()` function is executed automatically in short time intervals.  
In Pluto you could archive this with a [GitHub - JuliaPluto/PlutoUI.jl](https://github.com/fonsp/PlutoUI.jl) Clock element:

```julia
@bind tick PlutoUI.Clock(interval=0.001)

begin
    tick
    draw()
end

```

---

<div class="post-metadata">

**Author:** ![StatisticalMouse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/statisticalmouse/32/43370_2.png) [@StatisticalMouse](https://discourse.julialang.org/u/StatisticalMouse)\
**Post date:** [March 21, 2021, 8:00pm UTC](https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654/3 "2021-03-21T20:00:55Z")

</div>

Can the clock element animate moving a slide element?

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [March 21, 2021, 8:17pm UTC](https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654/4 "2021-03-21T20:17:13Z")

</div>

That’s great!

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [March 21, 2021, 8:23pm UTC](https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654/5 "2021-03-21T20:23:52Z")

</div>

The clock element just triggers execution of the cells where its `@bind` variable is referenced in regular intervals. The rest needs to be implemented in these cells.

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [March 21, 2021, 9:12pm UTC](https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654/6 "2021-03-21T21:12:17Z")

</div>

This works, but it is quite slow (framerate around 1). This is probably because I’m not updating the plots as efficiently as I could. If you know of any examples using this to update large plots quickly, I’ll take another look next week.

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [March 23, 2021, 3:08pm UTC](https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654/7 "2021-03-23T15:08:31Z")

</div>

Here’s the result if you want to play around with it: [WaterLily.jl/Pluto\_test.jl at master · weymouth/WaterLily.jl · GitHub](https://github.com/weymouth/WaterLily.jl/blob/master/notebooks/Pluto_test.jl)

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [March 30, 2021, 12:04pm UTC](https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654/8 "2021-03-30T12:04:16Z")

</div>

Sorry, but it seems there has been a change and this no longer works?

```julia
@bind tick PlutoUI.Clock(interval=0.001)

Failed to show value:

UndefVarError: interval not defined

```

Any idea what’s going on?

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [March 30, 2021, 1:05pm UTC](https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654/9 "2021-03-30T13:05:31Z")

</div>

Strange, it works for me:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/1/e1a430f78df0581a8d1d156dfd0e1a9d764a4b09.png)

Edit: I am using Pluto v0.12.21 and PlutoUI 0.7.6.

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [March 30, 2021, 2:38pm UTC](https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654/10 "2021-03-30T14:38:05Z")

</div>

I guess it was a version thing. I just updated to those (most recent) versions and it works again.

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [March 31, 2021, 12:07pm UTC](https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654/11 "2021-03-31T12:07:14Z")

</div>

Sorry to keep bugging on this, but I have one more question.

The `clock` works great to repeatedly call a mutating function `step!(sim)`. However, every time I update a parameter of `sim` using a slider, Pluto automatically reinitializes the strut. That’s a great default behavior, but is there a way to tell Pluto how to mutate the struct instead of reinitializing? I would like it to call a specific function, say `update!(sim)`, instead of calling the initial `sim=Simulation(...)` function again.

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [March 31, 2021, 1:27pm UTC](https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654/12 "2021-03-31T13:27:48Z")

</div>

You could wrap the struct into a Ref to prevent automatic updates, see [Zulip](https://julialang.zulipchat.com/#narrow/stream/243342-pluto.2Ejl/topic/introducing.20state)

Edit: Paste from Zulip:  
also consider defining a Ref in a separate cell, which never reruns (because it has no dependencies):

```julia
did_the_thing = Ref(false)

```

Use it like so:

```julia
if condition && !did_the_thing[]
    did_the_thing[] = true
    # code that should run only once
end

```

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [March 31, 2021, 1:37pm UTC](https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654/13 "2021-03-31T13:37:51Z")

</div>

Zulip? Sigh. Why not? This is like the 40th chat/stream/channel thing I’m on now…

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [March 31, 2021, 5:21pm UTC](https://discourse.julialang.org/t/jupyter-pluto-version-of-processing/57654/14 "2021-03-31T17:21:53Z")

</div>

That didn’t work, but I’ve posted the question on zulip (sigh) and will report back.
