22
3
This challenge is in honor of the tacky Christmas lights at my in laws' house.
The challenge is to create a graphical output showing the decoration in "real time".
The video (gif or other format) will have n-by-m vertical and horizontal "lights". 5 <= m,n <= 40. The frame size and resolution may vary dependent on n and m, but must be at least 50x50 pixels for n,m=5 (vector graphics is OK). A picture with n=6
and m=5
will look something like this:
The decoration:
Colors:
All lights will have one of the following 6 RGB-colors {255,0,0}
, {0,255,0}
, {0,0,255}
, {255,255,0}
, {0,255,255}
and {255,0,255}
.
Animation:
n
andm
will be taken as input on any reasonable format and in the order you like- The image will change every
dt = 25 ms
. Deviations are OK if it's due to "outside factors" such as limitation in the interpreter, slow computer etc.- If it's impossible to set the time step manually, then the default time step is accepted.
- All lights will be red (
{255,0,0}
) att=0
. - There's always a 5% chance that the first light (top-left) will change color. All colors (except the color it currently has) should be equally likely.
Each light (except the first) will get the color of the light to its left. If the light is at the far left then it will get the color of the light on the far right on the row above. The lights are numbered as shown below. Light number
k
will get the color of the light numberk-1
.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
The output should in theory run for ever (unless your language / interpreter has some limitation that prevents this).
- Please provide a sample of at least 5 seconds, preferably more in the answer (this is an encouragement, not a requirement). (A link to TIO or similar is of course OK too :D )
- Frames, axes, grid lines etc are accepted.
6-by-5
15-by-30
If the interpreter is slow, should be adjust the pause time so the total time between image updates is similar to that in the examples? What about if the pause is not needed (the code is already slowe enough)? That would save bytes, maybe against the spirit of the challenge – Luis Mendo – 2016-12-29T19:59:18.710
1Since you picked the colors for ease of implementation--in languages like QBasic that have a limited builtin set of colors, is it acceptable to use the closest available colors to the ones you specified? (Red, green, blue, yellow, cyan, magenta) – DLosc – 2016-12-29T21:04:22.063
If it's impossible to use the specified colours then yes, it's ok to use the closest alternatives. If it's just a bit longer then no.
r,g,y,b,
etc are shorter in several languages. – Stewie Griffin – 2016-12-29T21:46:17.027@LuisMendo, apologies for the late reply. I like the way you did it in your answer. It would be OK to use 25 ms, even if that would make the animation slower. I avoided
drawnow
when I implemented this in MATLAB, since the result was too slow. I think the answer must be: If it's a design choice that the interpreter has a fixed minimum time resolution of >=25 ms then it's OK. If it's due to poor/simple implementation, an online interpreter that is overloaded/slow etc. then it's not OK. – Stewie Griffin – 2016-12-30T14:54:17.1901@Stewie Got it, thanks. And nice challenge! – Luis Mendo – 2016-12-30T15:04:48.657
How exactly did you implement this in MATLAB? For me, simply calling
imshow
on each step takes >.07 seconds for a 15x15 image; did you use a trick to make it faster, or is my laptop dying slowly? – Sanchises – 2017-01-04T18:29:13.290@Sanchises I wrote it to a gif using
– Stewie Griffin – 2017-01-04T19:08:25.577imwrite
with'DelayTime',0
andpause(0.025)
(it might be the other way around (no pause, but'DelayTime',0.025
)). After timing the gif it looks like there was an additional 3 ms delay per step. 0.07 seconds was very slow, but it might be just as slow for me. I don't have MATLAB here so I can't test it.@Sanchises, have you tried running Chelsea's answer? Is
– Stewie Griffin – 2017-01-04T19:11:16.117imagesc
equally slow?Oh OK. I'll check later, but at least I know what's what. Is the delay due to MATLAB's massively slow
imshow
acceptable or should I write to agif
? – Sanchises – 2017-01-04T19:25:38.123