Munching squares: Difference between revisions

Content added Content deleted
Line 794: Line 794:
axis equal;</lang>
axis equal;</lang>
{{out}} [[File:matlab_xor.png|MATLAB output|200px]]
{{out}} [[File:matlab_xor.png|MATLAB output|200px]]

=={{header|Microsoft Small Basic}}==
<lang smallbasic>' Munching squares - smallbasic - 27/07/2018
size=256
GraphicsWindow.Width=size
GraphicsWindow.Height=size
For i=0 To size-1
For j=0 To size-1
BitXor() 'color=i Xor j
GraphicsWindow.SetPixel(i,j,GraphicsWindow.GetColorFromRGB(0,color,color))
EndFor
EndFor

Sub BitXor '(i,j)->color
n=i
Int2Bit()
ib=ret
n=j
Int2Bit()
jb=ret
color=0
For k=1 to 8
ki=Text.GetSubText(ib,k,1)
kj=Text.GetSubText(jb,k,1)
If ki="1" Or kj="1" Then
kk="1"
Else
kk="0"
EndIf
If ki="1" And kj="1" Then
kk="0"
EndIf
color=2*color+kk
EndFor
EndSub

Sub Int2Bit 'n->ret
x=n
ret=""
For k=1 to 8
t=Math.Floor(x/2)
r=Math.Remainder(x,2)
ret=Text.Append(r,ret)
x=t
EndFor
EndSub </lang>
{{out}}
[https://github.com/Pat-Garrett/RC/blob/master/Munching%20squares%20-%20vbnet.jpg Munching squares - SmallBasic]


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