# Save sketch as js-file with random params at runtime

**URL:** https://discourse.processing.org/t/save-sketch-as-js-file-with-random-params-at-runtime/36542
**Category:** Coding Questions
**Created:** [April 23, 2022, 11:03am UTC](https://discourse.processing.org/t/save-sketch-as-js-file-with-random-params-at-runtime/36542 "2022-04-23T11:03:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![res56](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@res56](https://discourse.processing.org/u/res56)
#### Post date: [April 23, 2022, 11:03am UTC](https://discourse.processing.org/t/save-sketch-as-js-file-with-random-params-at-runtime/36542/1 "2022-04-23T11:03:41Z")

</div>

Hi frens,

it is possible to save a sketch as javascript-file with “values” of random function at runtime?

Thanks in advance,  
Res

---

<div class="post-metadata">

### Author: ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)
#### Post date: [April 23, 2022, 11:22am UTC](https://discourse.processing.org/t/save-sketch-as-js-file-with-random-params-at-runtime/36542/2 "2022-04-23T11:22:13Z")

</div>

Would you like to save the values in a file as data?

See [p5.js Reference: `saveJSON()`](https://p5js.org/reference/#/p5/saveJSON).

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [April 23, 2022, 11:42am UTC](https://discourse.processing.org/t/save-sketch-as-js-file-with-random-params-at-runtime/36542/3 "2022-04-23T11:42:31Z")

</div>

> [@Creating and Populating a Table From Scratch](https://discourse.processing.org/t/creating-and-populating-a-table-from-scratch/12658/3):
>
> I’ve made a sketch that stores and reads an array of CSV row strings from the browser’s local storage using storeItem() & getItem() respectively; then converts that array to p5.TableRow objects; and finally use p5.Table::addRow() to populate a p5.Table container: card_index_dividers[http://p5js.org/reference/#/p5/getItem](http://p5js.org/reference/#/p5/getItem)[http://p5js.org/reference/#/p5.Table/addRow](http://p5js.org/reference/#/p5.Table/addRow) Each mouse click adds a new p5.TableRow to the p5.Table container, updating the browser’s local storage as well. …

---

<div class="post-metadata">

### Author: ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)
#### Post date: [April 23, 2022, 11:55am UTC](https://discourse.processing.org/t/save-sketch-as-js-file-with-random-params-at-runtime/36542/4 "2022-04-23T11:55:45Z")

</div>

Following is an example that calculates a random width and height for an ellipse, draws the ellipse, and saves the width and height of the ellipse in a `.json` file:

```auto
let json = {};

function setup() {
  createCanvas(320, 320);
  background(200);
  noLoop();
}

function draw() {
  // calculate width and height of ellipse
  w = random(width / 2, width);
  h = random(height / 2, height);
  // draw the ellipse
  ellipse(width / 2, height / 2, w, h);
  // populate the json object with the w and h data
  json.w = w;
  json.h = h;
  // save the data in a json file
  saveJSON(json, 'ellipse.json');
}

```

Later on, you can read the saved file in order to use the data. See [p5.js Reference: `loadJSON()`](https://p5js.org/reference/#/p5/loadJSON).
