Code Golf: 1x1 black pixel

限于喜欢 提交于 2019-12-02 21:08:43
Agos

WBMP, 5 bytes:

00 00 01 01 00

Can't imagine anything smaller

Data URI, 83 characters

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==

Image file: 10 bytes, in PGM format:

P5 1 1 1\n\0

To create it, in Python: 40 characters

 open('b.pgm', 'w').write('P5 1 1 1\n\0')

Unicode art format:

·

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:

File.WriteAllText("p.pbm", "P4 1 1 ÿ");

Logo / Turtle basic, 12 bytes

PENDOWN FD 1

I can't remember if pendown can be shortened to pd or not, if so, that drops it to 7 bytes.

bash: 31 chars

The script to download a single pixel gif from the interwebs is fewer bytes than the single pixel itself...

wget http://tinyurl.com/2w97dyo

Python+PIL 68 chars

from PIL import Image
Image.fromstring("P",(1,1),"\0").save("B.gif")

Postscript, 29 bytes. not really a "single pixel", but it was a single pixel on my preview screen.

0 0 moveto .5 0 lineto stroke
Yuval Adam

Python (w/ PIL) (85 chars):

from PIL import Image
i=Image.new("P",(1,1))
i.putpixel((0,0),(0))
i.save("i.gif","GIF")

An old image format I used to use: 4 bytes

 01 00 00 0C

The format consists of an array of 16 bit integers (little endian):

Bit mapping:

0-10:  number of pixels to shade
10-11: control bits
12-15: VGA16 pidel color

Control bits values:

0: normal
1: end of line
3: end of file

SVG, 59 characters:

<svg><rect width="1" height="1" style="fill:#000;"/></svg>

Unfortuntally, including Doctype it grows to 157...:

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg><rect width="1" height="1" style="fill:#000;"/></svg>

DrRacket: 23 chars

#lang slideshow
(disk 1)

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:

## tinygif
## World's Smallest Gif
## 35 bytes, 43 if transparent

use strict;
my($RED,$GREEN,$BLUE,$GHOST,$CGI);

## Adjust the colors here, from 0-255
$RED   = 255;
$GREEN = 0;
$BLUE  = 0;

## Set $GHOST to 1 for a transparent gif, 0 for normal
$GHOST = 0;

## Set $CGI to 1 if writing to a web browser, 0 if not
$CGI = 0;

$CGI && printf "Content-Length: %d\nContent-Type: image/gif\n\n", 
  $GHOST?43:35;
printf "GIF89a\1\0\1\0%c\0\0%c%c%c\0\0\0%s,\0\0\0\0\1\0\1\0\0%c%c%c\1\0;",
  144,$RED,$GREEN,$BLUE,$GHOST?pack("c8",33,249,4,5,16,0,0,0):"",2,2,4;

XPM, 57 bytes:

/* XPM */
static char *_x_[] = {"1 1 1 1",".c #000","."}

When looking for the wikipedia article to link it I found XPM2, 26 bytes, but I could not open that with any program here.

! XPM2
1 1 1 1
. c #000
.

Rebmu: 16 chars

en'PNGmkIM![1x1]

If you want it to save to a file based on an argument you pass in, that adds three more chars to the program:

rebmu/args [wrAen'PNGmkIM![1x1]] %my-black-pixel.png

The program is shorthand for the following Rebol, parentheses added for clarity:

write a (encode 'png (make image! [1x1]))
<div style="height: 0; width: 1px; border-top: 1px solid #000">

But positioning it will take more.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!