Munching squares: Difference between revisions

Content added Content deleted
(added MiniScript example)
Line 882: Line 882:
{{out}}
{{out}}
[https://github.com/Pat-Garrett/RC/blob/master/Munching%20squares%20-%20vbnet.jpg Munching squares - SmallBasic]
[https://github.com/Pat-Garrett/RC/blob/master/Munching%20squares%20-%20vbnet.jpg Munching squares - SmallBasic]

=={{header|MiniScript}}==
This version runs in Mini Micro (for the graphics). Note that because MiniScript does not currently have any bit operations (all numbers are floating-point), we have to implement an <code>xor</code> function the hard way.

<lang MiniScript>xor = function(a, b)
result = 0
bit = 1
while a > 0 or b > 0
if (a%2 == 0) != (b%2 == 0) then result = result + bit
bit = bit * 2
a = floor(a/2)
b = floor(b/2)
end while
return result
end function

for x in range(0,255)
for y in range(0,255)
gfx.setPixel x, y, color.rgb(0, xor(x,y), 0)
end for
end for</lang>

{{out}}
[[File:xor_pattern_miniscript.png|MiniScript output|254px]]


=={{header|OCaml}}==
=={{header|OCaml}}==