Skip to content

Commit 074526d

Browse files
committed
update index, push generated HTML for instances
1 parent d79ad74 commit 074526d

File tree

3 files changed

+187
-12
lines changed

3 files changed

+187
-12
lines changed

docs/index.html

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<div class="nb-box">
3939
<span><a href=".">🏡</a></span>
4040
<span><code>index.nim</code></span>
41-
<span><a href="https://github.com/pietroppeter/nim-p5"><svg aria-hidden="true" width="1.2em" height="1.2em" style="vertical-align: middle;" preserveAspectRatio="xMidYMid meet" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59c.4.07.55-.17.55-.38c0-.19-.01-.82-.01-1.49c-2.01.37-2.53-.49-2.69-.94c-.09-.23-.48-.94-.82-1.13c-.28-.15-.68-.52-.01-.53c.63-.01 1.08.58 1.23.82c.72 1.21 1.87.87 2.33.66c.07-.52.28-.87.51-1.07c-1.78-.2-3.64-.89-3.64-3.95c0-.87.31-1.59.82-2.15c-.08-.2-.36-1.02.08-2.12c0 0 .67-.21 2.2.82c.64-.18 1.32-.27 2-.27c.68 0 1.36.09 2 .27c1.53-1.04 2.2-.82 2.2-.82c.44 1.1.16 1.92.08 2.12c.51.56.82 1.27.82 2.15c0 3.07-1.87 3.75-3.65 3.95c.29.25.54.73.54 1.48c0 1.07-.01 1.93-.01 2.2c0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z" fill="#000"></path></svg></a></span>
41+
<span><a href="https://github.com/pietroppeter/p5nim"><svg aria-hidden="true" width="1.2em" height="1.2em" style="vertical-align: middle;" preserveAspectRatio="xMidYMid meet" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59c.4.07.55-.17.55-.38c0-.19-.01-.82-.01-1.49c-2.01.37-2.53-.49-2.69-.94c-.09-.23-.48-.94-.82-1.13c-.28-.15-.68-.52-.01-.53c.63-.01 1.08.58 1.23.82c.72 1.21 1.87.87 2.33.66c.07-.52.28-.87.51-1.07c-1.78-.2-3.64-.89-3.64-3.95c0-.87.31-1.59.82-2.15c-.08-.2-.36-1.02.08-2.12c0 0 .67-.21 2.2.82c.64-.18 1.32-.27 2-.27c.68 0 1.36.09 2 .27c1.53-1.04 2.2-.82 2.2-.82c.44 1.1.16 1.92.08 2.12c.51.56.82 1.27.82 2.15c0 3.07-1.87 3.75-3.65 3.95c.29.25.54.73.54 1.48c0 1.07-.01 1.93-.01 2.2c0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z" fill="#000"></path></svg></a></span>
4242
</div>
4343
<hr>
4444
</header><main>
@@ -72,19 +72,14 @@ <h2>nimp5 documentation</h2>
7272
</ol>
7373
<p>License is <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/">CreativeCommons Attribution NonCommercial ShareAlike</a>.</p>
7474
<p>The original sketch has been ported from p5js to p5nim.</p>
75-
<script defer>/* Generated by the Nim Compiler v1.6.0 */
75+
<ol start="8">
76+
<li><a href="./instances.html">Instances</a>: This program creates a canvas in a local p5 instance using &quot;instance mode&quot;, which allows to place a P5 instance into a specific <code>&lt;div&gt;</code> if desired. Otherwise this is the same example as <code>get_started</code>.</li>
77+
</ol>
78+
<script defer>/* Generated by the Nim Compiler v1.7.3 */
7679
var framePtr = null;
7780
var excHandler = 0;
7881
var lastJSError = null;
79-
if (!Math.trunc) {
80-
Math.trunc = function(v) {
81-
v = +v;
82-
if (!isFinite(v)) return v;
83-
return (v - v % 1) || (v < 0 ? -0 : v === 0 ? v : 0);
84-
};
85-
}
86-
87-
var objectID_620757154 = [0];
82+
var objectID_1224736930 = [0];
8883
</script>
8984
</main>
9085
<footer>

docs/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"data":[{"filename":"./get_started.html","title":"Get started","description":"This program creates a canvas that is 400 pixels wide and 400 pixels high, and then starts drawing white circles at the position of the mouse. When a mouse button is pressed, the circle color changes to black.\n","numbering":1},{"filename":"./flashing_canvas.html","title":"Flashing canvas","description":"A canvas that flashes random colors (shows how to change frameRate)","numbering":2},{"filename":"./easing.html","title":"Easing","description":"Move the mouse across the screen and the symbol will follow.\n","numbering":3},{"filename":"./keyboard.html","title":"Keyboard","description":"Click on the image to give it focus and press the letter keys to create forms in time and space. Each key has a unique identifying number. These numbers can be used to position shapes in space.\n","numbering":4},{"filename":"./polygons.html","title":"Polygons","description":"What is your favorite? Pentagon? Hexagon? Heptagon? No? What about the icosagon? The polygon() function created for this example is capable of drawing any regular polygon. Also shows [possible inputs for colors](https://p5js.org/reference/#/p5/fill).\n","numbering":5},{"filename":"./okazz_220919a.html","title":"Okazz 220919a","description":"Art by [Okazz](https://openprocessing.org/user/128718?view=sketches&o=31),\noriginal at [openprocessing.org/sketch/1653811](https://openprocessing.org/sketch/1653811).\n\nLicense is [CreativeCommons Attribution NonCommercial ShareAlike](https://creativecommons.org/licenses/by-nc-sa/3.0/).\n\nThe original sketch has been ported from p5js to p5nim.\n","numbering":6},{"filename":"./okazz_221026a.html","title":"Okazz 221026a","description":"Art by [Okazz](https://openprocessing.org/user/128718?view=sketches&o=31),\noriginal at [openprocessing.org/sketch/1653811](https://openprocessing.org/sketch/1711659).\n\nLicense is [CreativeCommons Attribution NonCommercial ShareAlike](https://creativecommons.org/licenses/by-nc-sa/3.0/).\n\nThe original sketch has been ported from p5js to p5nim.\n","numbering":7}]}
1+
{"data":[{"filename":"./get_started.html","title":"Get started","description":"This program creates a canvas that is 400 pixels wide and 400 pixels high, and then starts drawing white circles at the position of the mouse. When a mouse button is pressed, the circle color changes to black.\n","numbering":1},{"filename":"./flashing_canvas.html","title":"Flashing canvas","description":"A canvas that flashes random colors (shows how to change frameRate)","numbering":2},{"filename":"./easing.html","title":"Easing","description":"Move the mouse across the screen and the symbol will follow.\n","numbering":3},{"filename":"./keyboard.html","title":"Keyboard","description":"Click on the image to give it focus and press the letter keys to create forms in time and space. Each key has a unique identifying number. These numbers can be used to position shapes in space.\n","numbering":4},{"filename":"./polygons.html","title":"Polygons","description":"What is your favorite? Pentagon? Hexagon? Heptagon? No? What about the icosagon? The polygon() function created for this example is capable of drawing any regular polygon. Also shows [possible inputs for colors](https://p5js.org/reference/#/p5/fill).\n","numbering":5},{"filename":"./okazz_220919a.html","title":"Okazz 220919a","description":"Art by [Okazz](https://openprocessing.org/user/128718?view=sketches&o=31),\noriginal at [openprocessing.org/sketch/1653811](https://openprocessing.org/sketch/1653811).\n\nLicense is [CreativeCommons Attribution NonCommercial ShareAlike](https://creativecommons.org/licenses/by-nc-sa/3.0/).\n\nThe original sketch has been ported from p5js to p5nim.\n","numbering":6},{"filename":"./okazz_221026a.html","title":"Okazz 221026a","description":"Art by [Okazz](https://openprocessing.org/user/128718?view=sketches&o=31),\noriginal at [openprocessing.org/sketch/1653811](https://openprocessing.org/sketch/1711659).\n\nLicense is [CreativeCommons Attribution NonCommercial ShareAlike](https://creativecommons.org/licenses/by-nc-sa/3.0/).\n\nThe original sketch has been ported from p5js to p5nim.\n","numbering":7},{"filename":"./instances.html","title":"Instances","description":"This program creates a canvas in a local p5 instance using \"instance mode\", which allows to place a P5 instance into a specific `<div>` if desired. Otherwise this is the same example as `get_started`.\n","numbering":8}]}

docs/instances.html

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
<!DOCTYPE html>
2+
<html lang="en-us">
3+
<head>
4+
<title>instances.nim</title>
5+
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2280%22>🐳</text></svg>">
6+
<meta content="text/html; charset=utf-8" http-equiv="content-type">
7+
<meta content="width=device-width, initial-scale=1" name="viewport">
8+
<link rel='stylesheet' href='https://unpkg.com/normalize.css'>
9+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/light.min.css">
10+
<link rel='stylesheet' href='https://cdn.jsdelivr.net/gh/pietroppeter/nimib/assets/atom-one-light.css'>
11+
<style>
12+
.nb-box {
13+
display: flex;
14+
align-items: center;
15+
justify-content: space-between;
16+
}
17+
.nb-small {
18+
font-size: 0.8rem;
19+
}
20+
button.nb-small {
21+
float: right;
22+
padding: 2px;
23+
padding-right: 5px;
24+
padding-left: 5px;
25+
}
26+
section#source {
27+
display:none
28+
}
29+
30+
.nb-output {
31+
line-height: 1.15;
32+
}
33+
</style>
34+
35+
</head>
36+
<body>
37+
<header>
38+
<div class="nb-box">
39+
<span><a href=".">🏡</a></span>
40+
<span><code>instances.nim</code></span>
41+
<span><a href="https://github.com/pietroppeter/p5nim"><svg aria-hidden="true" width="1.2em" height="1.2em" style="vertical-align: middle;" preserveAspectRatio="xMidYMid meet" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59c.4.07.55-.17.55-.38c0-.19-.01-.82-.01-1.49c-2.01.37-2.53-.49-2.69-.94c-.09-.23-.48-.94-.82-1.13c-.28-.15-.68-.52-.01-.53c.63-.01 1.08.58 1.23.82c.72 1.21 1.87.87 2.33.66c.07-.52.28-.87.51-1.07c-1.78-.2-3.64-.89-3.64-3.95c0-.87.31-1.59.82-2.15c-.08-.2-.36-1.02.08-2.12c0 0 .67-.21 2.2.82c.64-.18 1.32-.27 2-.27c.68 0 1.36.09 2 .27c1.53-1.04 2.2-.82 2.2-.82c.44 1.1.16 1.92.08 2.12c.51.56.82 1.27.82 2.15c0 3.07-1.87 3.75-3.65 3.95c.29.25.54.73.54 1.48c0 1.07-.01 1.93-.01 2.2c0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z" fill="#000"></path></svg></a></span>
42+
</div>
43+
<hr>
44+
</header><main>
45+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.2/p5.min.js" integrity="sha512-rCZdHNB0AePry6kAnKAVFMRfWPmUXSo+/vlGtrOUvhsxD0Punm/xWbEh+8vppPIOzKB9xnk42yCRZ5MD/jvvjQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
46+
<h2>8. Instances</h2>
47+
<p>This program creates a canvas in a local p5 instance using &quot;instance mode&quot;, which allows to place a P5 instance into a specific <code>&lt;div&gt;</code> if desired. Otherwise this is the same example as <code>get_started</code>.</p>
48+
<pre><code class="nim hljs">
49+
<span class="hljs-keyword">import</span>
50+
jsffi, p5
51+
52+
<span class="hljs-keyword">proc</span> foo(): <span class="hljs-built_in">int</span> =
53+
<span class="hljs-number">400</span>
54+
55+
instance:
56+
<span class="hljs-keyword">let</span> x = <span class="hljs-number">5</span>
57+
<span class="hljs-keyword">let</span> y = <span class="hljs-number">10</span>
58+
setup:
59+
<span class="hljs-keyword">let</span> bar = foo() <span class="hljs-comment">## this won't be replaced, as there's no `foo` in p5 that we wrapped</span>
60+
createCanvas(bar, <span class="hljs-number">400</span>)
61+
background(<span class="hljs-number">200</span>)
62+
draw:
63+
<span class="hljs-keyword">if</span> mouseIsPressed:
64+
fill(<span class="hljs-number">0</span>)
65+
<span class="hljs-keyword">else</span>:
66+
fill(<span class="hljs-number">255</span>)
67+
ellipse(mouseX, mouseY, <span class="hljs-number">40</span>, <span class="hljs-number">40</span>)</code></pre>
68+
<script defer>/* Generated by the Nim Compiler v1.7.3 */
69+
var framePtr = null;
70+
var excHandler = 0;
71+
var lastJSError = null;
72+
var objectID_1224736930 = [0];
73+
74+
function foo_1073741846() {
75+
var result_1073741847 = 0;
76+
77+
result_1073741847 = 400;
78+
79+
return result_1073741847;
80+
81+
}
82+
83+
function toFloat_1476395012(n_1476395013) {
84+
var result_1476395014 = 0.0;
85+
86+
result_1476395014 = n_1476395013;
87+
88+
return result_1476395014;
89+
90+
}
91+
92+
function HEX3Aanonymous_1073741854(p5Inst_1073741855) {
93+
94+
function HEX3Aanonymous_1073741858() {
95+
var bar_1073741881 = foo_1073741846();
96+
p5Inst_1073741855.createCanvas(toFloat_1476395012(bar_1073741881), 400.0);
97+
p5Inst_1073741855.background(200.0);
98+
99+
100+
}
101+
102+
function HEX3Aanonymous_1073741882() {
103+
if (p5Inst_1073741855.mouseIsPressed) {
104+
p5Inst_1073741855.fill(0.0);
105+
}
106+
else {
107+
p5Inst_1073741855.fill(255.0);
108+
}
109+
110+
p5Inst_1073741855.ellipse(p5Inst_1073741855.mouseX, p5Inst_1073741855.mouseY, 40.0, 40.0);
111+
112+
113+
}
114+
115+
var x_1073741856 = 5;
116+
var y_1073741857 = 10;
117+
p5Inst_1073741855.setup = HEX3Aanonymous_1073741858;
118+
p5Inst_1073741855.draw = HEX3Aanonymous_1073741882;
119+
120+
121+
}
122+
var sHEX60gensym0_1073741892 = HEX3Aanonymous_1073741854;
123+
var p5InstHEX60gensym0_1073741893 = new p5(sHEX60gensym0_1073741892);
124+
</script>
125+
</main>
126+
<footer>
127+
<hr>
128+
<div class="nb-box">
129+
<span><span class="nb-small">made with <a href="https://pietroppeter.github.io/nimib/">nimib 🐳</a></span></span>
130+
<span></span>
131+
<span><button class="nb-small" id="show" onclick="toggleSourceDisplay()">Show Source</button></span>
132+
</div>
133+
</footer>
134+
<section id="source">
135+
<pre><code class="nim hljs"><span class="hljs-keyword">import</span> nimib, index
136+
nbInit
137+
nbRawHtml: <span class="hljs-string">&quot;&quot;&quot;&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.2/p5.min.js&quot; integrity=&quot;sha512-rCZdHNB0AePry6kAnKAVFMRfWPmUXSo+/vlGtrOUvhsxD0Punm/xWbEh+8vppPIOzKB9xnk42yCRZ5MD/jvvjQ==&quot; crossorigin=&quot;anonymous&quot; referrerpolicy=&quot;no-referrer&quot;&gt;&lt;/script&gt;&quot;&quot;&quot;</span>
138+
nb.addEntry(<span class="hljs-number">8</span>, <span class="hljs-string">&quot;Instances&quot;</span>, <span class="hljs-string">&quot;&quot;&quot;
139+
This program creates a canvas in a local p5 instance using &quot;instance mode&quot;, which allows to place a P5 instance into a specific `&lt;div&gt;` if desired. Otherwise this is the same example as `get_started`.
140+
&quot;&quot;&quot;</span>)
141+
nbJsFromCode:
142+
<span class="hljs-keyword">import</span> jsffi, p5
143+
<span class="hljs-comment"># to test that a local proc is not converted</span>
144+
<span class="hljs-keyword">proc</span> foo(): <span class="hljs-built_in">int</span> = <span class="hljs-number">400</span>
145+
146+
instance: <span class="hljs-comment"># call with `instance(&quot;&lt;name of my div&gt;&quot;)` to place into specific div</span>
147+
<span class="hljs-keyword">let</span> x = <span class="hljs-number">5</span>
148+
<span class="hljs-keyword">let</span> y = <span class="hljs-number">10</span>
149+
setup: <span class="hljs-comment"># `setup` and `draw` are templates shadowing the global templates</span>
150+
<span class="hljs-keyword">let</span> bar = foo() <span class="hljs-comment">## this won't be replaced, as there's no `foo` in p5 that we wrapped</span>
151+
createCanvas(bar, <span class="hljs-number">400</span>) <span class="hljs-comment"># each call will be checked against calls wrapped in the p5nim wrapper.</span>
152+
<span class="hljs-comment"># If a name matches, it will be replaced by `p5Inst.&lt;the call&gt;` instead.</span>
153+
background(<span class="hljs-number">200</span>)
154+
155+
draw:
156+
<span class="hljs-comment"># similar to calls, idents are also compared with known fields of the</span>
157+
<span class="hljs-comment"># `P5Instance` type and replaced by `p5Inst.&lt;field&gt;` in case of a match</span>
158+
<span class="hljs-keyword">if</span> mouseIsPressed:
159+
fill(<span class="hljs-number">0</span>)
160+
<span class="hljs-keyword">else</span>:
161+
fill(<span class="hljs-number">255</span>)
162+
ellipse(mouseX, mouseY, <span class="hljs-number">40</span>, <span class="hljs-number">40</span>)
163+
164+
nbJsShowSource()
165+
nbSave
166+
</code></pre>
167+
</section><script>
168+
function toggleSourceDisplay() {
169+
var btn = document.getElementById("show")
170+
var source = document.getElementById("source");
171+
if (btn.innerHTML=="Show Source") {
172+
btn.innerHTML = "Hide Source";
173+
source.style.display = "block";
174+
} else {
175+
btn.innerHTML = "Show Source";
176+
source.style.display = "none";
177+
}
178+
}
179+
</script></body>
180+
</html>

0 commit comments

Comments
 (0)