Code Golf:1x1 黑色像素
最近,我使用我最喜欢的图像编辑器制作了一个 1x1 黑色像素(当您想以便宜的方式在 HTML 中绘制实心框时,它可以派上用场)。尽管我将其设为单色 PNG,但结果却是 120 字节!我的意思是,这有点陡峭。 120 字节。 一个像素。然后我将其转换为 GIF,大小降至 43 字节。好多了,但仍然...
挑战
是或生成 1x1 黑色像素的最短图像文件或程序。提交内容可以是:
- 代表 1x1 黑色像素的图像文件。所选格式必须能够表示大于 1x1 的图像,并且不能是临时的(也就是说,它不能是您刚刚为代码高尔夫编写的图像格式)。图像文件将按字节数排名。
- 生成此类图像文件的程序。程序将按照字符数进行排名,就像代码高尔夫中常见的那样。
只要答案属于这两个类别之一,任何事情都是公平的。
另外,对于图像文件,请以十六进制或转义符指定它们,而不是使用外部图像主机:-)
Recently, I used my favorite image editor to make a 1x1 black pixel (which can come in handy when you want to draw solid boxes in HTML cheaply). Even though I made it a monochrome PNG, it came out to be 120 bytes! I mean, that's kind of steep. 120 bytes. For one pixel. I then converted it to a GIF, which dropped the size down to 43 bytes. Much better, but still...
Challenge
The shortest image file or program that is or generates a 1x1 black pixel. A submission may be:
- An image file that represents a 1x1 black pixel. The format chosen must be able to represent larger images than 1x1, and cannot be ad-hoc (that is, it can't be an image format you just made up for code golf). Image files will be ranked by byte count.
- A program that generates such an image file. Programs will be ranked by character count, as usual in code golf.
As long as an answer falls into one of these two categories, anything is fair game.
Also, for image files, please specify them in hexadecimal or escapes rather than using an external image host :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(17)
DrRacket:23 个字符
DrRacket: 23 chars
我参加这个聚会已经很晚了,但是 http://www.perlmonks.org/?node_id= 7974 有一个比迄今为止任何人发布的更通用的答案:
I'm pretty late to this party, but http://www.perlmonks.org/?node_id=7974 has a more general answer than anyone's posted so far:
XPM,57字节:
查找要链接的维基百科文章时我找到了XPM2,26字节,但我无法用这里的任何程序打开它。
XPM, 57 bytes:
When looking for the wikipedia article to link it I found XPM2, 26 bytes, but I could not open that with any program here.
Rebmu:16个字符
如果您希望它根据您传入的参数保存到文件中,则添加程序中还有三个字符:
该程序是以下 Rebol 的简写,为了清楚起见添加了括号:
Rebmu: 16 chars
If you want it to save to a file based on an argument you pass in, that adds three more chars to the program:
The program is shorthand for the following Rebol, parentheses added for clarity:
但定位需要更多。
But positioning it will take more.
数据 URI,83 个字符
Data URI, 83 characters
图像文件:10 字节,采用 PGM 格式
:用 Python 创建:40 个字符
Image file: 10 bytes, in PGM format:
To create it, in Python: 40 characters
Unicode 艺术 格式:
·
Unicode art format:
·
WBMP,5 字节:
无法想象更小的尺寸
WBMP, 5 bytes:
Can't imagine anything smaller
PBM 格式是一种黑白图形格式。
单个黑色像素的二进制表示需要 8 个字节,用 C# 将其写入文件将如下所示:
The PBM format is a black and white graphics format.
A binary representation of a single black pixel would take 8 bytes, and writing it to a file with C# would look like:
Logo / Turtle basic,12 字节
PENDOWN FD 1
我不记得
pendown
是否可以缩短为pd
,如果可以的话,那将其减少到 7 个字节。Logo / Turtle basic, 12 bytes
PENDOWN FD 1
I can't remember if
pendown
can be shortened topd
or not, if so, that drops it to 7 bytes.bash: 31 个字符
从互联网下载单个像素 gif 的脚本比单个像素本身的字节数少......
bash: 31 chars
The script to download a single pixel gif from the interwebs is fewer bytes than the single pixel itself...
Python+PIL 68 个字符
Python+PIL 68 chars
后记,29 字节。并不是真正的“单个像素”,但它是我的预览屏幕上的单个像素。
Postscript, 29 bytes. not really a "single pixel", but it was a single pixel on my preview screen.
Python(带 PIL)(85 个字符):
Python (w/ PIL) (85 chars):
我曾经使用的旧图像格式: 4 字节
该格式由 16 位整数数组(小端)组成:
位映射:
控制位值:
An old image format I used to use: 4 bytes
The format consists of an array of 16 bit integers (little endian):
Bit mapping:
Control bits values:
SVG,59 个字符:
不幸的是,包括 Doctype 它增长到 157 个...:
SVG, 59 characters:
Unfortuntally, including Doctype it grows to 157...: