 Hey, how's it going everybody? My name is John Hammond and I'm looking again at Python challenge A lot of people have asked me to get back into this so I figured I would try my best and here we are looking at challenge 16 We just finished looking at Mozart stuff now. We're granted with this image and honestly I have no idea what I'm looking at right now this looks like just a bunch of pixel colors and Kind of scribble stuff looks like a bunch of static Although I do see a lot of these like weird pink purple things like all over the place Looking at this initially I want to you know, I'll view the image so we can kind of zoom in on a little more Move it around. Okay. I guess I can't really do that that well Let's grab it and play with it in paint or something I'm putting all these in a specific folder for Python challenge You might want to do the same thing. I'll just put it there and then I'll open up color paints to actually open that file And I'll zoom in on it a bunch Okay So, I mean I can see like lighter pixels like we can see those lighter areas that just looks like static and It looks like these like pink purple dividers are on every row, right? Like we can see them on literally every single line in the image But these color values are so distinct. They probably aren't going to translate to like ASCII characters I don't feel like Since there's only one of these pink dividers on like every row it looks like At least from what I see are these on these are pretty close. So these on two different rows two three four and Two three five. Yeah, they're all on different rows. There's only one of them on each row I don't feel like it's like a divider between a bunch of these random color characters that could represent like ASCII texts to generate a message I don't feel like that's it. I Don't know what It could be referring to there's nothing. It's not like it's hiding any text anywhere else in the image Since the only thing we can like visibly see are all of these like pink dividers I'm curious if you know Because like look at all these like static lines that are a little bit lighter. They must go somewhere together I wonder if all of these like pink divider spots have to be aligned and like put together in a Vertical sequence, you know, we can probably do that We can definitely do that in Python with like the image library and the image like operations library If you haven't seen that we can just like move These into a specific position with an offset and all the data like every single line will be put together for us We'll just have to like chop up and like crop each individual row. We could totally do that I guess let's try that just to poke it stuff just to see if there's anything we can really do See I'll discard that Am I still recording? Okay, I Want to make sure that I actually still have audio before I do this. Let's try that. I'm just gonna pause this Okay, we're good. I still have audio. I've done that before I've like started to record an entire video And I've been like I've put it like 20 minutes or 20 seconds 20 seconds now Like 10 minutes or 20 minutes into a whole like programming thing and I turned out wasn't even recording sound so All right, let's start like a level 16 a dot pi file And I'll try and amp this up so you can see it It's out of shebang line Because for some reason I can't get file header do that for me anymore and let's open up this image let's get image and And That's really all we need for now Image can equal image dot open and the file name is a Mozart dot gif right and let's close that image And let's get just get the dimensions of it because I'm sure we're gonna have to like actually loop through it I want to actually open it up in another window Don't look at my home directory. I got a bunch of weird stuff in there. Oh No, I'm the completely wrong thing Where did my image go? Did it just go away? Was it hidden? All right, now we have the image that we can just fire up. I also had in the web browser, which I guess I could have done Sorry guys. I'm off to a slow start today. Let's get the size. Let's get the like width and height out of this image and Since this is a gif right if I actually print out the image info you can see clearly This is a gif so it's gonna be a little bit harder to like process images and like process colors out of it We can't like loop through it and get the data that easily. So Let's try let's try to do that that that row separation thing I'm gonna do that for why in range of height So I'm just going like line by line here by rows and I'm gonna set up a box crop box These are just gonna have to be the dimensions because if I actually get the documentation up for Python image Crop that actually needs a box and the box has to be a tuple defining the left upper right and lower pixel coordinates So we'll start with zero being the left Y being the Upper right being the whole width of the image and then the lower pixel coordinate Will be y plus one because we're just gonna go just grabbing like a line for it So row can equal image dot crop Pass in our crop box And I'll just do this for the first line just so you can see what I'm doing actually Now I'll do row shows and that's gonna be an image and I'll run this and you totally can't see that So this is like the whole row the whole first row just expanded out a bunch I don't know how well you can see that. Whoa. That was a weird thing that I did I don't know if you can see that at all regardless You can actually get the like the text out of it. We're gonna do row Dot two string since this is not Like a PNG or anything. We can't easily get colors out of it So this will be okay Obviously a bunch of jazz that we can't see in sublime text until we make it representative of the whole string And now we just have a bunch of like escape sequences that totally represent the data Now we just have to figure out if we're trying to find that Position. Oh jeez in the image where we actually have that like Pink and purple Indicator like that offset indicator. We're gonna want to be able to grab that position, right? So let's do that We have to find what it actually is though first. So since we have this in our String variable. It's actually fine and we can work with it like a string We just got the index like a string if we just treat it as a string. So let's say Row string can equal obviously the row two string and now for I'm just gonna loop through this so we can get like sequential characters It's just kind of like a quick Cheap hacky way to find out what the character might be so for I in range of Roast length of row string right because we're looping through it and I just want to be able to use it I want to be able to have I as a number not like for character in row string I'm gonna use I so I can index the sequential like the characters that follow This is gonna get me an error But it's just for like a little hack to find out what character is repeated because obviously we know that That offset indicator that like color that purple color is gonna be repeated Since it's a little bit wider than all the other things so character Equals string I Row string I sorry and if Character is equal to Row string I Plus one so we know it's the same thing as a sequential character and plus two and Plus three so we're just like looking forward to see hey Is this character repeated if it is what we can do is we'll just print out the representation of that character Just so we get the raw bite of it And it's gonna give me an error once I run this I know that for flak But it's still gonna give us it's still gonna find the pixel for us right yeah Yeah, so we get an error as expected, but we see that xc3 is repeated That's the one that's being repeated And we get the error because we're probably just gonna get out of range after once we hit the end of the row That's fine. We now know that this like pixel right here that character When you look at that pixel as all characters that is our offset indicator now that we've grabbed that we should be able to just find Where that offset is right? so I'm gonna remove this row dot show line and this finds us our offset indicator We'll comment that out because we don't need it anymore But now we can find our offset to equal row underscore string Thought index because we want to find where that actually happens that's offset indicator That's gonna be the purple thing right? But it looks like these all start at a white character that happens right before it so I'm just actually gonna Subtract one from that offset indicator Just so we know that's where it is Now we can actually take this offset and wrap around our whole row with it And I can do that with the image ops image channel ops are in Python image chops module offset Is what we want to be looking at? Try and find it for us So offset will return a copy of the image where data has been offset by the given distances So since we just found our offset indicator and where that offset is What we can do is we can just shift it over to like where the position of that Pink thing is so it will essentially align them for us wherever we want them to the data will wrap around the edges And it says if the y offset is emitted and sort seem to be equal to x offset That's what we're gonna do since we're just gonna pass in our original offset and Have it assume that hey, we want to remove x we'll do this for our row. We can just say row equals I Gotta actually import that module Import image chops And we can say row equals image chops dot offset What does it need it needs the image which would be row in this case and it needs the offset Which would be the offset that we just found cool So now we have that row shifted, right? But now we actually have to put that on our image that we're working with and we can do that since we've cropped the thing We do that real easily since we've cropped it With I think it's image paste Python image Till I just want to find the Documentation for it Paste is that is it? Yeah, yeah, yeah paste another image into this image the box argument box is what we just have because we cropped it, right? Yeah Box everything is a tuple or for tuple so we can just pass in that crop box that we just sent So we'll know where to actually put it so we do image dot paste our current row that we're looking at and where it has Been cropped to you with crop box so Now that we're done with just this single row we can image show this and I'll hopefully if I display it out. Oh No, it's not working. We're not getting it over there Do you guys see why that is? If you think about it this offset is actually like a positive number obviously So when we shift that by that offset, it's in pushing it forwards pushing it to the right but since the Pixel since our row indicator that purple line thing is already At the I want to find it. I want to find where that image is cutting it Gonna open it again code Python challenge 11 since It was already so far to the right. We have to move it to the left So we actually have to pass in our offset as a negative number so it'll subtract from its current position, right? Let's do that. Let's do row to offset now when I run this you can see Just barely I can't really zoom in on this like oh god image magic does not like control plus Just barely hopefully you can see that it has been shifted to the right all the way to the left Sorry all the way to the left so it's at the front position in our image. Let's do that For every single Row, I'm just doing it right now, which is the first one But if we were to do that I wonder since it'll align all of them. I wonder what will give us I'm not gonna do image.show for each iteration. I'm gonna bring it at that at the very end And let's see control beat Whoa, there it is Romance. Oh, that's totally it romance is totally the next little flag or whatever we can use to get to the next level That's cool. Look at that. It just ran through every single row and a line just at the beginning where That like indicator is that that purple box thing Try and display it again Can I zoom out here? Yeah, look at this every single purple thing was just moved to the left corner We've aligned them all and we get romance as our as our output With all those like lighter color lines being put in the right position. That's cool. I Want to I want to play with that a little more honestly I want to make a jiff out of like because what it's doing is it's doing this line by line, right? Let's I'm totally making a jiff of this. Let's do that import sub process because I'm gonna call image magic I'm gonna have image magic. Just take all frames of this. Let's actually take a frame number And Let's do frame plus equals one Just so we're adding a frame and then I'll save the current image as Frame zero plus the string the current frame we're on and let's just make it a dot jiff How do I and then we could just use Python to like make that into a jiff Python jiff programmatically this thing this thing I Just saw this a little bit earlier some guy just like took an image magic line So he's calling it from the command line And we can use print sub process. This probably isn't gonna give us any output since it's just calling a Check outputs. It's just calling a check up a thing And I want to have no delay and I want the frames to be frames anything dot jiff Animated jiff and some sub process wants this as an array let's just split it by each space character and And then we should totally have a jiff at the very end Sweet, let's try and run this. It's probably gonna take a little bit. Oh sub string not found. What is that? What went wrong? What went wrong? Okay, after a little more testing I did a little a little bit of thinking and for some reason it breaks when I'm saving it as a jiff, so I'm just gonna save it as a PNG and Change it to little takes PNG files as well Also, just gonna take that string and Z fillets just in case We have a little bit more than zero to it just so it's all in the proper order So I don't we don't need that trailing zero All right, so now hopefully we can run this it's gonna take a little bit It's gonna take a long little bit Because it's just savoring every individual frame and then creating an animated jiff with it But once we see our picture show up since we get the final romance thing hopefully it will look good. Oh God dang. I suck. What's going on? Frames, oh Is it because I removed that zero? Frames Dang it. I forgot an S. Control B run it again. I'm off my game today guys. I'm sorry If I don't challenge is hard though, so I've been taking me so long to record this stuff because like I gotta figure out What's going on too? Hopefully no errors this time No errors. Yeah, cool. All right, we get our image now If I drag over my folder, it's literally filled with all these frames if I open up the animated version It's gonna take a little bit to load because there's so much stuff to it. I'll make it full screen and Oh, look at it. Look at it. Just pile those frames on that's pretty cool. Just unravels That's how you seduce the computer right there Unscramble bits get romance to appear Cool All right, thanks for watching guys. That's got us our new Python challenge thing. So let's hop over to your Python challenge calm for this PC for such a turn Romance dot HTML and here we are. What is this? All right, that's what's next everyone Cookies and weird stuff, but thanks for watching. Hope you guys enjoy this one I know it's been a while since I've done some of Python challenge, but We're moving along See you soon everybody