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

123
Vistas
Use p5js script for an NFT?

I have seen people use this method for SVG-based NFTs:

function p5jsToImageURI(){
    string memory baseURL = "data:image/svg+xml;base64,PUT-BASE64-HERE"
}

But, since I don't want to generate a fixed image how can I use my p5js script (that looks slightly different each time the js code runs)? Is there a way to just somehow pass the seed to my script and the script with the seed passed to it is stored on-chain?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

var img,inpt,div

function convertImgToDataURLviaCanvas(url, callback, outputFormat){
    var img = new Image();
    img.crossOrigin = 'Anonymous';
    img.onload = function(){
        var canvas = document.createElement('CANVAS');
        var ctx = canvas.getContext('2d');
        var dataURL;
        canvas.height = this.height;
        canvas.width = this.width;
        ctx.drawImage(this, 0, 0);
        dataURL = canvas.toDataURL(outputFormat);
        callback(dataURL);
        canvas = null; 
    };
    img.src = url;
}

function convertFileToDataURLviaFileReader(url, callback){
    var xhr = new XMLHttpRequest();
    xhr.responseType = 'blob';
    xhr.onload = function() {
        var reader  = new FileReader();
        reader.onloadend = function () {
            callback(reader.result);
        }
        reader.readAsDataURL(xhr.response);
    };
    xhr.open('GET', url);
    xhr.send();
}


function img2b64(imagefile){
    var imageUrl = imagefile;
    var convertType = 'Canvas';    
    var convertFunction = convertType === 'FileReader' ?  convertFileToDataURLviaFileReader :   convertImgToDataURLviaCanvas;
    convertFunction(imageUrl, function(base64Img){
        code='foto = "'+base64Img+'";'
        inpt.value(code)
        div.html('<img src="'+base64Img+'">');  
     });
}



function setup() {
  but = createButton("CONVERT");
  but.mousePressed(function () {
      img2b64('nature100b.jpg');

  });
  inpt = createP('');
  inpt = createElement("textarea",'');
  inpt.elt.rows = 5;
  inpt.elt.cols = 50;
  div = createDiv('');

}

Try this https://editor.p5js.org/josepssv/full/wsCZnJqkA

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