Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda