Munching squares: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(11 intermediate revisions by 6 users not shown)
Line 108:
(* Test that the index is not out of bounds high. This could
be proven without a runtime check, but doing that is left
as an exercise for the very, veryan advanced reader. For one thing, you
one thing, you will need a more complicated version of lxor. Then you
lxor.will Youneed willto likelyprove, wantor toprovide useas an externalaxiom, that the constraintXOR
solver,of astwo well,numbers orof atthe leastsame anumber reasonableof setsignificant ofbits is
axiomsitself restricted to that number of bits. *)
val () = assertloc (i < numcolors)
 
Line 272:
{{Out}}
[https://imgur.com/a/pjl2Pd4 Screenshot.]
 
==={{header|Craft Basic}}===
<syntaxhighlight lang="basic">let s = 255
 
for y = 0 to s
 
for x = 0 to s
 
let r = x ~ y
fgcolor r, r * 2, r * 3
dot x, y
 
wait
 
next x
 
next y</syntaxhighlight>
 
==={{header|FreeBASIC}}===
Line 591 ⟶ 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
}</syntaxhighlight>
Example usage:
<syntaxhighlight lang="bqn">"xor.ppm" •FChars XORppm 256</syntaxhighlight>
 
=={{header|Burlesque}}==
Line 881 ⟶ 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 923 ⟶ 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 972 ⟶ 1,068:
 
=={{header|Fōrmulæ}}==
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Munching_squares}}
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
'''Solution'''
 
[[File:Fōrmulæ - Munching squares 01.png]]
 
'''Test case'''
 
[[File:Fōrmulæ - Munching squares 02.png]]
 
[[File:Fōrmulæ - Munching squares 03.png]]
In '''[https://formulae.org/?example=Munching_squares this]''' page you can see the program(s) related to this task and their results.
 
=={{header|GLSL}}==
Line 1,825 ⟶ 1,928:
{{trans|D}}
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color
import "dome" for Window
 
9,476

edits