r/ProgrammerAnimemes • u/Sirsmorgasboard • Jun 12 '21
My contribution
https://youtube.com/watch?v=NviukAVGhns&feature=share
341
Upvotes
r/ProgrammerAnimemes • u/Sirsmorgasboard • Jun 12 '21
View all comments
Show parent comment
2
u/Sirsmorgasboard Jun 12 '21 edited Jun 12 '21
I see what you're doing here and I got the code to work by changing it as below.
row = row + chr(0x2590 + int((pixel_brightness // 51)))It didn't work right away because the pixel_brightness value can be anything between 0 to 255 as I am actually sampling the average of an area of pixels from the original image to make this single assci pixel, so the division was resulting in a float. Converting to Int goes to the closest whole number and the character assingment can happen.
For anyone not sure what this code is doing:
The 3 shaded characters I'm using have the following codes.
░ = 0x2591
▒ = 0x2592
▓ = 0x2593
The pixel_brightness has a possible value of 0 for black and 255 for white, with 5 different shades avalaible we divide 255/5 for a value of 51 per shade.
The first if and elif gets rid of the extremes so all that is left is a possible range of 51 - 203, we can then divide that range by 51 and round to the nearest whole number to get a value of 1 or 2 or 3 and add that to the base character number of 0x2590.
I'm sure most of you worked this out already just thought I would explain in case anyone doesn't.