使用p5js脚本的NFT?



我看到有人在基于svg的nft中使用这种方法:

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

但是,因为我不想生成一个固定的图像,我怎么能使用我的p5js脚本(每次js代码运行时看起来略有不同)?是否有一种方法,只是以某种方式传递种子到我的脚本和脚本的种子传递给它是存储在链上?

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('');
}

试试这个https://editor.p5js.org/josepssv/full/wsCZnJqkA

相关内容

  • 没有找到相关文章

最新更新