I've always liked screens full of randomly colored pixels. They're interesting to look at and the programs that draw them are fun to watch.

The challenge

Fill your screen, or a graphical window, with colored pixels.

The rules

  • Your program must have an even chance of picking all colors (i.e in the range #000000 to #FFFFFF), or all colors that can be displayed on your system.
  • Your program must continue to display random pixels until manually stopped (it cannot terminate on its own).
  • Pixels can be any size, as long as your output has at least 40x40 "pixels".
  • Your program must run at such a speed that it can replace every pixel on the screen/window at least once after running for three minutes.
  • Your program must choose truly random colors and points to replace, i.e. random with all points/colors equally likely. It cannot just look random. It must use a pRNG or better, and the output cannot be the same every time.
  • Your program must have an equal chance of picking all colors each iteration.
  • Your program must replace only one pixel at once.
  • Your program cannot use the internet nor your filesystem (/dev/random and /dev/urandom excepted).

Example

Your output could look like this if stopped at a random time:

The winner

The shortest answer in each language wins. Have fun!

  • By "truly random", I assume pseudorandom is OK (like Math.random() or similar) – OldBunny2800 Jun 2 '17 at 1:29
  • @OldBunny2800 It must use a pRNG or better – TheLethalCoder Jun 2 '17 at 13:07
  • Since the program can't use the internet, I'll just leave this in a comment: babelia.libraryofbabel.info/slideshow.html – KSmarts Jun 2 '17 at 13:28
  • 1
    So does the "3 minute limit" apply to setup time, too? Or just once the "program" begins? Asking because I have a Minecraft redstone solution, which runs very quickly once it is going, but takes a while to set up initially (it has to "place" each "pixel" in the 40x40 grid) before it can start changing colors. – BradC Jun 4 '17 at 2:34
  • 5
    Truly random by definition exclude pseudo-random, yet doesn't define a distribution. I assume you mean a uniform PRNG, where all events are equiprobable and independent of each other. – Dennis Jun 4 '17 at 4:44

44 Answers 44

up vote 72 down vote accepted
+50

Minecraft 1.12 Redstone Command Blocks, 4,355 2,872 bytes

Minecraft screenshot with armor stands and map

(Size determined by saved structure block file size.)

Here is a full YouTube overview, but I'll try to outline the code below.

Setup Routine:

2 rows of command blocks for setup

This sets up the 40x40 grid of Minecraft armor stands. Armor stands are necessary because Minecraft has no way to substitute variables into world coordinates. So the workaround is to refer to the location of these armor stand entities.

(impulse) summon armor_stand 2 ~ 1 {CustomName:"A"} /create named armor stand
(chain) fill -2 ~ -2 43 ~ 43 stone                  /create big stone square
(chain) fill -1 ~ -1 42 ~ 42 air                    /leave just a ring of stone
(chain) setblock -4 ~ -12 redstone_block            /kicks off next sequence

This named armor stand is basically our "cursor" to place all the armor stands that we will need. The redstone block in the last step "powers" nearby blocks (including our command blocks), so kicks off the next loop:

(repeat) execute @e[name=A] ~ ~ ~ summon armor_stand ~-1 ~ ~   /create new armor stand 
(chain) tp @e[name=A] ~1 ~ ~                                   /move "cursor" one block
(chain) execute @e[name=A] ~ ~ ~ testforblock ~1 ~ ~ stone     /if at end of row,
(conditional) tp @e[name=A] ~-40 ~ ~1                          /go to start of next row
(chain) execute @e[name=A] ~ ~ ~ testforblock ~ ~ ~2 stone     /If at last row
(conditional) setblock ~6 ~ ~ air                              /stop looping
(conditional) kill @e[name=A]                                  /kill cursor

At this point our grid is complete:

Completed armor stand grid

Random Color Selector

Color and Pixel Selector

The purple repeaters in the center of this picture choose a random color via the following command:

(repeat) execute @r[type=armor_stand,r=9] ~ ~ ~ setblock ~ ~-2 ~ redstone_block

That "@r[]" is the magic sauce, it selects a random entity in the world that matches the given conditions. In this case, it finds an armor stand inside a radius of 9 blocks, and we've set up 16 armor stands, one for each wool color. Under the selected color, it places a redstone block (which powers the two command blocks on either side).

Random Pixel Selector

Placing the redstone block under the selected wool color triggers two more command blocks:

(impulse) execute @r[type=armor_stand] ~ ~ ~ setblock ~ ~3 ~ wool X
(impulse) setblock ~ ~ ~1 air

This first line uses our same magic @r command to choose any armor stand on the entire map (no radius restriction, so that includes the 40x40 grid), and places a wool of the selected color above its head. The X determines the color, and ranges from 0 to 15. The second command removes the redstone block so it is ready to go again.

I have 5 purple repeater blocks, and redstone works in "ticks" 20 times a second, so I'm placing 100 pixels per second (minus some color overlaps). I've timed it, and I usually get the entire grid covered in about 3 minutes.

This was fun, I'll try to look for other challenges that might also work in Minecraft. Huge thanks to lorgon111 for his YouTube Command Block tutorial series.

EDIT: Made some serious reductions in the size of the saved structure, now at 2,872 saved bytes:

closer command blocks with visible void blocks

  1. Scooted things in a bit (in all 3 dimensions) so I could reduce the overall size of the saved area.
  2. Changed the different colored wools to stone, they were just decorative anyway.
  3. Removed the glowstone lamp.
  4. Changed all air blocks to void blocks (the red squares).

Tested by pulling the saved structure into a new world, everything still works as designed.

EDIT 2: Read-only Dropbox link to the NBT structure file

Walk through is in my YouTube video, but here are the steps:

  1. In Minecraft 1.12, create a new creative superflat world using the "Redstone Ready" preset. Make it peaceful mode.
  2. Once the world exists, copy the NBT file into a new \structures folder you create under the current world save.
  3. Back in the game, do /give @p structure_block, and /tp @p -12, 56, -22 to jump to the right spot to get started.
  4. Dig a hole and place the structure block at -12, 55, -22.
  5. Right-click the structure block, click the mode button to switch it to "Load".
  6. Type in "random_pixels", turn "include entities" ON, and click "Load"
  7. If it finds the structure file, it will preview the outline. Right-click again and click "load" to bring the structure into the world.
  8. Press the button to run the setup routine.
  9. When it completes, flip the switch to run the wool randomization.
  • 5
    Holy crap... you actually did it. And it's your first answer, wow! Welcome to the site, and this is an amazing way to start! – MD XF Jun 5 '17 at 1:59
  • 2
    @MDXF In addition to your +10, I'm giving +60 – NoOneIsHere Jun 5 '17 at 2:03
  • 2
    @NoOneIsHere All right :P But if you have an answer, it'll have to be +100... – MD XF Jun 5 '17 at 2:05
  • 2
    I am going to try and golf this if you give the the world file (I will not post another answer but just give you the file) – Christopher Jun 7 '17 at 16:07
  • 2
    Well, shortest answer in each language wins and this is the shortest answer in Minecraft :P have an extra +15 – MD XF Jun 7 '17 at 16:43

sh + ffmpeg, 52 bytes

ffplay -f rawvideo -s cif -pix_fmt rgb24 /dev/random

Does ffmpeg count as an esolang? :D

Sadly the pix_fmt is required, as ffmpeg defaults to yuv420p. That fails the "must have equal likelihood of every possible pixel color" requirement. Conveniently, cif is a shortcut for a fairly large video size that uses less space than "40x40".

Unsurprisingly, optimizing this gif with gifsicle did absolutely nothing. It's 4MiB.

  • 3
    Does this "replace only one pixel at once"? – Scott Milner Jun 3 '17 at 21:08
  • 1
    Technically? ffmpeg will wait for the entire frame to be filled with pixels before displaying it, though. I misread "must only replace 1 pixel at a time" as "may". :/ – Una Jun 3 '17 at 23:42
  • 1
    And of course gifsicle couldn't save any bytes in the gif: there is no way to compress arbitrary data and the random pixels are all chaotically arranged, meaning that the most efficient way of encoding them is one pixel at a time. Numberphile (I think?) had a video on "what is information" and did random noise to intentionally mess with YouTube's compression. VSauce had a video on video compression at one point too, but I forget what it was called. – Draco18s Jun 30 '17 at 17:45
  • 1
    @Draco18s, I know, the note about it being incompressible was making fun of myself for trying to run gifsicle on it anyway. – Una Jun 30 '17 at 19:15
  • 2
    Gifsicle is the wrong tool. Precomp gets it down from 4 MB to 3 MB :) That's because the GIF algorithm expands the randomness instead of compressing it and Precomp reverses this. – schnaader Oct 17 '17 at 16:01

C on POSIX, 98 96 95 92 bytes

-3 thanks to Tas

#define r rand()
f(){for(srand(time(0));printf("\e[%d;%dH\e[%d;4%dm ",r%40,r%40,r%2,r%8););}

This chooses between 16 colors (dark grey, red, green, blue, orange, cyan, purple, light grey, black, pink, light blue, yellow, light cyan, magenta, white) and prints them directly to the terminal.

Note that if your GPU is too slow, this may seem like it's updating the entire screen at once. It's actually going pixel by pixel, but C is fast.

colors

Alternate solution that makes the colors more distinct:

f(){for(srand(time(0));printf("\e[%d;%dH\e[%d;3%dm█",rand()%40,rand()%40,rand()%2,rand()%8););}

Proof that it goes pixel by pixel (screenshot from alternate program):

3d!!!

Wow, that looks almost 3-dimensional...

  • It's missing a ; to compile correctly but seems to work great other than that! B-) – cleblanc Jun 1 '17 at 20:28
  • @cleblanc Oh, you're right! I forgot to add that after I switched from while to for. – MD XF Jun 1 '17 at 20:39
  • 2
    You could probably shave a few bytes by #define r rand() and then using r%40, r%40, r%2, r%8 – Tas Jun 2 '17 at 4:26
  • By not using 32-bit color this does not meet the requirements. – wberry Jun 4 '17 at 5:49
  • 3
    @wberry "Your program must have an even chance of picking all colors (i.e in the range #000000 to #FFFFFF), or all colors that can be displayed on your system." These are all the colors that the POSIX terminal can display. – MD XF Jun 4 '17 at 17:31

JS+HTML 162+32 (194) 124+13 (137) bytes

Thanks to Luke and other commenters for saving me lots of bytes.

r=n=>n*Math.random()|0
setInterval("b=c.getContext`2d`;b.fillStyle='#'+r(2**24).toString(16);b.fillRect(r(99),r(99),1,1)",0)
<canvas id=c>

  • 2
    Actually <canvas id=c> should be sufficient as I think the default size for the canvas-element is 300 x 150 px and so exceeds your "viewport size" of 99 x 99 px. Anyway, nice solution. – insertusernamehere Jun 1 '17 at 21:52
  • 1
    @insertusernamehere, yes, thanks – Octopus Jun 1 '17 at 21:57
  • 1
    Doesn't work in Firefox now though. It does work in Chrome – ETHproductions Jun 1 '17 at 22:09
  • 1
    OK, OK, I've got it. Save 2 bytes by doing b=c.getContext2d. (Not sure how to format this, but if "2d" is a template literal, it doesn't need the parentheses.) (Deleting my previous suggestions.) – Rick Hitchcock Jun 1 '17 at 22:26
  • 1
    Along with Rick's suggestion, use a with statement to get rid of all instances of b.: r=n=>n*Math.random()|0 setInterval("with(c.getContext`2d`)fillStyle='#'+r(2**24).toString(16),fillRect(r(99),r(99),1,1)") – darrylyeo Jun 2 '17 at 16:16

MATL, 28 bytes

40tI3$l`3l2$r,40Yr]4$Y(t3YGT

Try it at MATL Online. I have added a half-second pause (.5Y.) to this version.

enter image description here

Explanation

40       % Push the number literal 40 to the stack
t        % Duplicate
I        % Push the number 3 to the stack
3$l      % Create a 40 x 40 x 3 matrix of 1's (40 x 40 RGB image)
`        % Do...while loop
  3l1$r  % Generate 3 random numbers (RGB)
  ,      % Do twice loop
    40Yr % Generate two integers between 1 and 40. These will be the
  ]      % row and column of the pixel to replace
  4$Y(   % Replace the pixel with the random RGB value
  t      % Make a copy of the RGB image
  3YG    % Display the image
  T      % Push a literal TRUE to create an infinite loop
  • 1
    I love it! ---- – MD XF Jun 2 '17 at 1:28
  • 4
    out of curiosity, how did you giffify your code output? – Octopus Jun 2 '17 at 5:23
  • 2
    @Octopus I just used LICEcap. One of these days, I'm going to incorporate animated GIF output into the online compiler. – Suever Jun 2 '17 at 11:36
  • Seeing as how this answer uses less commands/methods to achieve a similar result, couldn't you convert it to MATL to possibly achieve a lower score? – MD XF Nov 26 '17 at 5:16

TI-BASIC (84+C(S)E only), 37 35 bytes

:For(A,1,5!
:For(B,1,5!
:Pxl-On(A,B,randInt(10,24
:End
:End
:prgmC //"C" is the name of this program

Due to hardware limitations, this will eventually crash, since every time a program is nested within a program in TI-BASIC, 15 KB of RAM are allocated to "keep a bookmark" in the parent program. This would run fine on a "theoretical" calculator with infinite RAM, but if we want it to run indefinitely on a real calculator, we can just wrap it in a While 1 loop for an extra 2 bytes:

:While 1
:...
:End

The TI-83 family calculators with color screens (TI 84+CE and CSE) support 15 colors. They have color codes 10 through 24. This cycles through all the pixels in a 120 by 120 (5!) square and assigns each a random color.

Result:

enter image description here

  • Yay, another BASIC answer! Just to be sure, does this run forever? – MD XF Jun 2 '17 at 1:54
  • @MDXF Now it does! ;-). Missed that part the first time. +5 bytes. – Scott Milner Jun 2 '17 at 1:57
  • You can make the for loops start at 0 if you want to cover 100x100 pixels. – kamoroso94 Jun 2 '17 at 13:30
  • @kamoroso94 Ah, true. I could also do 5! if I wanted 120 pixels. – Scott Milner Jun 2 '17 at 15:13
  • 2
    @MDXF TI-BASIC is token-based. I.e. For( is 1 byte, Pxl-On( is 1 byte, randInt( is 2 bytes, etc. – Scott Milner Jun 2 '17 at 22:18

Bash + coreutils, 59 56 bytes

for((;;)){ printf "\e[48;5;`shuf -i 0-16777215 -n1`m ";}

\e[48;5;COLORm is the escape secuence to background color.

Each "pixel" has the chance to be in the [0..16777215] range every time.

  • 1
    Wow, that's a really good idea! +1 – MD XF Jun 2 '17 at 17:44
  • You can shove off 3 bytes, if you use jot: for((;;)){ printf "\e[48;5;`jot -r 1 0 16777215`m ";} – Moreaki Jun 3 '17 at 14:27
  • I stole this idea and golfed it down to 45 bytes (\e is 1 escape char, and shuf | xargs makes it shorter (no need for -n 1, and no for). codegolf.stackexchange.com/a/158142/7017 . I can delete it if you want (I'm not really sure if I should just propose this as a comment instead of posting it. My goal is to get a bit of points to one day bounty the amazing answers to the amazing "tetris in game of life" challenge & answer! see codegolf.stackexchange.com/q/11880/7017 – Olivier Dulac Mar 14 at 18:52

MATLAB, 56 bytes

x=rand(40,40,3);while imagesc(x),x(randi(4800))=rand;end

Output looks like the image below. One "pixel" changes at a time, and only one of the RGB-colors changes.

Why? The colors in MATLAB are represented as a 3D-matrix, one layer for R,G and B. The code above changes only one of the layers per iteration. All pixels and all layers can be changed, so if you wait a bit all colors are equally possible in all positions.

Add pause(t) inside the loop to pause t seconds between each image.

You must stop it with Ctrl+C.

enter image description here

  • 3
    Clever use of the handle to the graphics object as the conditional in the where – Suever Jun 1 '17 at 20:56
  • 2
    A rule has been clarified - Your program must have an equal chance of picking all colors/points each iteration. Does your program fulfill this? – MD XF Jun 1 '17 at 21:43

Javascript+HTML 118 + 13 (131 bytes)

r=_=>255*Math.random()|0;setInterval('x=c.getContext`2d`;x.fillRect(r(),r(),1,1,x.fillStyle=`rgb(${[r(),r(),r()]})`)')
<canvas id=c>

  • This will produce evenly distributed RGB colors. You cannot use Hex colors without proper padding as numbers like #7 is not a valid color, or #777 and #777777 are the same color (2x the odds)
  • The canvas element is 300x150 by default, but I'm actually drawing on a 255x255 square, so there are off canvas pixels, so the effective area is 255x150.
  • Works only on Google Chrome.
  • 2
    Great first post! Welcome to the site! – MD XF Jun 3 '17 at 18:53

Excel VBA, 131 102 85 Bytes

Anonymous VBE immediate window function that uses a helper function (see below) to output an array of randomly colored cells to the range A1:AN40 of the activesheet object.

Note: This solution is restricted to 32-Bit installs of MS Excel (and therefore of Office as a whole) as 8^8 will not compile on 64-Bit versions of VBA

Randomize:Cells.RowHeight=48:For Each c In[A1:AN40]:c.Interior.Color=(8^8-1)*Rnd:Next

Sample Output

Randomized Cell Colors

Previous Version

Randomize:Cells.ColumnWidth=2:For Each c In Range("A1:AN40"):c.Interior.Color=RGB(n,n,n):Next

Helper Function

Outputs a random int in the range [0,255]

Function n
n=Int(255*Rnd)
End Function

C#, 369 288 287 bytes

namespace System.Drawing{class P{static void Main(){var g=Graphics.FromHwnd((IntPtr)0);var w=Windows.Forms.Screen.GetBounds(Point.Empty);for(var r=new Random();;)g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256),r.Next(256),r.Next(256))),r.Next(w.Width),r.Next(w.Height),1,1);}}}

Saved 88 bytes thanks to @CodyGray.

A full program that get's the handle to the screen and it's size and then starts randomly drawing pixels on it. Note that this might grind your graphics card to a halt when ran. Also if the screen or any control decides to repaint at any time the pixels will be lost and have to be redrawn.

Note: When running keep focus on the window as to kill it you have to either Alt+F4 or press the close button and doing so when you can't see the screen is a bit hard.

I couldn't record this working, with ScreenToGif, as that kept forcing a repaint so the pixels would get removed. However, here is a screenshot of it running after about 10-15 seconds, any longer and I think I may have ground my PC to a halt! The gap in the top right corner is where the screen forced a repaint just as I took the screenshot.

Full version example

Full/Formatted version:

namespace System.Drawing
{
    class P
    {
        static void Main()
        {
            var g = Graphics.FromHdc((IntPtr)0);
            var w = Windows.Forms.Screen.GetBounds(Point.Empty);

            for (var r = new Random();;)
                g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256), r.Next(256), r.Next(256))),
                                r.Next(w.Width), r.Next(w.Height), 1, 1);
        }
    }
}

A version for 308 227 226 bytes that only draws on the region 0-40:

namespace System.Drawing{class P{static void Main(){var g=Graphics.FromHdc((IntPtr)0);for(var r=new Random();;)g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256),r.Next(256),r.Next(256))),r.Next(40),r.Next(40),1,1);}}}

Example output for this one:

Small example output


  • Graphics.FromHwnd((IntPtr)0) would also work, and be much shorter than P/Invoking GetDC. Of course, your code is still like Tas's, and leaks resources like crazy, which is why it grinds your machine to a halt after only a short time of running. – Cody Gray Jun 2 '17 at 9:14
  • @CodyGray Oh I know it leaks, should still work within the challenges specs though. And GetDC does not return IntPtr.Zero so sending that to FromHdc will not work. – TheLethalCoder Jun 2 '17 at 10:22
  • 1
    Read the suggestion more carefully. :-) I'm not suggesting that you call FromHdc, I'm suggesting that you call FromHwnd. Notice that when you call GetDC to obtain the DC for a window handle, you pass in a NULL pointer (0) as the window handle. – Cody Gray Jun 2 '17 at 12:37
  • @CodyGray Ah yes that works, thanks! They're named to similar, should have read your comment more carefully... – TheLethalCoder Jun 2 '17 at 12:41

C# Console, 233 220 189 188 bytes

namespace System{using static Console;class P{static void Main(){for(var r=new Random();;){BackgroundColor=(ConsoleColor)r.Next(16);SetCursorPosition(r.Next(40),r.Next(40));Write(" ");}}}}

enter image description here

Uses "all" (windows) 16 console colors.

Thanks for the "feature" to be able to alias classes in C# via the using directive.

Edit #1

  • Removed some spaces.

  • Removed zeros from Random.Next()

  • Went to namespace system{...}

Edit #2

  • Minimum size of grid is 40x40

  • One byte by declaring Random in for loop header

  • Removed public from Main method

Edit #3

Turns out using C=Console; is not the best there is. using static Console is much like the VB.Net way to "Import" classes

I give up: TheLethalCoder made this happen


Original code for adapting window size at 207 bytes:

namespace System{using static Console;class P{static void Main(){for(var r=new Random();;){BackgroundColor=(ConsoleColor)r.Next(16);SetCursorPosition(r.Next(WindowWidth),r.Next(WindowHeight));Write(" ");}}}}

Original Image:

enter image description here

  • namespace System should save bytes, r.Next can remove the zero I believe, Remove irrelevant white space, – TheLethalCoder Jun 2 '17 at 12:23
  • Also just titling C# is fine – TheLethalCoder Jun 2 '17 at 12:23
  • Thanks! I leave Console in the title since I feel for this challenge it provides valuable context. I don't see how namespace System{} is shorter than using System;. Care to explain? – MrPaulch Jun 2 '17 at 12:30
  • 1
    I had this strong but unfounded memory that public is nescessary for the Main. Unfounded memories are the best! – MrPaulch Jun 2 '17 at 12:52
  • 1
    Thanks. Will not give up! :) Will use what I learned on the next challenge! – MrPaulch Jun 2 '17 at 13:06

Processing, 90 bytes

void draw(){float n=noise(millis());int i=(int)(n*9999);set(i%99,i/99,(int)(n*(-1<<24)));}

enter image description here

expanded and commented:

void draw(){
  float n=noise(millis());//compute PRNG value
  int i=(int)(n*9999);    //compute 99x99 pixel index
  set(i%99,i/99,          //convert index to x,y 
  (int)(n*(-1<<24)));     //PRNG ARGB color = PRNG value * 0xFFFFFFFF 
}

Ideally I could use a pixel index instead of x,y location, but Processing's pixels[] access requires loadPixels() pre and updatePixels() post, hence the use of set(). point() would work too, but has more chars and requires stroke(). The random area is actually 99x99 to save a few bytes(instead of 100x100), but that should cover 40x40 with each pixel in such an area to be replaced.

Perlin noise() is is used instead of random() to keep it more pseudo-random and a byte shorter. The value is computed once, but used twice: once for the random position, then again for the colour.

The colour is actually ARGB(00000000 to FFFFFFFF) (not RGB) (bonus points ? :D).

Python, 133 bytes

I'm not quite sure if this fits the specs, because it's on a canvas in a 40x40 area.

from turtle import*
from random import*
ht()
up()
speed(0)
R=randint
while 1:goto(R(0,39),R(0,39));dot(1,eval('('+'R(0,255),'*3+')'))

Try it online - version without eval, which doesn't work in Trinket

  • Note quite sure why, maybe your turtle dist is different from mine, but my default canvas is 300 by 400 while the default colormode is 1.0 not 255. – Jonathan Allan Jun 1 '17 at 21:30
  • Trinket.io is pretty unique. – mbomb007 Jun 1 '17 at 21:37
  • Yeah - I just tried changing colormode and it wouldn't have any of it :/ – Jonathan Allan Jun 1 '17 at 21:38
  • Why does dot(1,R(0,255),R(0,255),R(0,255)) not work either? dot is meant to accept (width,*color). It's not Python :p – Jonathan Allan Jun 1 '17 at 21:40
  • Because Trinket.io uses skulpt.js, which is an incomplete implementation of Python. – mbomb007 Jun 1 '17 at 21:44

JavaScript using Canvas 340 316 324 bytes

function r(t,e){return Math.floor(e*Math.random()+t)}function f(){x.fillStyle="rgba("+r(1,255)+","+r(1,255)+","+r(1,255)+", 1)",x.fillRect(r(0,40),r(0,40),1,1)}c=document.createElement("canvas"),c.width=40,c.height=40,x=c.getContext("2d"),document.getElementsByTagName("body")[0].appendChild(c),c.interval=setInterval(f,1);

full version

  • 2
    Welcome to the site! :) – DJMcMayhem Jun 1 '17 at 20:21
  • Does this honor the rule, "Your program must continue to display random pixels until manually stopped (it cannot terminate on its own)."? – Octopus Jun 1 '17 at 20:44
  • This appears to simply generate a bunch of random pixels when run. It does not continue to display pixels one by one until stopped. – MD XF Jun 1 '17 at 20:48
  • Seems that I missed that rule. I mistakenly thought the goal was to create an image not an animation. I will update my answer when I return to my computer. – Tim Penner Jun 1 '17 at 21:01
  • 1
    @MDXF it's animated now – Tim Penner Jun 1 '17 at 22:34

Processing, 112 bytes

void setup(){size(40,40);}void draw(){stroke(random(255),random(255),random(255));point(random(40),random(40));}

I can't guarantee that every pixel is replaced every 3 minutes, but looking at it it appears to be doing so. At least the odds of it missing a pixel, out of 1600 total, updating a random one 30x per second, totaling 5400 updates per 3 minutes, makes it unlikely that one would be missed.

Ungolfed:

The program is really straightforward. Open a window at 40x40 pixels, and every frame (default 30 per second) get a random color, and draw a point at a random coordinate between 0 and the parameter. 40 for pixel coordinates, 255 for colors.

void setup()
{
  size(40,40);
}

void draw()
{
  stroke(random(255),random(255),random(255));
  point(random(40),random(40));
}

enter image description here

  • Can you remove the size(40,40); and change point to point(random(99),random(99));? (or 100 instead if 99 isn't working) – Cows quack Jun 2 '17 at 5:51
  • @KritixiLithos in Processing, the size function MUST be the first line of code in the setup function (reasons why are complicated), so I can't get around that. I can change all occurrences of 40 to 99, I just didn't since it didn't save me any space. I mainly went with the minimum size to increase the odds that every pixel will be refreshed in a 3-minute period – Cody Jun 2 '17 at 15:40
  • Heh, that was what I first thought as well, until someone told me about it and it somehow worked out, as you can see here in a submission of mine. – Cows quack Jun 2 '17 at 15:43
  • 1
    Removing the whole setup() function on the latest version of Processing on my machine works fine without errors. – Cows quack Jun 2 '17 at 15:48
  • I guess my version of Processing is quite old, and I don't use it enough to bother upgrading right now. – Cody Jun 2 '17 at 15:49

HTML+SVG+PHP, 245 Bytes

<?$u=$_GET;$u[rand()%40][rand()%40]=sprintf("%06x",rand()%16777216);echo'<meta http-equiv="refresh" content="0.1; url=?'.http_build_query($u).'" /><svg>';foreach($u as$x=>$a)foreach($a as$y=>$c)echo"<rect x=$x y=$y width=1 height=1 fill=#$c />";

Expanded

$u=$_GET; # Get the Url
$u[rand()%40][rand()%40]=sprintf("%06x",rand()%16777216); # Set One Value in a 2 D Array
echo'<meta http-equiv="refresh" content="0.1; url=?'.http_build_query($u).'" /><svg>'; # refresh the site after 0.1 second follow the new Get parameter
foreach($u as$x=>$a) #loop through x Coordinates as Key
  foreach($a as$y=>$c) #loop through y Coordinates as Key value is the color
    echo"<rect x=$x y=$y width=1 height=1 fill=#$c />"; #print the rects for the SVG

Example for Output without meta tag and in a greater version

<svg viewBox="0 0 40 40" width=400 height=400><rect x=11 y=39 width=1 height=1 fill=#1b372b /><rect x=11 y=7 width=1 height=1 fill=#2c55a7 /><rect x=11 y=31 width=1 height=1 fill=#97ef86 /><rect x=11 y=26 width=1 height=1 fill=#94aa0a /><rect x=11 y=4 width=1 height=1 fill=#f8bf89 /><rect x=11 y=6 width=1 height=1 fill=#266342 /><rect x=11 y=29 width=1 height=1 fill=#369d80 /><rect x=11 y=20 width=1 height=1 fill=#ccfab8 /><rect x=11 y=12 width=1 height=1 fill=#ac0273 /><rect x=13 y=25 width=1 height=1 fill=#0d95e9 /><rect x=13 y=0 width=1 height=1 fill=#d2a4cb /><rect x=13 y=37 width=1 height=1 fill=#503abe /><rect x=13 y=35 width=1 height=1 fill=#4e60ae /><rect x=13 y=30 width=1 height=1 fill=#3cdd5e /><rect x=13 y=12 width=1 height=1 fill=#60464c /><rect x=13 y=17 width=1 height=1 fill=#a3b234 /><rect x=13 y=3 width=1 height=1 fill=#48e937 /><rect x=13 y=20 width=1 height=1 fill=#58bb78 /><rect x=13 y=4 width=1 height=1 fill=#5c61e6 /><rect x=13 y=10 width=1 height=1 fill=#758613 /><rect x=13 y=21 width=1 height=1 fill=#9b3a09 /><rect x=13 y=28 width=1 height=1 fill=#6c6b3b /><rect x=13 y=32 width=1 height=1 fill=#9b3a0f /><rect x=13 y=14 width=1 height=1 fill=#0c9bcc /><rect x=38 y=34 width=1 height=1 fill=#a3a65d /><rect x=38 y=23 width=1 height=1 fill=#c4441a /><rect x=38 y=25 width=1 height=1 fill=#cec692 /><rect x=38 y=39 width=1 height=1 fill=#535401 /><rect x=38 y=30 width=1 height=1 fill=#21371a /><rect x=38 y=26 width=1 height=1 fill=#7560a4 /><rect x=38 y=33 width=1 height=1 fill=#f31f34 /><rect x=38 y=9 width=1 height=1 fill=#3fce3f /><rect x=38 y=13 width=1 height=1 fill=#78cab8 /><rect x=3 y=39 width=1 height=1 fill=#c6cf06 /><rect x=3 y=26 width=1 height=1 fill=#d7fc94 /><rect x=3 y=31 width=1 height=1 fill=#048791 /><rect x=3 y=19 width=1 height=1 fill=#140371 /><rect x=3 y=12 width=1 height=1 fill=#6e7e7a /><rect x=3 y=21 width=1 height=1 fill=#f917da /><rect x=3 y=36 width=1 height=1 fill=#00d5d7 /><rect x=3 y=24 width=1 height=1 fill=#00f119 /><rect x=34 y=15 width=1 height=1 fill=#e39bd7 /><rect x=34 y=1 width=1 height=1 fill=#c1c1b8 /><rect x=34 y=36 width=1 height=1 fill=#0d15d5 /><rect x=34 y=29 width=1 height=1 fill=#d15f57 /><rect x=34 y=11 width=1 height=1 fill=#6f73b9 /><rect x=34 y=33 width=1 height=1 fill=#93ce78 /><rect x=34 y=16 width=1 height=1 fill=#ddd7bd /><rect x=34 y=14 width=1 height=1 fill=#73caa6 /><rect x=34 y=28 width=1 height=1 fill=#972d89 /><rect x=34 y=31 width=1 height=1 fill=#27e401 /><rect x=34 y=10 width=1 height=1 fill=#559d6d /><rect x=34 y=22 width=1 height=1 fill=#170bc2 /><rect x=30 y=13 width=1 height=1 fill=#a9ac0d /><rect x=30 y=4 width=1 height=1 fill=#3d9530 /><rect x=30 y=10 width=1 height=1 fill=#67b434 /><rect x=30 y=15 width=1 height=1 fill=#54930a /><rect x=30 y=11 width=1 height=1 fill=#8ce15b /><rect x=30 y=7 width=1 height=1 fill=#ddf53d /><rect x=30 y=32 width=1 height=1 fill=#04de14 /><rect x=30 y=19 width=1 height=1 fill=#f52098 /><rect x=30 y=22 width=1 height=1 fill=#dc7d70 /><rect x=30 y=0 width=1 height=1 fill=#d458c3 /><rect x=30 y=30 width=1 height=1 fill=#1f8895 /><rect x=30 y=36 width=1 height=1 fill=#b3d891 /><rect x=30 y=29 width=1 height=1 fill=#0f9810 /><rect x=30 y=5 width=1 height=1 fill=#b4ce36 /><rect x=30 y=33 width=1 height=1 fill=#a837ba /><rect x=30 y=23 width=1 height=1 fill=#02beb3 /><rect x=30 y=24 width=1 height=1 fill=#2a75da /><rect x=37 y=2 width=1 height=1 fill=#7b3aa3 /><rect x=37 y=26 width=1 height=1 fill=#0e9fb2 /><rect x=37 y=32 width=1 height=1 fill=#afb3a1 /><rect x=37 y=24 width=1 height=1 fill=#b421d6 /><rect x=37 y=16 width=1 height=1 fill=#39e872 /><rect x=37 y=38 width=1 height=1 fill=#552970 /><rect x=37 y=11 width=1 height=1 fill=#2a0b2a /><rect x=37 y=18 width=1 height=1 fill=#1fe310 /><rect x=37 y=36 width=1 height=1 fill=#a80fe3 /><rect x=37 y=6 width=1 height=1 fill=#141100 /><rect x=26 y=13 width=1 height=1 fill=#5d521d /><rect x=26 y=11 width=1 height=1 fill=#d7227e /><rect x=26 y=1 width=1 height=1 fill=#8dae67 /><rect x=26 y=19 width=1 height=1 fill=#acfd2c /><rect x=26 y=2 width=1 height=1 fill=#307dd5 /><rect x=26 y=35 width=1 height=1 fill=#76b559 /><rect x=26 y=4 width=1 height=1 fill=#e6a551 /><rect x=12 y=34 width=1 height=1 fill=#266a0a /><rect x=12 y=16 width=1 height=1 fill=#8bcf44 /><rect x=12 y=13 width=1 height=1 fill=#00caac /><rect x=12 y=3 width=1 height=1 fill=#bb7aa5 /><rect x=12 y=37 width=1 height=1 fill=#3b0559 /><rect x=12 y=27 width=1 height=1 fill=#e82087 /><rect x=12 y=8 width=1 height=1 fill=#b65157 /><rect x=19 y=20 width=1 height=1 fill=#556336 /><rect x=19 y=33 width=1 height=1 fill=#81bca0 /><rect x=19 y=34 width=1 height=1 fill=#65478a /><rect x=19 y=35 width=1 height=1 fill=#256956 /><rect x=19 y=10 width=1 height=1 fill=#c49f9c /><rect x=19 y=12 width=1 height=1 fill=#99bd3d /><rect x=19 y=13 width=1 height=1 fill=#dae45d /><rect x=19 y=36 width=1 height=1 fill=#de28e2 /><rect x=19 y=30 width=1 height=1 fill=#f26ff1 /><rect x=4 y=23 width=1 height=1 fill=#3a31dc /><rect x=4 y=4 width=1 height=1 fill=#d480e7 /><rect x=4 y=24 width=1 height=1 fill=#a304c6 /><rect x=4 y=28 width=1 height=1 fill=#775aeb /><rect x=4 y=16 width=1 height=1 fill=#d942d1 /><rect x=4 y=8 width=1 height=1 fill=#ad6c7e /><rect x=4 y=3 width=1 height=1 fill=#8ef507 /><rect x=4 y=9 width=1 height=1 fill=#c59549 /><rect x=4 y=7 width=1 height=1 fill=#f757fb /><rect x=4 y=35 width=1 height=1 fill=#2db5de /><rect x=20 y=22 width=1 height=1 fill=#340f7b /><rect x=20 y=2 width=1 height=1 fill=#ae6b7c /><rect x=20 y=20 width=1 height=1 fill=#120232 /><rect x=20 y=1 width=1 height=1 fill=#bb534c /><rect x=20 y=11 width=1 height=1 fill=#a736a1 /><rect x=20 y=38 width=1 height=1 fill=#63646f /><rect x=20 y=8 width=1 height=1 fill=#8e2095 /><rect x=20 y=27 width=1 height=1 fill=#2ae2c6 /><rect x=32 y=20 width=1 height=1 fill=#56dc7a /><rect x=32 y=34 width=1 height=1 fill=#ec16ca /><rect x=32 y=19 width=1 height=1 fill=#e2ce80 /><rect x=32 y=21 width=1 height=1 fill=#5c7638 /><rect x=32 y=0 width=1 height=1 fill=#35647c /><rect x=32 y=33 width=1 height=1 fill=#9e174a /><rect x=32 y=5 width=1 height=1 fill=#8217b4 /><rect x=32 y=30 width=1 height=1 fill=#b3e018 /><rect x=32 y=36 width=1 height=1 fill=#90ea3d /><rect x=22 y=29 width=1 height=1 fill=#9d975f /><rect x=22 y=12 width=1 height=1 fill=#b50680 /><rect x=22 y=31 width=1 height=1 fill=#9cd270 /><rect x=22 y=16 width=1 height=1 fill=#05a7f7 /><rect x=22 y=20 width=1 height=1 fill=#f6c4d5 /><rect x=22 y=21 width=1 height=1 fill=#9b0dd8 /><rect x=22 y=22 width=1 height=1 fill=#bc1c9e /><rect x=22 y=26 width=1 height=1 fill=#22b4c3 /><rect x=22 y=36 width=1 height=1 fill=#f54b7b /><rect x=22 y=19 width=1 height=1 fill=#7d3be4 /><rect x=22 y=6 width=1 height=1 fill=#ff9c6f /><rect x=22 y=34 width=1 height=1 fill=#cce01c /><rect x=22 y=30 width=1 height=1 fill=#7c4fd0 /><rect x=22 y=33 width=1 height=1 fill=#c2ef4e /><rect x=25 y=3 width=1 height=1 fill=#35c580 /><rect x=25 y=31 width=1 height=1 fill=#172b52 /><rect x=25 y=39 width=1 height=1 fill=#5e724d /><rect x=25 y=10 width=1 height=1 fill=#f50c4a /><rect x=25 y=4 width=1 height=1 fill=#012808 /><rect x=25 y=33 width=1 height=1 fill=#3a0dc3 /><rect x=25 y=12 width=1 height=1 fill=#2f254a /><rect x=25 y=30 width=1 height=1 fill=#19ff2c /><rect x=25 y=38 width=1 height=1 fill=#4a3112 /><rect x=0 y=1 width=1 height=1 fill=#886f4f /><rect x=0 y=35 width=1 height=1 fill=#0bb010 /><rect x=0 y=0 width=1 height=1 fill=#a7f77e /><rect x=0 y=27 width=1 height=1 fill=#1b38da /><rect x=0 y=39 width=1 height=1 fill=#3788ae /><rect x=0 y=13 width=1 height=1 fill=#af5149 /><rect x=0 y=32 width=1 height=1 fill=#dcb445 /><rect x=0 y=20 width=1 height=1 fill=#36a218 /><rect x=0 y=2 width=1 height=1 fill=#aacbb8 /><rect x=0 y=14 width=1 height=1 fill=#fb17e3 /><rect x=17 y=8 width=1 height=1 fill=#cb2be8 /><rect x=17 y=11 width=1 height=1 fill=#dd80b1 /><rect x=17 y=35 width=1 height=1 fill=#a269aa /><rect x=17 y=6 width=1 height=1 fill=#9faf64 /><rect x=17 y=9 width=1 height=1 fill=#762811 /><rect x=17 y=23 width=1 height=1 fill=#94fa57 /><rect x=17 y=26 width=1 height=1 fill=#9bacc3 /><rect x=17 y=1 width=1 height=1 fill=#93c849 /><rect x=17 y=4 width=1 height=1 fill=#4a9fd4 /><rect x=17 y=22 width=1 height=1 fill=#1fc5f3 /><rect x=17 y=37 width=1 height=1 fill=#76d6a3 /><rect x=17 y=5 width=1 height=1 fill=#a13389 /><rect x=9 y=38 width=1 height=1 fill=#064ba3 /><rect x=9 y=23 width=1 height=1 fill=#cc83ad /><rect x=9 y=25 width=1 height=1 fill=#1de7e8 /><rect x=9 y=3 width=1 height=1 fill=#834afe /><rect x=9 y=9 width=1 height=1 fill=#15a0fb /><rect x=9 y=27 width=1 height=1 fill=#4d54dc /><rect x=9 y=21 width=1 height=1 fill=#2bf614 /><rect x=9 y=28 width=1 height=1 fill=#8080b7 /><rect x=9 y=39 width=1 height=1 fill=#d76a3b /><rect x=9 y=33 width=1 height=1 fill=#f8da2c /><rect x=9 y=26 width=1 height=1 fill=#5884ae /><rect x=7 y=39 width=1 height=1 fill=#a0264b /><rect x=7 y=15 width=1 height=1 fill=#bd87c7 /><rect x=7 y=18 width=1 height=1 fill=#4d4878 /><rect x=7 y=35 width=1 height=1 fill=#1dcc8c /><rect x=7 y=38 width=1 height=1 fill=#76497f /><rect x=7 y=1 width=1 height=1 fill=#87b1ae /><rect x=35 y=24 width=1 height=1 fill=#5d947e /><rect x=35 y=17 width=1 height=1 fill=#eabbdc /><rect x=35 y=19 width=1 height=1 fill=#01c75b /><rect x=35 y=36 width=1 height=1 fill=#06b0dd /><rect x=35 y=21 width=1 height=1 fill=#0fbba8 /><rect x=35 y=1 width=1 height=1 fill=#480be1 /><rect x=35 y=11 width=1 height=1 fill=#3f8ef6 /><rect x=35 y=30 width=1 height=1 fill=#7691d0 /><rect x=35 y=13 width=1 height=1 fill=#c9a286 /><rect x=27 y=12 width=1 height=1 fill=#08083e /><rect x=27 y=25 width=1 height=1 fill=#95d3b4 /><rect x=27 y=30 width=1 height=1 fill=#584c1b /><rect x=27 y=9 width=1 height=1 fill=#c01082 /><rect x=27 y=3 width=1 height=1 fill=#3bf653 /><rect x=27 y=33 width=1 height=1 fill=#c06f23 /><rect x=27 y=38 width=1 height=1 fill=#184c3e /><rect x=27 y=0 width=1 height=1 fill=#725d4c /><rect x=27 y=36 width=1 height=1 fill=#e7a71b /><rect x=27 y=16 width=1 height=1 fill=#43c039 /><rect x=23 y=30 width=1 height=1 fill=#947161 /><rect x=23 y=37 width=1 height=1 fill=#e8a8e5 /><rect x=23 y=12 width=1 height=1 fill=#bd9976 /><rect x=23 y=6 width=1 height=1 fill=#15085d /><rect x=23 y=31 width=1 height=1 fill=#102c95 /><rect x=23 y=24 width=1 height=1 fill=#173bc2 /><rect x=23 y=2 width=1 height=1 fill=#bac13c /><rect x=23 y=36 width=1 height=1 fill=#eb5a88 /><rect x=23 y=22 width=1 height=1 fill=#5ddc38 /><rect x=28 y=19 width=1 height=1 fill=#1ea833 /><rect x=28 y=38 width=1 height=1 fill=#dc6f6b /><rect x=28 y=2 width=1 height=1 fill=#d9fd8a /><rect x=28 y=15 width=1 height=1 fill=#eb213e /><rect x=28 y=22 width=1 height=1 fill=#b23956 /><rect x=28 y=16 width=1 height=1 fill=#875b0a /><rect x=28 y=14 width=1 height=1 fill=#ba6172 /><rect x=28 y=18 width=1 height=1 fill=#b9779a /><rect x=39 y=26 width=1 height=1 fill=#df5e52 /><rect x=39 y=4 width=1 height=1 fill=#aabb4f /><rect x=39 y=2 width=1 height=1 fill=#7ce85c /><rect x=39 y=16 width=1 height=1 fill=#1f70a8 /><rect x=39 y=15 width=1 height=1 fill=#55e398 /><rect x=39 y=29 width=1 height=1 fill=#955213 /><rect x=39 y=33 width=1 height=1 fill=#976c99 /><rect x=39 y=34 width=1 height=1 fill=#a23109 /><rect x=39 y=25 width=1 height=1 fill=#36aeae /><rect x=39 y=9 width=1 height=1 fill=#28a600 /><rect x=39 y=17 width=1 height=1 fill=#771e5b /><rect x=39 y=30 width=1 height=1 fill=#9980b1 /><rect x=31 y=14 width=1 height=1 fill=#8ffea6 /><rect x=31 y=13 width=1 height=1 fill=#d35c5c /><rect x=31 y=39 width=1 height=1 fill=#407beb /><rect x=31 y=10 width=1 height=1 fill=#45ba53 /><rect x=31 y=2 width=1 height=1 fill=#842997 /><rect x=31 y=20 width=1 height=1 fill=#ca47b0 /><rect x=31 y=37 width=1 height=1 fill=#ed098e /><rect x=31 y=5 width=1 height=1 fill=#041b67 /><rect x=31 y=22 width=1 height=1 fill=#4aaaa6 /><rect x=31 y=31 width=1 height=1 fill=#40ccbd /><rect x=31 y=27 width=1 height=1 fill=#6325ca /><rect x=33 y=18 width=1 height=1 fill=#cfbbbc /><rect x=33 y=34 width=1 height=1 fill=#b3f6b8 /><rect x=33 y=26 width=1 height=1 fill=#ef3b82 /><rect x=33 y=16 width=1 height=1 fill=#c7df5b /><rect x=33 y=39 width=1 height=1 fill=#5ad5ba /><rect x=33 y=12 width=1 height=1 fill=#9361fd /><rect x=33 y=35 width=1 height=1 fill=#1f4795 /><rect x=33 y=3 width=1 height=1 fill=#86a80c /><rect x=33 y=17 width=1 height=1 fill=#582008 /><rect x=33 y=9 width=1 height=1 fill=#686941 /><rect x=33 y=36 width=1 height=1 fill=#76ada4 /><rect x=33 y=21 width=1 height=1 fill=#511f50 /><rect x=33 y=14 width=1 height=1 fill=#64aaf7 /><rect x=8 y=28 width=1 height=1 fill=#3de9b7 /><rect x=8 y=24 width=1 height=1 fill=#5c8451 /><rect x=8 y=31 width=1 height=1 fill=#e75b30 /><rect x=8 y=38 width=1 height=1 fill=#4ee9d0 /><rect x=8 y=29 width=1 height=1 fill=#544381 /><rect x=8 y=16 width=1 height=1 fill=#12332f /><rect x=8 y=0 width=1 height=1 fill=#9e775f /><rect x=8 y=34 width=1 height=1 fill=#02224e /><rect x=8 y=1 width=1 height=1 fill=#b299f4 /><rect x=8 y=10 width=1 height=1 fill=#b2bd80 /><rect x=8 y=20 width=1 height=1 fill=#054876 /><rect x=8 y=27 width=1 height=1 fill=#ab273a /><rect x=2 y=30 width=1 height=1 fill=#1bd5f4 /><rect x=2 y=10 width=1 height=1 fill=#b00e99 /><rect x=2 y=9 width=1 height=1 fill=#bf18b0 /><rect x=2 y=8 width=1 height=1 fill=#9aa92b /><rect x=2 y=16 width=1 height=1 fill=#aa7e3d /><rect x=2 y=1 width=1 height=1 fill=#c383ea /><rect x=2 y=24 width=1 height=1 fill=#63ab54 /><rect x=2 y=19 width=1 height=1 fill=#086cac /><rect x=2 y=0 width=1 height=1 fill=#4510cc /><rect x=2 y=6 width=1 height=1 fill=#7b529c /><rect x=6 y=27 width=1 height=1 fill=#fcc946 /><rect x=6 y=20 width=1 height=1 fill=#0a7324 /><rect x=6 y=26 width=1 height=1 fill=#d93cc2 /><rect x=6 y=14 width=1 height=1 fill=#c8d410 /><rect x=6 y=33 width=1 height=1 fill=#0e5b22 /><rect x=6 y=1 width=1 height=1 fill=#e2accf /><rect x=6 y=2 width=1 height=1 fill=#06064a /><rect x=6 y=39 width=1 height=1 fill=#fae1de /><rect x=6 y=30 width=1 height=1 fill=#db50d3 /><rect x=6 y=15 width=1 height=1 fill=#59b1c5 /><rect x=6 y=16 width=1 height=1 fill=#a0178a /><rect x=16 y=29 width=1 height=1 fill=#1eb287 /><rect x=16 y=31 width=1 height=1 fill=#5fa9b0 /><rect x=16 y=36 width=1 height=1 fill=#918835 /><rect x=16 y=2 width=1 height=1 fill=#d46404 /><rect x=16 y=1 width=1 height=1 fill=#31808e /><rect x=16 y=15 width=1 height=1 fill=#22d652 /><rect x=10 y=25 width=1 height=1 fill=#94f771 /><rect x=10 y=14 width=1 height=1 fill=#e3a90a /><rect x=10 y=4 width=1 height=1 fill=#7fbdb3 /><rect x=10 y=32 width=1 height=1 fill=#d71f68 /><rect x=10 y=10 width=1 height=1 fill=#f3dcd7 /><rect x=10 y=27 width=1 height=1 fill=#cadd64 /><rect x=10 y=31 width=1 height=1 fill=#3c38c0 /><rect x=10 y=34 width=1 height=1 fill=#542641 /><rect x=10 y=19 width=1 height=1 fill=#e17ef2 /><rect x=10 y=24 width=1 height=1 fill=#676729 /><rect x=10 y=11 width=1 height=1 fill=#619f8e /><rect x=10 y=0 width=1 height=1 fill=#1576eb /><rect x=10 y=16 width=1 height=1 fill=#52854c /><rect x=36 y=2 width=1 height=1 fill=#fe133c /><rect x=36 y=31 width=1 height=1 fill=#b67ea7 /><rect x=36 y=7 width=1 height=1 fill=#92babc /><rect x=36 y=16 width=1 height=1 fill=#fc24a0 /><rect x=36 y=26 width=1 height=1 fill=#a80f75 /><rect x=36 y=15 width=1 height=1 fill=#5ddb90 /><rect x=18 y=13 width=1 height=1 fill=#64180c /><rect x=18 y=9 width=1 height=1 fill=#d67c04 /><rect x=18 y=18 width=1 height=1 fill=#3e0988 /><rect x=18 y=4 width=1 height=1 fill=#072b32 /><rect x=18 y=34 width=1 height=1 fill=#723cab /><rect x=18 y=14 width=1 height=1 fill=#560f7d /><rect x=18 y=29 width=1 height=1 fill=#4a7dd0 /><rect x=18 y=30 width=1 height=1 fill=#db0cfc /><rect x=18 y=16 width=1 height=1 fill=#f79bbf /><rect x=14 y=18 width=1 height=1 fill=#e45cec /><rect x=14 y=4 width=1 height=1 fill=#05b63c /><rect x=14 y=38 width=1 height=1 fill=#ee0251 /><rect x=14 y=14 width=1 height=1 fill=#12fb9f /><rect x=14 y=17 width=1 height=1 fill=#f8fbc9 /><rect x=14 y=22 width=1 height=1 fill=#58e112 /><rect x=14 y=1 width=1 height=1 fill=#a5bc5c /><rect x=14 y=10 width=1 height=1 fill=#3c6002 /><rect x=14 y=5 width=1 height=1 fill=#556f7a /><rect x=14 y=36 width=1 height=1 fill=#ccfaa9 /><rect x=14 y=15 width=1 height=1 fill=#2a8597 /><rect x=1 y=28 width=1 height=1 fill=#899272 /><rect x=1 y=29 width=1 height=1 fill=#be4da2 /><rect x=1 y=6 width=1 height=1 fill=#cbe1a5 /><rect x=1 y=1 width=1 height=1 fill=#8aebd4 /><rect x=1 y=31 width=1 height=1 fill=#547b9e /><rect x=1 y=10 width=1 height=1 fill=#ba7996 /><rect x=1 y=34 width=1 height=1 fill=#e29661 /><rect x=1 y=0 width=1 height=1 fill=#899d3f /><rect x=1 y=4 width=1 height=1 fill=#6993f0 /><rect x=1 y=13 width=1 height=1 fill=#119a7c /><rect x=1 y=15 width=1 height=1 fill=#e7c61c /><rect x=1 y=17 width=1 height=1 fill=#6e8770 /><rect x=1 y=36 width=1 height=1 fill=#cdda71 /><rect x=5 y=8 width=1 height=1 fill=#318f52 /><rect x=5 y=34 width=1 height=1 fill=#763499 /><rect x=5 y=37 width=1 height=1 fill=#5d0d72 /><rect x=5 y=0 width=1 height=1 fill=#97c9e7 /><rect x=5 y=12 width=1 height=1 fill=#babcca /><rect x=5 y=20 width=1 height=1 fill=#37d5cb /><rect x=5 y=31 width=1 height=1 fill=#642296 /><rect x=5 y=24 width=1 height=1 fill=#a6688c /><rect x=5 y=1 width=1 height=1 fill=#697956 /><rect x=29 y=32 width=1 height=1 fill=#b53b61 /><rect x=29 y=7 width=1 height=1 fill=#d131a3 /><rect x=29 y=18 width=1 height=1 fill=#0e082e /><rect x=29 y=17 width=1 height=1 fill=#8ca3dd /><rect x=29 y=11 width=1 height=1 fill=#376e46 /><rect x=29 y=20 width=1 height=1 fill=#11e2cf /><rect x=29 y=37 width=1 height=1 fill=#24b8de /><rect x=24 y=10 width=1 height=1 fill=#a906da /><rect x=24 y=36 width=1 height=1 fill=#ae0516 /><rect x=24 y=8 width=1 height=1 fill=#e0b9b1 /><rect x=24 y=27 width=1 height=1 fill=#29b27b /><rect x=24 y=33 width=1 height=1 fill=#78ea3e /><rect x=24 y=7 width=1 height=1 fill=#e5147e /><rect x=24 y=11 width=1 height=1 fill=#ce7084 /><rect x=24 y=23 width=1 height=1 fill=#78f645 /><rect x=24 y=25 width=1 height=1 fill=#a01f02 /><rect x=24 y=4 width=1 height=1 fill=#e4340c /><rect x=24 y=16 width=1 height=1 fill=#9b69d7 /><rect x=21 y=31 width=1 height=1 fill=#58ca7d /><rect x=21 y=39 width=1 height=1 fill=#037cb5 /><rect x=21 y=36 width=1 height=1 fill=#097454 /><rect x=21 y=28 width=1 height=1 fill=#71d744 /><rect x=21 y=38 width=1 height=1 fill=#10457c /><rect x=15 y=2 width=1 height=1 fill=#f4bf09 /><rect x=15 y=7 width=1 height=1 fill=#90357d /><rect x=15 y=27 width=1 height=1 fill=#6079ba /><rect x=15 y=5 width=1 height=1 fill=#cff723 /><rect x=15 y=17 width=1 height=1 fill=#54a6db />

C++ on Windows, 125 bytes

#include<Windows.h>
#include<ctime>
#define r rand()%256
int main(){for(srand(time(0));;)SetPixel(GetDC(0),r,r,RGB(r,r,r));}

Newlines necessary and included in byte count.

Loops forever, randomly picks a position between 0 and 255 (inclusive) for row and column values, assigns random R,G,B values between 0-255 (inclusive)

  • 1
    I realize you're golfing this, but man that leak of a device context each time through the loop really gets my spidey-senses tingling! – Cody Gray Jun 2 '17 at 9:09
  • Save 15 bytes by making it C on Windows instead of C++ on Windows, as C compilers will let you leave off the #includes. (And yes, there are non-Visual Studio C compilers for Windows.) – MD XF Jun 2 '17 at 22:06

Python 3.6 + Tkinter, 281 bytes

from tkinter import*
from random import*
from threading import*
a=randrange
x=40
d={"width":x,"height":x}
w=Tk()
c=Canvas(w,**d)
c.pack()
i=PhotoImage(**d)
c.create_image((20,20),image=i)
def r():
 while 1:i.put(f"{a(0,0xffffff):0>6f}",(a(0,x),a(0,x)))
Thread(r).start()
mainloop()
  • As tkinter is a standard library, you don't need to include it in the header – caird coinheringaahing Jun 1 '17 at 20:20
  • I get the same error -- Windows 10, Python 3.6.0 I can guess why init is seeing four passed parameters -- the method is being passed a "self" parameter implicitly. But I have no idea why that is generating an error, since the documentation shows the Canvas constructor accepts three parameters (master, x, y) as shown in the code. – CCB60 Jun 2 '17 at 5:03
  • Should be fixed now. – Martmists Jun 2 '17 at 8:52
  • 1
    also @Ilikemydog Tkinter is not always in stdlib. On windows it's optional when installing, and I don't think my arch partition has Tkinter installed either. Might as well include it. – Martmists Jun 2 '17 at 12:09
  • ther is typo - "img" instead of "i". And still it does not work, this time I get c.create_image((20,20),i) File "C:\Python36\lib\tkinter\__init__.py", line 2483, in create_image return self._create('image', args, kw) File "C:\Python36\lib\tkinter\__init__.py", line 2474, in _create *(args + self._options(cnf, kw)))) _tkinter.TclError: unknown option "pyimage1" – Mikhail V Jun 2 '17 at 19:39

JavaScript (ES7) + HTML using SVG, 129 + 10 = 139 bytes

SVG version, heavily inspired by @Octopus's <canvas> approach.

JS

r=n=>n*Math.random()|0
setInterval('s.innerHTML+=`<rect x=${r(40)} y=${r(40)} fill=#${r(2**24).toString(16)} width=1 height=1>`')

HTML

<svg id=s>

Since the Stack Snippet likes to break the script by parsing the <rect> tag, here's a CodePen.

6502 Assembly, 92 bytes

loo: lda $fe
sta $00
lda $fe
and #$3
clc
adc #$2
sta $01
lda $fe
ldy #$0
sta ($00),y
jmp loo

Output:

output

Explanation:

loop: lda $fe       ; accumulator = random
      sta $00       ; store accumulator
      lda $fe       ; accumulator = random
      and #$3       ; accumulator &= 3
      clc           ; clear carry
      adc #$2       ; accumulator += 2
      sta $01       ; store accumulator
      lda $fe       ; accumulator = random
      ldy #$0       ; register Y = 0
      sta ($00),y   ; store register Y
      jmp loop      ; loop
  • 1
    What is yoiur target 6502 platform here? BBC Micro? Apple ][? Commodore VIC-20 etc...? – Shaun Bebbers Mar 15 at 11:49
  • Do label names have to be at least three characters long? – Jonathan Frech Sep 7 at 1:12

LOGO, 71 bytes

The only language that I know of, being not esoteric/specially designed for codegolfing, and have forever function. Any idea on the map part?

pu forever[setxy random 100 random 100 setpixel map[random 256][1 1 1]]

shortC, 66 56 bytes

Dr rand()
AOZR"\e[%d;%dH\e[%d;4%dm ",r%40,r%40,r%2,r%8);

-10 bytes thanks to Dr. Rand. :P

A                                                                  main function
 O                                                                 for
  Z                                                                seed rand()
   R                                                               print
    "\e[%d;%dH                                                     coordinate placeholder string
              \e[%d;4%dm "                                         color placeholder string
                          ,rand()%40,rand()%40,rand()%2,rand()%8   fill placeholders
                                                                ); interpreter hole

No TIO link because you obviously can't print to the kind of terminal this requires online.

Perl (on *nix), 69 bytes

The \x1bs are literal escape characters.

Relies on stty command and works well on OS X.

{printf"\x1b[%i;%iH\x1b[48;5;%im ",map{rand$_}`stty size`=~/\d+/g,256;redo}

Similar to other approaches, but I liked the combination of all params into one call to printf so thought I'd share. Kills my terminal.

enter image description here


Twice as many pixels, 83 bytes

{printf"\x1b[%i;%iH\x1b[48;5;%i;38;5;%im▄",map{rand$_}`stty size`=~/\d+/g,256,256;redo}

This approach uses a unicode block and a random foreground and background colour which gives a more square pixel. Kills my terminal too, but looks cooler.

enter image description here

  • Don't forget you can use the literal escape byte, ASCII 0x1B (27) instead of \e. And on StackExchange this can be represented by . – MD XF Jul 21 '17 at 16:11
  • @MDXF Yeah... I need to test that as a script, because that wasn't working via -e! I also need to up the byte count of the one with unicode. Oops! Thanks for the reminder! – Dom Hastings Jul 21 '17 at 16:13

Bash, 104 bytes

The \es are literal escape characters.

These are pretty much translations of my Perl submission, but using bash fork bomb style syntax! Not as clever as the other bash entry that writes directly to the display I'm afraid.

:(){ printf "\e[%i;%iH\e[48;5;%im " $((RANDOM%`tput lines`)) $((RANDOM%`tput cols`)) $((RANDOM%256));:;};:

More pixels, 130 bytes

Same as my Perl answer, this uses a unicode character for the foreground and colours the background of each pixel too.

:(){ printf "\e[%i;%iH\e[48;5;%i;38;5;%im▄" $((RANDOM%`tput lines`)) $((RANDOM%`tput cols`)) $((RANDOM%256)) $((RANDOM%256));:;};:
  • Not bad. However, I still don't understand the "\e[48;5;%im". Why are the 48 and 5 necessary? – MD XF Jul 21 '17 at 16:46
  • That access the full 256 colours, rather than just the standard 16 colour palette. In terminals that support it, it's possible to use \e[48;2;RRR;GGG;BBBm but very few terminal emulators support it... :( – Dom Hastings Jul 21 '17 at 16:48
  • Holy mother of code.... I had no idea that was possible. My life is a lie. Thanks a million :P – MD XF Jul 21 '17 at 16:50
  • @MDXF ^^ and also 38;5 denotes foreground and 48;5 deonates background. misc.flogisoft.com/bash/tip_colors_and_formatting – Dom Hastings Jul 21 '17 at 16:50
  • 1
    @MDXF No worries! Glad to help! Shame I missed this when it was brand new, but that Minecraft answer... unreal! – Dom Hastings Jul 21 '17 at 16:50

QBIC, 34 bytes

screen 12{pset(_r640|,_r480|),_r16

Unfortunately, QBIC doesn't set a SCREEN mode by default, so that eats some bytes. PSET is an illegal command in QBIC's default graphical context.

Explanation

screen 12           Set the screen to a mode supporting (colored) graphics
{                   DO until the compiler is killed by ctrl-scroll lock
pset                PSET is a QBasic command to set one pixel
(_r640|,_r480|)     it takes a set of coords (x, y) which QBIC chooses at random with _r
,_r16               and a color (1,16)

Sample output

@Anonymous found an error in QBIC's rnd() function. Fixing that gives the output below. Thanks!

enter image description here

  • As should be obvious from the screen shot, your solution doesn't satisfy the randomness conditions. Given a coordinate, not all colours are equally likely and given a colour, not all coordinates are equally likely; they're highly correlated and that's putting it mildly. The problem is the random number generator you're using: FUNCTION getRandomNumber! (Bottom!, Top!) ↵ RANDOMIZE TIMER 'this sets the random number generator ↵ IF Bottom > Top THEN ... END IF ↵ getRandomNumber = INT((Top - Bottom + 1) * RND + Bottom) ↵ END FUNCTION Your random numbers are just hashes of the current time. – Anonymous Oct 15 '17 at 22:50
  • @Anonymous It's fixed now, thanks! – steenbergh Oct 16 '17 at 15:55

6502 Assembly, 582 bytes

Whew, this was fun. Does more or less the same thing as my Applesoft BASIC solution.

start:
lda #15
sta $0
sta $1
loo:
lda $fe
and #3
cmp #0
beq g_l
cmp #1
beq g_r
cmp #2
beq g_d
dec $1
d_w:
lda $1
and #$1f
asl
tax
lda ypo,x
sta $2
inx
lda ypo,x
sta $3
lda $0
and #$1f
tay
lda ($2),y
tax
inx
txa
sta ($2),y
jmp loo
g_d:
inc $1
jmp d_w
g_l:
dec $0
jmp d_w
g_r:
inc $0
jmp d_w
ypo:
dcb $00,$02,$20,$02,$40,$02,$60,$02
dcb $80,$02,$a0,$02,$c0,$02,$e0,$02
dcb $00,$03,$20,$03,$40,$03,$60,$03
dcb $80,$03,$a0,$03,$c0,$03,$e0,$03
dcb $00,$04,$20,$04,$40,$04,$60,$04
dcb $80,$04,$a0,$04,$c0,$04,$e0,$04
dcb $00,$05,$20,$05,$40,$05,$60,$05
dcb $80,$05,$a0,$05,$c0,$05,$e0,$05
  • Is this the ungolfed version of your other 6502 assembly answer? :-) – Cody Gray Jun 7 '17 at 11:06
  • @CodyGray Nope, it does things a bit differently. It's more like my Applesoft BASIC answer (uses a random walk), and the other 6502 assembly answer is more like all the other ones. – MD XF Jun 7 '17 at 14:45
  • I disagree with the byte counts: this is way shorter than 583 bytes of assembly? – Olivier Dulac Mar 14 at 18:33
  • @OlivierDulac tio.run/##Zc/… ? – MD XF Mar 15 at 2:01

R, 143 138 bytes

-4 bytes thanks to user2390246

r=runif
s=sample
g=1600
x=1:40
k=hsv(r(g),r(g),r(g))
while(1){image(x,x,matrix(1:g,40),c=k)
Sys.sleep(99/g)
k[s(g,1)]=hsv(r(1),r(1),r(1))}

image makes the required 40x40 grid of rectangles with a matrix m of values (fixed to be 1:1600 in a 40x40 square), with a randomly selected color for each rectangle, k. It plots the image, waits long enough to actually render the image, then randomly changes one of the colors. Uses hsv encoding since it is a value between 0 and 1, which allows us to use runif to generate random colors.

This generates a new plot each time.

  • It won't affect the score, but shouldn't image(x,x,m,c=k) be outside the while loop? – user2390246 Jun 2 '17 at 12:31
  • I don't think you need to define m, you only use it once. – user2390246 Jun 2 '17 at 12:34
  • 1
    @user2390246 for the image question, nah, it has to be re-called every time since it's really drawing a new image each time after changing one of the colors. Good call on the m, though. I originally thought I had to change that matrix and never went back and changed it. – Giuseppe Jun 2 '17 at 13:17

Java 7 with JavaFX, 686 674 bytes

import javafx.scene.*;import javafx.scene.canvas.*;import javafx.scene.layout.*;public class M extends javafx.application.Application{public static void main(String[]a){launch(a);}GraphicsContext g;public M(){}public void start(javafx.stage.Stage x){BorderPane r=new BorderPane();Canvas c=new Canvas(40,40);g=c.getGraphicsContext2D();Pane p=new Pane();p.getChildren().addAll(c);r.setCenter(p);x.setScene(new Scene(r,40,40));x.show();new javafx.animation.AnimationTimer(){public void handle(long n){M.this.g.setFill(javafx.scene.paint.Color.color(Math.random(),Math.random(),Math.random()));M.this.g.fillRect((int)(Math.random()*40),(int)(Math.random()*40),1,1);}}.start();}}

Explanation:

import javafx.scene.*;import javafx.scene.canvas.*;import javafx.scene.layout.*;
                                            // Required imports

public class M extends javafx.application.Application{
                                            // The class (NOTE: The public is mandatory for JavaFX)
  public static void main(String[]a){       //  Mandatory main method
    launch(a);                              //   Call the launch of the Application
  }                                         //  End of main-method

  GraphicsContext g;                        //  GraphicsContext on class-level which we'll use in the animation

  public M(){}                              //  Empty constructor (again, mandatory for JavaFX)

  public void start(javafx.stage.Stage x){  //  Overwritten start-method of Application
    BorderPane r=new BorderPane();          //   Create a BorderPane
    Canvas c=new Canvas(40,40);             //   Create a Canvas with the minimum size
    g=c.getGraphicsContext2D();             //   Retrieve the GraphicsContext and set it to the class-level variable
    Pane p=new Pane();                      //   Create a Pane
    p.getChildren().addAll(c);              //   Add the Canvas to the Pane
    r.setCenter(p);                         //   Put it in the center (otherwise it won't show in the window)
    x.setScene(new Scene(r,40,40));         //   Create a new Scene
    x.show();                               //   And show the screen
    new javafx.animation.AnimationTimer(){  //   Create a new animation
      public void handle(long n){           //    Overwritten handle-method of this animation
        M.this.g.setFill(javafx.scene.paint.Color.color(Math.random(),Math.random(),Math.random()));
                                            //     Set a random color
        M.this.g.fillRect((int)(Math.random()*40),(int)(Math.random()*40),1,1);
                                            //     And add this color as a 1x1 pixel in a random position
      }                                     //    End of handle-method
    }.start();                              //   And start the animation
  }                                         //  End of start-method
}                                           // End of class

Output:

enter image description here

Mathematica 112 Bytes

r:=RandomReal[];b:=⌈40r⌉;a=r&~Array~{40,40,3};Dynamic[a[[b,b]]={r,r,r};ArrayPlot[a,ColorFunction->RGBColor]]

Very straightforward, uses Dynamic around an ArrayPlot. Not terribly fast; limited by the maximum speed dynamic can update, but should fulfill the goal on most computers.

Starts out with a random 40x40 grid and recolors a random pixel one at a time. Ceiling characters are 3 bytes each, Ouch!

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.