Incorporating p5.js sketches into dynamic NFT creation

Hey everyone! I’m trying to figure out how to make NFTs with p5.js that change each time. I’ve seen people use SVG-based methods, but that’s not what I want. I’m looking for a way to store my p5.js script on-chain and maybe pass a seed to it. That way, the NFT would look a bit different every time the code runs. Is this even possible? Here’s a simple example of what I’m thinking:

function createDynamicNFT(seed) {
  let sketch = function(p) {
    p.setup = function() {
      p.createCanvas(200, 200);
      p.randomSeed(seed);
    }
    p.draw = function() {
      p.background(220);
      p.ellipse(p.random(width), p.random(height), 50, 50);
    }
  }
  return sketch;
}

Does anyone know if there’s a way to make this work with NFTs? I’m really curious to hear your thoughts!

hey nina, that’s a super cool idea! i’ve been tinkering with p5.js too and i’m fascinated by the potential for dynamic nfts. have you thought about using a hybrid approach? like, what if you stored a simplified version of your sketch logic on-chain, but kept the full p5.js library off-chain? that way, you could still pass a seed to generate unique variations without the crazy gas costs.

oh, and here’s a random thought - what if you used the nft’s token ID as part of the seed? that could make each one truly unique!

i’m really curious how you’re planning to handle the rendering part. are you thinking of using a custom front-end to interpret and display the on-chain logic? it’d be awesome to see how that works!

what kind of visuals are you aiming for with your nfts? i bet you could come up with some really mesmerizing generative art pieces. maybe we could brainstorm some ideas together?

yo nina, cool project! have u considered using a serverless function to generate ur nft art? u could store ur p5.js script off-chain, then use the function to run it with different seeds. this way, u get dynamic nfts without the gas costs of on-chain storage. just an idea to explore! :art::sparkles:

Incorporating p5.js sketches into dynamic NFTs is an intriguing concept, but it comes with challenges. While storing the entire p5.js library on-chain isn’t feasible due to gas costs, you could explore alternatives. One approach is to store a minimized version of your sketch code on-chain and use a custom renderer off-chain. This way, you can pass the seed and any additional parameters to generate unique variations. Another option is to use a deterministic algorithm that produces consistent results based on the input seed. You could then store this algorithm on-chain and use it to generate the visual elements of your NFT. This method ensures the uniqueness of each piece while maintaining the core concept of on-chain generation. Remember to consider the limitations of blockchain storage and execution when designing your dynamic NFT system. It’s a complex endeavor, but with careful planning, you can create innovative and engaging NFTs that leverage p5.js-like functionality.