@dedrick
You can use the loadJSON()
function in p5.js to get JSON data with variables. Here's an example:
1 2 |
let name = "Alice"; let age = 25; |
1 2 3 4 |
let jsonData = { name: name, age: age }; |
1 2 3 4 5 6 7 |
function setup() { loadJSON('data.json', gotData); } function gotData(data) { console.log(data); } |
In this example, data.json
is a file containing the JSON data with the variables name
and age
. When the data is loaded, the gotData
function is called with the JSON data as an argument, and you can access the variables using dot notation (e.g., data.name
, data.age
).