NFTBirds - Python generation script walkthrough

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello this is the voice of bit birds this video is going to be a informal walkthrough of how this bit bird generation python script functions um i will be jumping on and off the screen because on a couple previous takes i've you know opened up a file tree that has my full name in it or something like that so so bear with me on that one uh before i dig in i did want to mention that if you're just getting into this and you're not really that familiar with programming i'll kind of set the expectation that setting up the dependencies could be a bit of a tricky process for you but if you're persistent i believe that you can do it often in technology installing something like pip which is a python installation mechanism is something that the developer doesn't even really think about because it's been on their computer for you know a long time and they use it all the time so so setting that up for someone that's that's coming into it new can be a bit of a tricky sticking point in in my experience if you're having issues um please reach out to the community we would we would certainly not want to deny you the opportunity to struggle but at the same time we don't want you to get stuck and and kind of give up so reach out to the community on twitter or discord and we'll see if we can get you sorted so without further ado this is the asset that i will be sharing i'll share a link right to this github repository on twitter and on discord if you're familiar with git you can clone this repository if you're not um often it's easiest to just go right to this section and say i want to download this repository as a zip file actually that is somewhere that in in my experience it has popped up my name so i'm going to pull this off screen real quick and click that download zip button cool so i've downloaded that right to my desktop um i can drag the file over here it is generate dash bit birds dash main dot zip depending on your uh on your computer you can extract that zip file in different ways it might be uh right click extract or something like that but what i do on my mac is just double click it and that leaves us with a folder here of generate dash bit birds dash main so if i jump into that these are the assets that that make up this this repository basically so we don't need this necessarily anymore this is where we are working from here on out the bitbird generation script is how the script how the images are actually generated this bird images folder is where they will be generated to and i've got a placeholder text file in here just so that github does include that file if i were to just click this it would open in in my code code editor visual studio there's some other good ones like sublime text and uh and brackets and adam and just many of them but i can go ahead and open this and it will pop us into uh vs code now you can run this in a number of ways you could run it from the command line if you're familiar with that vs code has a pretty convenient little execute button in the top right here so this little play button up here green arrow is going to let us run that when i do go to run that it will again pop up a terminal with my name in it so i will pull that off screen to do that right now i'll pull open this this bird images folder and we'll be able to actually see the images generate in there as i hit execute and so i've just done that i'll pull this down and this is super zoomed but we'll go through how this script is functioning uh python often has you import different libraries so that's we're starting with we're importing this one is the python imaging library and specifically a fork of the original python image library called pillow that i my understanding is it works better with python 3. and so this is basically just telling the code we can now use the resources of this pil functionality uh same sort of thing with uh numpy here i like that i like to call it numpy personally but that's probably wrong it gives us the ability to work with arrays importing os gives us the ability to interact with uh some some things about the operating system itself so for example we are going to use that to generate a a path to where we are going to create these files because it will do that dynamically in my original version of this it just had a static path through you know users slash my name slash whatever to get to this bird underscore images folder but we need to do that dynamically because that path would not be the same on your computer this random library allows us to generate pseudo-random numbers and i go into a bit more about what that means in uh in the read me uh but effectively what it is is it'll generate a deterministic random number so from the same starting seed uh we'll see a bit later it'll always generate the same first random number and then the same second random number and that sort of stuff so it's not truly random in a mathematical or a security sense but it does give us enough variation that we can kind of generate these randomized parts last bit here is it's just setting uh these couple variables the directory name so that it can use it later for the sort of the path to where those files will be created and then the dimensions of the the image which we'll use later at uh 480 by 480 pixels once we get to this point this is basically a loop it is going to loop through this functionality for every single bird and it will do it as we've defined here 50 times it will start with time number zero it will run to uh time number 49 i don't believe it'll run to number 50 but we can actually probably check that on the birds itself uh yeah so it runs 249 there it does include seems to include the first number it doesn't include the second number uh that's kind of the devil's in the detail sort of stuff the first thing that we do in this loop that's generating each bird is kind of define a starting seed number so in this case i used the last eighth block that that happened before i generated all of these images and each time it loops through it will add the iteration number to this so basically for the first time it'll use it as one one nine eight one two oh seven the next time it'll do that plus one then the time after that that plus two et cetera so each time it's kind of starting each bird with a different seed number uh just by kind of kind of using this these random integer mechanisms are what are actually generating those pseudo-random numbers so i'll actually give a three-second overview of what's happening here and then we'll jump down a little bit and we'll come back up to uh to sort of this level this is where we're generating all of the colors and all of the different traits of the birds we're generating the head color the throat color the the color of the eye whites in crazy birds uh crazy eyebirds the beat color that sort of stuff i'll pause on how specifically it's doing that to jump down very briefly uh this is the image itself so each one of these is itself a pixel so this is a 24 by 24 pixel image basically it has 24 arrays of pixels so each array is a list it's got kind of one big array here with a bunch of arrays in it so each one of these is a line and then each of these is a pixel within that line so you can actually see as i'm highlighting this you can kind of see where the variables are these bg variables are background the ol variables are outline hd variables are head color th is throat color beat color etc so so this kind of gives you a picture of how this image itself is being generated it's happening pixel by pixel with each of these variables and actually if we look over here to the right we can see that in each of these different four blobs you can kind of see the outline of the bird itself and if you zoom way out on the code just based on those slight differences in the variables you can see those i did choose two letter variables for all of these just so that it would stay in nice organized rows and lines and that makes it a lot easier to to work with and to look at so we've got one for woodpecker we've got one for j we've got one for eagle we've got one for cockatoo and so we can see that the cockatoos outline has these kind of crazy other lines and that sort of stuff so with that in mind that's the context i wanted to share as we go into how each of these different characteristics are being generated the head color is using this random integer mechanism uh to generate something between 1 and 255 for each of the rgb values so that's red green blue values in a color so this will basically say something like you know here's a here's a static rgb value for example so 240 248 and 255 that's a very light color the the sort of ends of the spectrum here would be zero zero zero is totally black 255 255 255 is totally white and then you've got a range of stuff in between there so you could say you know i want to do uh i don't know if it's percentage or basically units of of red or units of blue in this color so it's kind of like when you go to home depot and they uh they're mixing you up some paint so the first bit here is generating that rgb value for the head by generating three random numbers between one and uh and 255. same thing with the throat color so in theory these could all be random in the read me on on the github repository i've put some more notes and i'd be eager to discuss these if folks may uh may spy some patterns or no more i do think the way i'm using these seeds to basically say i'm going to generate from this number a next random number and that next random number is going to be the seed for these i'll generate a new random number so they're kind of these random numbers are chaining off of each other and i think with some of these logical layers uh it's it's causing certain behavior where certain attributes seem to not be able to pair up with other attributes for example um i don't think uh from well i certainly haven't seen any and it seems to me that this script the way the logic chains together and decides on beak color and then decides on which bird it seems to never be able to to generate a red beaked woodpecker another example and actually the one where i originally realized that there may be some strange behavior going on it was about halfway through the minting so we were already in it to win it i realized that all of the cockatoos had the same blue crest so as i mentioned in the readme i've actually gone through and for for cockatoos number two three and four i've done a separate run of cockatoos and swapped those those blue crested ones in with some others just so that there's a little bit more variability to those it wouldn't be fun to have you know all four of the the unique special cockatoos as pretty similar birds with the blue crest but other than that this exact script is precisely the birds that are that are minted as nfts and those cockatoos i will mention those were only put in in the place that the random order did actually already generate a cockatoo i just changed a little bit of uh which ones were going into those those four slots of 1500 so what we saw in the first bit is it's generating sort of those color variables randomly this is where we get into a bit of a different angle and it's using a random number uh to to basically define uh some sort of logical statement so here we're saying we want to set d equal to a random integer between zero and a thousand that could be you know 683 it could be 14 yadda yadda and so basically here it's just saying okay in this sort of chain of random numbers when we get to d if d is less or if d is 47 or less or if d is specifically greater than in this highlighted one 47 then it's going to be normalized so they'll have this you know almost white eye background and black pupils or else so this else would hit if it's 47 or less so a 4.7 probability if you're looking at 47 out of 1000 then it'll have crazy eyes so in that case we're generating uh the eye white color sort of the background of the eyes in the same way we're generating this uh this this top bit for the throat color and the head color and then the eye pupil is sort of a very reddish sort of crazy looking thing um so that's how we kind of make the logical decision to say this bird should have crazy eyes or should not have crazy eyes we take that same sort of thing even a little bit further into the beak color so here we'll say we want to set the beak color we want to do a variable called f again we've sort of from the previous sections defined a new seed so it'll kind of generate a random new number for each of these sections and we're basically saying okay we for f we want to make that a random integer again between zero and a thousand so again it could be 983 it could be 12 whatever and then it's going to evaluate that and it says if f is greater than 500 then it's going to be gray beak if it's between 547 pretty much with some equals and not equals in those then it'll be a gold beak so gold beaks and gray beaks are most of them that's basically uh from anything 48 to a thousand it's going to be a gold beak or a grey beak the red beaks show up if it's between 47 and 8 the way this you know greater than or equal to and this is just greater than so 7 is not included in this particular calculation 47 is included in this calculation just for folks that may not recall that or may not know the syntax of that in in python but yeah basically this is saying it'll be a red beak if the number generated is between 8 and 47 and then other than that that's basically saying everything else it's already spoken for if the random number is seven or less that's how you get a black beak so that is slightly less than a one percent probability of a black beak on any given bird background color and the outline color is going to be the same every time so that's just kind of a gray and a black outline and then we get to the section where we're defining all of these birds we've already taken a look at that perhaps it will it will resonate a bit more now that we have some context on how each of these variables are being set so you know we've got the j outline variables we've got that randomly generated head color randomly generated throat color uh sort of selected beak color that comes from a handful of of pre-configured options we've got the i pupil in those two pixels and then we've got the eye white in those six pixels and so unless it's a crazy crazy eyebird um that will always be the same sort of you know lightish gray but not not pure white we've got the eagle we've got the cockatoo and here's where we actually decide which bird to use again we've got a seed number and we're generating a random and then we're going to make a decision based on that we're basically saying okay if this random number the last in our random number chain is 251 or greater since this one doesn't include 250 then it will be a basic bird so roughly 75 chance or maybe exactly 75 chance that it will be a basic bird or else if it's between 100 and 250 then it'll be a j so that's probably a 15 percent chance of course because 150 out of a thousand uh 15 chance it'll be a j between 40 and 100 that'll be a woodpecker so that's about a six percent chance between 5 and 40 that will be an eagle with 5 not being included so basically if the number is 6 240 that will be an eagle if the number then doesn't hit any of those rules that means the number is 5 or less and that is how we get a cockatoo so from here we're near the bottom of the loop this is basically just saying we want to to turn this into some data that is usable i couldn't even say exactly why numpy is doing this or numpy is doing this but it is so i just go with it this is using the python image library or pillow to create the image from this new array of pixels uh here's where we're actually generating the file name that will be used for this so it's basically looking now for a folder in the same folder as this we've got the der name that would be like users slash name slash desktop slash project slash whatever so that's going to find wherever we are dynamically wherever this is being run put that at the beginning of the the url i guess or kind of the file path it'll then say okay and we're going to add slash bird images so this is now looking for the bird images folder and it's looking for the bird number so we saw for example that each of these is you know number nine number 10 number 11. you may recall that that x variable was from way up at the top that was like the iteration number and then we're just ending it out with dot png which is the file name and then this saves that file at that point we have created one single bird and it jumps right back to the top and it'll say okay now that we've created bird number one uh we are now on uh so it'll start with zero then one then two yadda yadda if we just created bird number three it'll say okay now we're on bird number four x is four we're gonna say this is uh one one nine eight one two seven plus four so one two one one as kind of the starting seed and then it'll generate all those those random mechanisms from there so with that i hope that was valuable uh i would say if you want to explore and and change this um a very easy way to test it is to to start this with a different seed if you were to say hey i want the seed to be 15 instead of this this ether block number that'll generate a whole different set of birds um if you wanted to mess with the number of birds generated you could set this how many loops basically is is what this line is saying it's saying as long as you know x is between 0 and 49 we'll keep doing this loop and once we get to 50 we're done but if you wanted to say i want to make this 200 birds or something like that you can absolutely do that and it will generate up to bird 199. another area if you're kind of looking to more get into the actual generative art layer is to start messing with these i could say you know i want to make the outline of this i want to make these background pixels be outline pixels or head color pixels or something like that so this is kind of a a very manual way to create an image pixel by pixel but fortunately the program once you've created the sort of template can can generate the images for you very quickly you can kind of modify all of this you could you know if you really wanted to mess around with a bunch more pixels you could do more than 24 by 24 you could uh you could do all sorts of different stuff you can even add your own little variables in if you wanted to say um you know there's like an eyeglasses variable or something like that you could create your own variable you could create some logic on how it's set and then you're basically you know would do something like if this random number that we've picked is you know if we're giving out a 50 50 chance if it's greater than 500 then we want to set the eyeglass equal to like you know a black or a brown color that variable will then show as an eyeglass or else maybe we just say okay we want to if there's no eyeglasses then we just want to set the eyeglasses equal to what would be in that position otherwise like the head color or something like that so i hope this was valuable as i mentioned um this this is a an exciting area it's really been a joy to explore please reach out to the community uh if if you're really banging your head off of something i've in in my day job i'm not a professional coder but i do work with technology quite a bit and the rule of thumb is usually you know if you've spent more than half an hour on one particular error message that you feel like should be solvable that's that's a pretty good threshold to reach out and and raise your hand and uh and yeah if you if you ask good questions i'm sure the community and i myself will be very eager to uh to help unblock you uh so a good question will basically say like here's what i have here's what i'm trying here's what i have tried here is what i expect to be happening but instead i'm getting you know this xyz error message the more detail you can provide the more useful what is not necessarily a good question is just kind of saying like i need help with this or something like that that'll that'll uh not get you too far in uh in the rough and tumble world of the internet i hope this will uh inspire someone i hope it'll have someone or multiple people expand their skill sets i i hope you uh you know come to explore this and enjoy it and learn some new things and and maybe in some some small way or large way can better your life from uh from the experience of exploring this and learning from it and i i sincerely appreciate everyone's engagement with the bit birds project thanks for watching
Info
Channel: NFTBirds
Views: 11,110
Rating: 4.9257293 out of 5
Keywords: python, ethereum, nft, bitbirds
Id: vTxjLLHncMo
Channel Id: undefined
Length: 20min 53sec (1253 seconds)
Published: Sat Mar 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.