Skip to content

Commit

Permalink
Modify the name of the generated JS functions appending ginpar_
Browse files Browse the repository at this point in the history
Instead of `myFunction`, name them `ginpar_myFunction` to avoid easy
collisions if users define `myFunction`.

They're still possible, but they must also append `ginpar_`.

Implement a `ginpar_save` function that will save the image using the
random and noise seeds in the name.
  • Loading branch information
davidomarf committed Nov 3, 2019
1 parent 4eb47a2 commit 6cceb22
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ginpar/templates/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<label for="{{ id }}">
{{ name }}
</label>
<input name="{{ id }}" id = "{{ id }}" {{ attrs | getattrs }} onchange="updateVars(); setup(); draw();">
<input name="{{ id }}" id = "{{ id }}" {{ attrs | getattrs }} onchange="ginpar_updateVars(); setup(); draw();">
</div>
22 changes: 15 additions & 7 deletions ginpar/templates/retrieve.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
var RANDOM_SEED = Math.round(Math.random() * 100000000)
var NOISE_SEED = Math.round(Math.random() * 100000000)

{% if global_seed -%}
function newRandomSeeds(){
RANDOM_SEED = Math.random() * 100000000
NOISE_SEED = Math.random() * 100000000
function ginpar_newRandomSeeds(){
RANDOM_SEED = Math.round(Math.random() * 100000000)
NOISE_SEED = Math.round(Math.random() * 100000000)
}
{%- endif %}


function resetDraw(){
updateVars(); setup(); draw();
function ginpar_resetDraw(){
ginpar_updateVars(); setup(); draw();
}

function updateVars(){
function ginpar_updateVars(){
{% for param in params -%}
{%- if param["attrs"]['type'] == 'dimensions' -%}

Expand All @@ -28,5 +31,10 @@ function updateVars(){
{%- endfor %}

}
updateVars()

function ginpar_save(){
save(`${RANDOM_SEED}-${NOISE_SEED}`)
}

ginpar_updateVars()
{{'\n'}}

0 comments on commit 6cceb22

Please sign in to comment.