Create a bad pixel

41

3

Your task is to write a program that makes your screen appear to have a bad pixel.

You should choose exactly one pixel on the screen, and exactly one channel between red, green and blue, and make its value either always 0 or always maximum (usually 255). The values of other channels should be the same as if your program didn't run.

You can choose the pixel and channel in whatever ways, such as hardcoding it or generate it randomly on each run. But it must always be visible on fairly modern hardwares.

If the color that originally should be displayed on that pixel has changed, your program should update in less than 0.5 seconds when the system is fast enough.

You cannot make assumptions about what is currently displayed on the screen (such as a taskbar using the default theme).

Your program doesn't need to work when a screensaver, login screen, effect from a window manager, etc, are active.

Shortest code wins.

jimmy23013

Posted 2016-12-11T14:20:44.000

Reputation: 34 042

1Can we assume a specific OS? – Loovjo – 2016-12-11T15:01:23.740

@Loovjo Yes, you can. – jimmy23013 – 2016-12-11T16:00:07.463

Ow... the requirement to preserve the other channels probably doubles my already-ridiculous byte count. – Bob – 2016-12-12T03:41:20.323

Answers

21

Bash on Linux - 25 bytes of Latin-1

+3 from @wyldstallyns / -2 from removing quotes / -1 because I forgot how this works / -9 from @Dennis

printf ÿ>/dev/fb0;exec $0

Assumes that /dev/fb0 exists (it does on my Arch Linux system, and I think it should on any other Linux system). Requires root access as well. This does not work for me when X is running. On my system, this just constantly sets the blue channel of the top-left pixel to full (ÿ is 255).

artificialnull

Posted 2016-12-11T14:20:44.000

Reputation: 481

You need echo -n - otherwise this could golf to: yes ff>/dev/fb0 – wyldstallyns – 2016-12-11T18:01:49.543

@wyldstallyns Yeah, I've fixed it accordingly. AFAIK, printing the newline would influence more than one pixel (not allowed by challenge description) – artificialnull – 2016-12-11T18:08:18.483

Use /*/fb0 and insist haters produce a non-contrived example of side effects. – wyldstallyns – 2016-12-11T18:18:36.630

1How is ÿ 255? I don't think this works. 255 is not a valid unicode character, it's not ascii either, so it must rely on one of those ancient codepages that shouldn't ever be used, as they differ from machine to machine. – orion – 2016-12-11T19:51:17.223

@orion Portability is not a concern in code golf. As long as it reproducably works on one machine, it's valid. – Dennis – 2016-12-11T19:57:56.220

@wyldstallyns it can still be golfed to yes <character>|tr -d '\n'>/*/fb0, or just using /dev/zero. – orion – 2016-12-11T19:58:07.107

1printf ÿ>/dev/fb0;exec $0 saves a few bytes. – Dennis – 2016-12-11T19:59:04.983

3@orion The yes approach doesn't work. /dev/fb0 has to be reopened after writing one pixel channel. – Dennis – 2016-12-11T20:04:22.893

Oh, right, otherwise it would just blank the entire buffer. – orion – 2016-12-11T20:07:13.513

@wyldstallyns /home/fb0 isn't that contrived. It probably exists as a username somewhere. – None – 2016-12-12T02:44:50.490

@ais523 That would just send an extraneous "Is a directory" message to sterr. – wyldstallyns – 2016-12-12T02:49:08.387

@wyldstallyns no, it would output "bash: /*/fb0: ambiguous redirect" and not run the printf. – Muzer – 2016-12-12T17:27:18.313

@ais523 Sorry, I was talking about a prior version that used yes – wyldstallyns – 2016-12-12T17:32:47.247

$0&printf ÿ>/dev/fb0. Saves a few bytes. I'm not sure how reliable it is though. – jimmy23013 – 2016-12-23T14:27:18.350

11

Visual C++, 102 100 99 98 bytes

#include<Windows.h>
int main(){for(HDC d=GetDC(0);;Sleep(99))SetPixel(d,9,9,GetPixel(d,9,9)|255);}

Runs on Windows, directly using the Win32 API with Visual C++ compiler targeting the console subsystem. Uses the "screen" device context to set the red channel of the pixel at (9,9) to 0xFF.

The sleep is necessary to allow other programs to draw in between the get/set - and 9ms was too short, leading to the pixel getting stuck1 on its initial colour.


1 Unfortunately, not quite the same type of stuck pixel this question is looking for...

Bob

Posted 2016-12-11T14:20:44.000

Reputation: 844

8

HolyC, 13 bytes

GrPlot(,9,9);

Puts a black dot on the persistent layer directly.

Layers

What it looks like.

Screenshot

m4kefile

Posted 2016-12-11T14:20:44.000

Reputation: 81

6

C#, 247 244 371 366 354 352 bytes

Runs on Windows. Gets a device context for the entire screen, and repeatedly maximises the red channel at (9,9).

namespace System.Runtime.InteropServices{using I=IntPtr;class P{[DllImport("User32")]static extern I GetDC(I h);[DllImport("Gdi32")]static extern int GetPixel(I h,int x,int y);[DllImport("Gdi32")]static extern int SetPixel(I h,int x,int y,int c);static void Main(){for(I d=GetDC((I)0);;Threading.Thread.Sleep(99))SetPixel(d,9,9,GetPixel(d,9,9)|255);}}}

I originally didn't want to import GetPixel/SetPixel, but there's no particularly easy way to read a single pixel off a Graphic. So right now this is effectively the same as my VC++ attempt. Maybe saving to bitmap will be shorter...


-5 bytes thanks to @TuukkaX

Bob

Posted 2016-12-11T14:20:44.000

Reputation: 844

1You can remove the whitespaces from the parameter list of SetPixel. – Yytsi – 2016-12-12T05:41:35.140

@TuukkaX Thanks! Missed those. – Bob – 2016-12-12T06:14:21.290

You can make it sleep for 9ms rather than 99ms – Rob – 2016-12-12T06:18:26.710

2@Rob I tried that, as mentioned in the C++ answer. Unfortunately, 9ms didn't seem to be enough when I tested (Win7). Other programs did not have enough time to paint, so the pixel effectively got stuck on its initial colour. – Bob – 2016-12-12T06:25:47.500

Could also shorten it by running through about 0x1FFFFFFF iterations in a busy loop instead of the sleep, but this would have to be tuned for every machine to stay within the 0.5s limit. – Bob – 2016-12-12T06:43:09.050

3

SmileBASIC, 20 bytes

SPSET.,299,99,1,1,33

Updates constantly.
Sets sprite 0 to a 1x1 area at 299,99 on the sprite sheet (which is a red pixel).
33 is the display attribute, which is 1 (display on) + 32 (additive blending).

12Me21

Posted 2016-12-11T14:20:44.000

Reputation: 6 110

0

Java 7, 266 bytes

import java.awt.*;public class K extends java.applet.Applet{public static void main(String[]a){new K();}Label l=new Label(".");public K(){add(l);}public void paint(Graphics g){s(Color.red);s(Color.green);s(Color.blue);repaint();}void s(Color c){l.setForeground(c);}}

I ran this on windows 7. Opens a Java Applet which has a white background by default. Adds a label with a period and then changes the color of the label ad nauseum.

Poke

Posted 2016-12-11T14:20:44.000

Reputation: 3 075

3Not actually sure if this is valid since it only changes the pixel in the applet window. Won't change the pixel color if the applet loses focus... I'll delete this answer if it doesn't meet the challenge's criteria. – Poke – 2016-12-12T20:57:16.820

0

Tcl/Tk, 61

wm at . -tr #F0F0F0
wm o . 1
grid [canvas .c]
.c cr o 9 9 9 9

On the image there is a black pixel near the upper left corner of the Vivaldi icon: badpixel


If on an interactive shell, there are abbreviations of commands available:

Tcl/Tk, 57

wm at . -tr #F0F0F0
wm o . 1
gri [can .c]
.c cr o 9 9 9 9

There is a black pixel over the V white area of the Vivaldi icon: badpixel

sergiol

Posted 2016-12-11T14:20:44.000

Reputation: 3 055