17
6
This is a quine variation.
Introduction
We all write short code, because some obscure reasons, but whatever we do, the'll take up at least 144 pixels/byte (with a 12px font). But what would happen, if we would encode our code in images? This is your task today.
Challenge
You task is to read in your own source code (non-proper quines are allowed, e.g. literally reading the source file), and create an image out of it, by setting the red, green and blue components of a pixel based on the ASCII value of the character.
Example:
We have the string "Hello world!"
Hello world!
Let's convert this to ASCII values:
72 101 108 108 111 32 119 111 114 108 100 33
Map the RGB values to it (If the source code's length is not divisible by 3, use 0s as the remaining characters):
__________________________________________________
| R | G | B || R | G | B || R | G | B || R | G | B |
----------------------------------------------------
|72 |101|108||108|111|32 ||119|111|114||108|100|33 |
----------------------------------------------------
We then create the image with the smallest area out of it. We have 4 sets of RGB values, so the smallest image will be a 2*2 image, going from the top left pixel to the right:
And we get this awfully colored image (resized, so it's at least visible, also proves the fact how small it can get)
Rules/Additional information
- There's no input
- The output should be as a separate file, or in a separate window.
- For multibyte characters, split the character in 2 bytes.
- The source code must be at least 1 byte long
- The image should be the one from the possible sizes, wich has the closest width/height ratio to 1
- The pixel count on the image should exactly be ceil(byte count / 3), no extra pixels should be added
Scoring
This is a code-golf, so the smallest answer in bytes wins.
7Waiting for a Piet submission... :P – Rɪᴋᴇʀ – 2016-05-17T14:38:34.593
3What is "the smallest image"? Smallest area? Wouldn't this always be a straight line? Does the image have to be square? If so, how do we pad pixels that don't fit in the square? Could you provide some sample solutions? (Not necessarily with source code, just any string) – James – 2016-05-17T15:26:30.507
@DrGreenEggsandHamDJ Added an extra rule – Bálint – 2016-05-17T16:17:19.847
2Still not super clear. Which is more important, smallest area, or smallest width to heighth ratio? What if it was three, or any other prime number of pixels? Should I do 1x3 (smallest area) or 2x2 with a pixel missing (smallest ratio)? What should that missing pixel be? – James – 2016-05-17T16:22:15.083
3Was this on the sandbox? It seems like it could've used some time there. – Morgan Thrapp – 2016-05-17T16:38:52.197
1Isn't the smallest width/height ratio technically going to always be
height = N
andwidth = 1
? I think you mean width/height closest to 1. – Suever – 2016-05-17T17:37:22.430@Suever added that too – Bálint – 2016-05-17T17:59:19.483
1
Well, the ambiguity is gone, my only thought is that it's a little bit of a chameleon challenge. The challenge is about encoding ASCII into an image, but now we also have worry about finding which set of factors is closest together. You don't have to change it, just something to think about for your next challenge.
– James – 2016-05-17T19:09:10.473@DrGreenEggsAndHamDJ I know, but as that part is hard-codable, I didn't thought it will be a problem. – Bálint – 2016-05-17T20:36:36.587
ceil(byte count / 3)
- ceil or byte length have to be divadable by 3? – Qwertiy – 2016-05-17T22:12:04.957@Suever I think I stated that – Bálint – 2016-05-18T05:15:44.683
@Qwertiy No, it doesn't – Bálint – 2016-05-18T05:16:45.217
@EᴀsᴛᴇʀʟʏIʀᴋ It's inspired by piet. – Bálint – 2016-05-18T08:58:17.813
The bit about multibyte characters could be better stated as "use the raw bytes of your program's source code in the code's text encoding". Specifying 2 bytes doesn't cover the characters in UTF-8 that span 3 or 4 bytes. – Mego – 2016-05-18T22:16:36.650
Why not allow the image file contents to be printed to stdout? – Mego – 2016-05-19T14:36:15.160
@Mego Because that's not what I originally wanted – Bálint – 2016-05-19T17:26:21.023
That would be the same as "print out the ascii values of your code" – Bálint – 2016-05-19T17:26:53.760
@Bálint And saving it to a file is different somehow? – Mego – 2016-05-19T23:26:41.197
@Mego Then you actually need to construct an image. – Bálint – 2016-05-20T05:33:37.430
@Bálint Submissions can still "construct an image" without needing to save it to a file or display it - outputting the image file contents to STDOUT is accepted by default. You override this default for no good reason. Additionally, the existence of the PPM (P6) image file format completely trivializes this challenge - a solution must simply prepend the image header
P6 W H 255
to its own source code. – Mego – 2016-05-20T05:38:27.840@Bálint Why is the Actually answer still accepted when it fails to fulfil one of your requirements? The output should be as a separate file, or in a separate window. – Adám – 2017-05-03T00:26:50.490