Fake the forecast
Matlab (182*)
It is assumed that the input is stored in n
. hen looking at the algorithm, it is not sure that the results will be unique, but I checked for n=1 upto 3000
that they are unique and satisfy the rules. I basically just use complex numbers of the unit circle and 'smoothen' them by conv2 with a gaussian filter. After that they get 'rounded' to the 8 possible directions.
*I know no way how to scale the output to a certain number of pixels, so that has to be done manually=/
EDIT: I just discovered that there are cases where my checking program didn't recognise wrong solutions (changes by more than 1 step), but I am trying to find another solution.
Input:
n = 1
Code:
rand('seed',0);
for x=1:n
b = exp(1i*rand(8)*2*pi);
end
for k=1:12
b = conv2(b,[1,2,1]'*[1,2,1],'same');b=b./abs(b);
end
c = exp(1i*round(angle(b)*4/pi)*pi/4)/3;
quiver(real(c),imag(c));
Mathematica, 116 115 bytes
f@n_:=Graphics[Array[(d=n~BitGet~#;Arrow@{1+{w=15#~Mod~8+6.5d,h=15Floor[#/8]},14+{w-13d,h}})&,64,0],ImageSize->120]
I suppose a good horse never jumps higher than it has to. 2920 different grids are very easily achieved with using only two directions (I'm using N
and NE
), which makes satisfying the continuity rule trivial. I'm simply choosing between N and NE based on the bits of n
, so this will actually produce 264 different wind maps.
Here are the first ten maps:
PS: My original idea was to enumerate all 84 combinations for the 4 corners and "linearly" interpolation the rest of the grid. That probably would have resulted in nicer maps, but this is code golf after all, so I went with the what fulfils the minimum requirements.
PHP 5.4, 549 bytes
Somewhat hindered by the need to define arrows as graphics, here is my PHP code:
<? $i=$argv[1];$p="R0lGODdhBQAFAIAAAP///wAAACwAAAAABQAFAAAC";$a=[$p."BwRiicGsDwoAOw",$p."CEQeoLfmlhQoADs",$p."CARiF8hnmGABADs",$p."CIwDBouYvGIoADs",$p."BwRil8Gs+QoAOw",$p."CIQRYcqrnkABADs",$p."CARihscYn1YBADs",$p."CAx+Bmq6HWIBADs"];$c=[$i&7,$i>>3&7,$i>>6&7,$i>>9];$m=imagecreate(120,120);imagecolorallocate($m,255,255,255);foreach($a as$_)$z[]=imagecreatefromstring(base64_decode($_));for($y=0;$y<8;$y++)for($x=0;$x<8;$x++)imagecopy($m,$z[($c[0]*(7-$x)*(7-$y)+$c[1]*$x*(7-$y)+$c[2]*(7-$x)*$y+$c[3]*$x*$y)/49%8],$x*15+5,$y*15+5,0,0,5,5);imagepng($m);
Takes its argument from the command line, such as:
php windmap.php 123
This solution will use the input as the definition of the four corners. The rest of the map will be smoothly interpolated between values. It has defined results for all values from 0 to 4095, a grand total of ~11.25 years of fake forecast, which should be more than enough time to fix the weather software!
Here's a GIF of all the results:
And a ZIP containing each map can be downloaded here
(Small note: My domain recently expired because I wasn't paying attention. I've renewed it, but the above image and link may not work until the DNS updates)
Unsquishified:
<?php
$input = $argv[1];
$prefix = "R0lGODdhBQAFAIAAAP///wAAACwAAAAABQAFAAAC";
$arrows = [
$prefix."BwRiicGsDwoAOw", // E
$prefix."CEQeoLfmlhQoADs", // NE
$prefix."CARiF8hnmGABADs", // N
$prefix."CIwDBouYvGIoADs", // NW
$prefix."BwRil8Gs+QoAOw", // W
$prefix."CIQRYcqrnkABADs", // SW
$prefix."CARihscYn1YBADs", // S
$prefix."CAx+Bmq6HWIBADs", // SE
];
$points = [
$input & 7,
$input >> 3 & 7,
$input >> 6 & 7,
$input >> 9 // input beyond 0o7777 (4095) will be undefined due to lack of & 7 here
];
$img = imagecreate(120,120);
imagecolorallocate($img,255,255,255);
$arrowimgs = [];
foreach($arrows as $src) {
$arrowimgs[] = imagecreatefromstring(base64_decode($src));
}
for($y=0; $y<8; $y++) {
for($x=0; $x<8; $x++) {
$point = (
$points[0] * (7-$x)/7 * (7-$y)/7
+ $points[1] * $x /7 * (7-$y)/7
+ $points[2] * (7-$x)/7 * $y /7
+ $points[3] * $x /7 * $y /7
) % 8;
imagecopy($img,$arrowimgs[$point],$x*15+5,$y*15+5,0,0,5,5);
}
}
imagepng($img,"out.png");