HOME | DD
Published: 2019-07-07 20:03:01 +0000 UTC; Views: 244; Favourites: 0; Downloads: 1
Redirect to original
Description
User smawzyuw2 posted a programming request: A Request for a ProgrammerHere's my third attempt (this time in Python). Did it the hard way, by writing individual bytes to a bitmap file. As such, the result is mirrored vertically (because bitmaps store the pixels from bottom to top for some reason).
Script and renders are in the zip in the download. (Warning: The contents of the zip file (uncompressed) are about 2.6 GB.) Here's what the script looks like:
width = 27720
height = 27720
f = open("pattern.bmp","w") # make a new bitmap file (24 bits per pixel)
# write bitmap file header
f.write("BM")
f.write(chr(((width*height)+54)&0xFF)+chr((((width*height)+54)>>8)&0xFF)+chr((((width*height)+54)>>16)&0xFF)+chr((((width*height)+54)>>24)&0xFF)) # file size
f.write(chr(0x00)+chr(0x00))
f.write(chr(0x00)+chr(0x00))
f.write(chr(0x36)+chr(0x00)+chr(0x00)+chr(0x00))
# write DIB header
f.write(chr(0x28)+chr(0x00)+chr(0x00)+chr(0x00))
f.write(chr((width)&0xFF)+chr(((width)>>8)&0xFF)+chr(((width)>>16)&0xFF)+chr(((width)>>24)&0xFF)) # width
f.write(chr((height)&0xFF)+chr(((height)>>8)&0xFF)+chr(((height)>>16)&0xFF)+chr(((height)>>24)&0xFF)) # height
f.write(chr(0x01)+chr(0x00))
f.write(chr(0x18)+chr(0x00))
f.write(chr(0x00)+chr(0x00)+chr(0x00)+chr(0x00))
f.write(chr((width*height)&0xFF)+chr(((width*height)>>8)&0xFF)+chr(((width*height)>>16)&0xFF)+chr(((width*height)>>24)&0xFF)) # image data size
f.write(chr(0x013)+chr(0x0B)+chr(0x00)+chr(0x00))
f.write(chr(0x013)+chr(0x0B)+chr(0x00)+chr(0x00))
f.write(chr(0x00)+chr(0x00)+chr(0x00)+chr(0x00))
f.write(chr(0x00)+chr(0x00)+chr(0x00)+chr(0x00))
# write image data
y = 1
x = 1
while y<=height:
if (x%y)==0:
f.write(chr(0xFF)+chr(0xFF)+chr(0xFF)) # write white pixel
else:
f.write(chr(0x00)+chr(0x00)+chr(0x00)) # write black pixel
x += 1
if x>width:
r = (width*3)%4
while r>0:
f.write(chr(0x00)) # write padding byte
r -= 1
x = 1
y += 1
f.close() # close the file
Took about 10 minutes (on iMac with 3.3GHz i5 processor) to render the 27720 x 27720 image.
edit - It seems my script only works reliably when the dimensions are a multiple of 12. Guess I messed something up with the padding. Oh well.
Related content
Comments: 5
smawzyuw2 [2019-07-08 01:22:14 +0000 UTC]
How do I open the image? When I click on it to open it, it says that it's not a valid bmp file or the format is not currently supported
👍: 0 ⏩: 1
razalcat34 In reply to smawzyuw2 [2019-07-08 10:07:47 +0000 UTC]
No idea... it might have something to do with the image editor your using. But it opened without a problem on the Mac I was using yesterday. I'll try converting it to PNG a little later (can't do it right now...)
As for why I took the request... I don't know... I came across it in a search (searching for math stuff) and it looked like a fun challenge, not too difficult. The pattern seemed pretty interesting too (I think I'd heard about that pattern before somewhere, but I never really checked it out... or maybe it wasn't that same pattern but something similar. Do you happen to know whether this particular pattern has a name?)
👍: 0 ⏩: 1
smawzyuw2 In reply to razalcat34 [2019-07-08 15:58:48 +0000 UTC]
I've never heard of a name for it before. It's a pattern I thought up of in high school years ago. I tried looking it up online to see it was given a name but I couldn't find anything on the pattern.
👍: 0 ⏩: 1
razalcat34 In reply to smawzyuw2 [2019-07-08 16:18:51 +0000 UTC]
Ok, I've converted the BMP to PNG. Here: Pattern (high res) (in the download). If that still doesn't work, I don't know what to tell you.
👍: 0 ⏩: 0
smawzyuw2 [2019-07-08 00:46:35 +0000 UTC]
Thank you! I'm wondering why you decided to take my request. And how you even found that request.
👍: 0 ⏩: 0
























