Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
Using template file to generate unique files locally with p5.js

I have a template JS file where I need to change 1 variable and then save a copy of that js file. I cannot use node because it does not support p5. I'm wondering if there is a way to do this locally.

let result;
function preload() {
  result = loadStrings('template.js')
}
function setup() {
  if (result[0] != null) {
    result[0] = "let number = "+"\"" + 1 + "\"";
    let writer = createWriter('modifiedTemplate.js');
    writer.write(result)
    writer.close()  
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.min.js"></script>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If I'm understanding correctly, you want to load a file, edit it and save it as a new file. In that case, what you have is pretty much there.

The only potential issues I can see are the following - Let's say you have a templates file that looks like:

let number = 10;
let count = 4;

And you want to change let number = 10 to let number = 1. First of all, you can use template literals to do that:

result[0] = `let number = 1;`;

Then what you have should save the file, however it wouldn't be in the format you might expect - the output of the file would be:

let number = 1;,let count = 4;

That's the nature of the javascript toString method. I'd recommend joining the array and separating each line by a new line:

writer.write(result.join('\n'));

Which should output like the following:

let number = 1;
let count = 4;

If you get stuck I've implemented this in a p5.js sketch which should point you in the right direction.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!