Skip to content

Commit

Permalink
Only create RANDOM_SEED and NOISE_SEED when global_seed is True
Browse files Browse the repository at this point in the history
Check for the existence (and truthness) of `global_seed` inside the
`sketch/data.yaml` configuration file.

This will only add the `newRandomSeeds()` function if sketch is
globally-seeded
  • Loading branch information
davidomarf committed Nov 3, 2019
1 parent c4a0f76 commit 4eb47a2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 1 addition & 2 deletions ginpar/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,7 @@ def render_sketch_page(build_path, sketch, site, page_template, input_templates)

## Copy all the content from original sketches/{title}.js to sketch.js
sf = open(sketch["script"], "r")

sketch_script.write(gg.makeValueGetter(list(params)))
sketch_script.write(gg.makeValueGetter(("global_seed" in sketch["data"] and sketch["data"]["global_seed"]), list(params)))
for x in sf.readlines():
sketch_script.write(x)
sf.close()
Expand Down
5 changes: 2 additions & 3 deletions ginpar/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ def dict_to_attrs(d):
_jinja_env.filters["getattrs"] = dict_to_attrs


def makeValueGetter(attrs):
def makeValueGetter(global_seed, attrs):
_TEMPLATE = _jinja_env.get_template("retrieve.js")

return _TEMPLATE.render(params=attrs)
return _TEMPLATE.render(global_seed = global_seed, params=attrs)


def sketch_to_dict(s):
Expand Down
7 changes: 5 additions & 2 deletions ginpar/templates/retrieve.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{% if global_seed -%}
function newRandomSeeds(){
RANDOM_S = Math.random() * 100000000
NOISE_S = Math.random() * 10000000
RANDOM_SEED = Math.random() * 100000000
NOISE_SEED = Math.random() * 100000000
}
{%- endif %}


function resetDraw(){
updateVars(); setup(); draw();
Expand Down

0 comments on commit 4eb47a2

Please sign in to comment.