Seu objetivo é simples: o programa deve tornar a tela do seu computador totalmente preta .
Depois que o programa é iniciado, a tela deve rapidamente ficar completamente preta e permanecer até que o programa seja encerrado (qualquer tecla ou alt + F4, movimento do mouse etc.), após o qual as coisas devem voltar ao normal. Portanto, NÃO é permitido desligar o computador ou desligar o monitor . Nem um único pixel não preto deve estar visível durante esse período, nem mesmo um cursor piscando.
O usuário não deve fazer nenhuma preparação (mover o mouse para fora da tela, desconectar os cabos etc. ou a entrada do usuário após o início do programa), basta iniciar o programa.
Você pode assumir com segurança que o computador possui apenas um monitor conectado. Também assumimos um computador desktop ou notebook padrão, porque fazê-lo em um dispositivo específico sem um monitor normal seria muito simples.
Se você usar algum recurso externo (uma imagem em preto, um arquivo GUI etc.), o tamanho em bytes será adicionado ao tamanho do código.
Tudo bem se ele funciona apenas em uma família de sistemas operacionais, ou se requer opengl etc., mas é necessário desaprovar uma configuração de hardware muito específica.
Seu código fonte deve ser escrito em uma linguagem de programação, não apenas em um arquivo de configuração que algum outro programa (como um protetor de tela) usará.
Respostas:
Bash, 28 or 12
Assuming default installation of Ubuntu 12.04 LTS.
Automatically starts the screensaver, which is a black screen by default.
Edit: As suggested by @Glenn Randers-Pehrson, here's one with 12 bytes
Note that this may not work if you have another file on your system that satisfies this name, say
/tmp/1/gnd
. But it's code-golf, who cares?Check out my other bash answer if you don't use Gnome screensaver!
fonte
Assembly (bootloader) 131 chars / 512 bytes compiled (actually smaller, but bootsector must be 512 bytes long.)
It is a simple boot loader. When computer starts, BIOS will load it from disk (floppy). Then it enters into graphics mode and just hangs. When user presses the power button, program will end and computer will enter to mode where is was before running program.
Tested with VirtualBox.
It will compile with nasm:
Source code:
fonte
cli
andsti
? Moves toSS
automatically disable interrupts for the duration of the next instruction, andAX
won't be changed if an interrupt happens beforeMOV SS,AX
. Also, why notMOV AX, 0x13
instead of twoMOV
s?QBASIC (31)
fonte
Java : 165
Simple Java, just creates a fullscreen black frame. To exit you have to Alt+Tab back to the console and Ctrl-C, but that seems simple enough.
fonte
Applesoft ][ BASIC (17)
fonte
Bash - 57
26On a laptop this will set the screen backlight brightness to 0 via
/sys/class/backlight
, on a tablet or phone this will set the screen led brightness to 0 via/sys/class/leds
fonte
Fn+F6
,Fn+<up arrow>
and many other key combinations fall into "any key" and "etc.", and those are one of the many to put the light back as it was.find /sys/class/{backlight,leds}/*/
?I know this is code-golf but I couldn't resist.
Just make sure you don't have any browser windows open (in this case, Chrome);
Execute this PitchBlack.bat (
3124 bytes):If placed in the same directory of your Chrome.exe file, this batch will execute Chrome in kiosk mode and it will open a file called /1 (
494134 bytes) in fullscreen:Et voilà!
Total byte count:
807258Thanks to @ace :)
To exit the program, you must go for a classic ALT+F4; You don't actually have to do any preparation after the program starts (neither before, you just have to place
/1
and the batch file), so it's fine with the rules.Please note that if you get your cursor towards the screen borders, it may become visible. The OP didn't say this was not allowed, since
So this should be totally ok! :P
fonte
chrome --kiosk 'data:text/html,<style>body{background:#000;cursor:none;}</style>'
can work without additional file?file:
shceme you get no URL bar visible, but withdata:
scheme there is URL bar?chromium-browser --kiosk 'data:text/html,<style>body{background:#000;cursor:none;}</style>
starts almost-fullscreen Chromium with the black page without any bars.file:///1
if the html is saved as/1
, and the html file can be shortened to<body bgcolor=0 style=cursor:none>
chrome
in your answer rather thanchromium
C# -
211202200196179 bytesHides the cursor and shows a full-screen black window. Can be closed with Alt+F4
Un-golfed code:
I don't need to cast to
FormBorderStyle
, because that's not necessary if the integer is0
.fonte
System.Drawing.Color.Black
,FormWindowState.Maximized
,FormWindowState.Maximized
andFormBorderStyle.None
with their corresponding values.Color.Black
. It should work right away. OrBackColor=This.ForeColor
, which MIGHT work too.using System.Drawing;
, and the second doesn't work because I set the variable values inside brackets.using System;
thennew Windows.Forms.Form
andBackColor=Drawing.Color.Black
. It MIGHT work! And save a few bytes.C#
175171167A lot of the answers here don't actually make the screen black: on an LCD screen, the backlight remains on and bleeds through, leaving you with a darkish grey.
This little snippet actually tells Windows to turn off the screen, the same as what the inactivity timer does (Note: this doesn't violate the "no power off" rule because it really just causes the monitor to go into standby. Most monitors will turn back on when input is resumed. Also, that rule's intention seems to be to make sure the program can turn it back on - see below.)
Move the mouse or press a key to turn the screen back on.
Monitor power off adapted from https://stackoverflow.com/a/713519/1030702
fonte
Amiga assembly
ASM-One -
228219 chars, 172 bytes compiled (168 bytes optimized)It's been 20 years since I last coded a single line in Amiga assembly, so bear with me. :-)
The Amiga was a bit more involved than the PC in terms of setting up a blank screen, so tried to get rid of as much setup and teardown as possible. There's no disabling of interrupts or multitasking; no double WaitTOF; no view replacement; etc. I wouldn't even have written this for the quickest and dirtiest demo. Which means this:
... although it's been tested on emulated A500 and A1200, with or without fast memory. Compiles to a standard executable. Mouse click exits.
Less golfed:
fonte
Python / Pygame
19912712592Thanks to some tips from ace.
fonte
from pygame import*
instead. Also, I don't thinkfill((0,0,0))
is necessary since the default color is black. Then you can removes
altogether. I don't thinkdisplay.flip()
is needed either. Also, use one space for indentation instead of 4 can save you more spaces. Finally, instead ofFULLSCREEN
andKEYDOWN
, you can use their numeric values, namely-1<<31
(-2147483648) and2
respectively.TI-BASIC,
76Works both in the terminal (home screen) or as a program. Pressing
ON
or most other buttons returns to the terminal/home screen.fonte
Shade(Ymin,Ymax
.Commodore 64 (16 bytes)
It has been more than 20 years since I used Turbo Assembler, so I can only provide source for use in VICE's monitor. Assemble this at $032C and
save
[1] through $033B.Reset
andLOAD"PITCHDARK",8,1
. Hit good ol'Runstop+Restore
[2] to get back to normal.How does it work?
Here's the true source:
$032C is the kernal
CLALL
or "Close All Channels And Files" vector. As part of its cleanup, the BASICLOAD
command does aCLR
which in turn callsCLALL
. We replace theCLALL
vector with a pointer to our own routine immediately after the vector. We set the border to black and cover the screen with the border, and then callRESTOR
at $FF8A. The last vector replaced byRESTOR
isSAVE
at $0332-0333 which means the last 8 bytes are undisturbed. We then exit via the restoredCLALL
vector to continueLOAD
's execution.Thanks for this, it was fun trip down memory lane, relearning how to do an autorun program :)
[1] use save and not bsave so that load with ,1 works correctly
[2] Escape + PageUp in x64, probably.
fonte
sh/X11 on Arch Linux, 26
fonte
-set
for bothxbacklight = 0
andxbacklight + 7
.x=xbacklight;$x +0;read;$x +7
Bash, 37
Uses
unclutter
to hide the mouse pointer and a fullscreen session ofxterm
to black the screen. The cursor will reappear for a moment if you move it, but if you leave it alone the screen will be black until you press Ctrl+C.It will take a few seconds for the mouse cursor to disappear (as long as you don't move it). If this isn't fast enough, add the
-grab
option tounclutter
for an additional 6 chars.WARNING: this will leave a process of
unclutter
running even after you press Ctrl+C, usekillall unclutter
to stop it.Explanation
unclutter &
launchesunclutter
. The&
is there so we can get on with the next command instead of waiting for this one to terminate.xterm -fullscreen
launches XTerm, whose background is black by default.The
-e yes ''
option causes XTerm to runyes ''
, thereby printing the empty string forever. This serves to hide the terminal cursor, and also provides the Ctrl+C functionality.fonte
&
to save 2 bytes.Bash, 31 (or 52)
On a TTY, use the following script (assuming your default TTY background is black, which is true at least for Ubuntu 12.04 LTS):
Your TTY would still be fully functional even after using this script :)
If this isn't allowed, use the following (52 bytes):
And press Enter to terminate the script.
Special thanks to @nyuszika7h.
fonte
x='setterm -foreground';$x black;clear;read;$x white
(52 bytes).Processing, 113
I tried putting the code above onto draw() to save some bytes, but it didn't work. Press Alt-F4 to quit.
fonte
ZX Spectrum Basic (29 bytes)
Iterates over the screen, plotting black pixels which are automatically cleared when the program finishes.
The ZX Spectrum's edition of basic uses single bytes as commands and no newlines, if counting displayed characters you get 61 chars.
fonte
Lua + LÖVE (50)
Both functions are supposed to take a boolean argument, yet this works.
fonte
QBasic, 9 bytes
CLS
clears the screen,SLEEP
without any arguments holds execution until a key is pressed.fonte
SmileBASIC, 15 bytes
Pressing START or SELECT will end the program.
XSCREEN 4
sets the display mode to show a 320*480 image spanning both screens. This should clear everything, so anACLS
is not required.EXEC.
makes the code repeat by constantly running the program in slot 0. I wasn't able to doXSCREEN 4EXEC.
because you can't have a number directly beforeE
fonte
Sinclair BASIC - 28 chars
The thing about Sinclair BASIC was each keyword had it's own character code (taking up one byte), so this would actually take up 13 bytes including spaces.
fonte
:NEW
) as the commands are single bytes rather than a collection of characters.SmileBASIC, 23 bytes
Runs forever until the program is force-killed with START or SELECT. This makes both screens completely black, going so far to disable 3D (thus turning off the 3D LED on o3DS.)
fonte
Most POSIX compatible shells (at least
bash
andzsh
), 21Needs to be run on a tty
First command hides the cursor, second command clears the screen (duh) and third command reads a line of text
fonte
BASH - 14 chars
pmset sleepnow
does the job!(typed into my Mac's Terminal)
fonte
Bash: 48 characters
CW because not clear whether it qualifies due to the way it works:
(Note that DP1 is the first connected display. If you have a laptop, its embedded display is eDP1.)
fonte
HTML Application (.hta), 102 bytes
fonte
TI-80 BASIC, 5 bytes
fonte
Chip-8, 0 bytes
Source: http://laurencescotford.co.uk/?p=75
fonte