Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda