Munching squares: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(7 intermediate revisions by 5 users not shown)
Line 288:
next x
 
next y</syntaxhighlight>
 
end</syntaxhighlight>
 
==={{header|FreeBASIC}}===
Line 610 ⟶ 608:
>2%*28*:**-2/\1-:v<:8:-1<_@ v
^\-1*2%2/*:*82::\_$0.0..:^:*<</syntaxhighlight>
 
=={{header|BQN}}==
Outputs a string that represents a PPM image.
 
BQN uses the <code>•bit</code> namespace for native bitwise operations, including casting. An input bit width and output bit width have to be given.
<syntaxhighlight lang="bqn">nl←@+10
XORppm ← {
g←⥊(0∾∾˜)¨((↕𝕩)16‿16•bit._xor⊢)˘↕𝕩
s←•Repr 𝕩
h←"P3"∾nl∾s∾" "∾s∾nl∾(•Repr 𝕩-1)∾nl
h∾∾∾⟜nl¨{¯1↓∾∾⟜' '¨•Repr¨𝕩}¨g
end}</syntaxhighlight>
Example usage:
<syntaxhighlight lang="bqn">"xor.ppm" •FChars XORppm 256</syntaxhighlight>
 
=={{header|Burlesque}}==
Line 900 ⟶ 912:
(recur (mod (inc i) (inc n)))))
</syntaxhighlight>
 
=={{header|Evaldraw}}==
 
Since all variables in Evaldraw are doubles, convert to binary and do a custom per bit xor operation.
 
[[File:Evaldraw xor squares.gif|thumb|alt=xor pattern where color is the result of xor(x,y) over values x from 0 to 128 and y to 128|Coloring the xor munching squares pattern over time]]
 
<syntaxhighlight lang="c">enum{NUMBITS=7, MAXNUMS=3}
static binary[MAXNUMS][NUMBITS];
() {
cls(0);
t = 100*klock();
for(y = 0; y < 128; y++) {
decToBin(y,1);
for(x = 0; x < 128; x++) {
decToBin(x,0);
xor(0,1,2);
c = binToDec(2);
setcol(hsv_to_rgb( (t+c*1)%360,.8,1) );
setpix(x,y);
}
}
}
 
binToDec(id) {
num = 0;
for(i=0; i<NUMBITS; i++) {
if( binary[id][i] == 1) {
num += 2^(NUMBITS-i-1);
}
}
return num;
}
 
decToBin(num,id) {
for(i=0; i<NUMBITS; i++) binary[id][i] = 0;
bitpos = NUMBITS-1;
while( num > 0 && bitpos >= 0) {
binary[id][bitpos] = num % 2 == 1;
bitpos--; // ready for next bit
num = int(num/2);
}
}
 
xor(num1,num2,store) {
for(i=0; i<NUMBITS; i++)
if(binary[num1][i] == binary[num2][i]) binary[store][i] = 0; else binary[store][i] = 1;
}</syntaxhighlight>
 
=={{header|D}}==
Line 942 ⟶ 1,002:
 
</pre>
 
=={{header|EasyLang}}==
 
[https://easylang.dev/show/#cod=VYxLCoAwDET3PcWsFWqL4s7DaK0f0BZSEb29iRTBZDHJG2aSQwdrDCq0jZoi4QL1YfZGfgCC7j/iWTg1rEcfRpHrjd1o62xL6SKVH4hbpJo5b0Z7PD2nCiTHUZFskHeHwBJG2+8QUyutHg== Run it]
 
<syntaxhighlight lang="easylang">
sc = 100 / 64
for x range0 64
for y range0 64
h = bitand bitxor x y 63
c = h / 63
color3 c c c
move x * sc y * sc
rect sc + 0.1 sc + 0.1
.
.
</syntaxhighlight>
 
=={{header|EchoLisp}}==
Line 993 ⟶ 1,070:
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Munching_squares}}
 
'''Solution'''
 
[[File:Fōrmulæ - Munching squares 01.png]]
 
'''Test case'''
 
[[File:Fōrmulæ - Munching squares 02.png]]
 
[[File:Fōrmulæ - Munching squares 03.png]]
 
=={{header|GLSL}}==
Line 1,841 ⟶ 1,928:
{{trans|D}}
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color
import "dome" for Window
 
9,476

edits