uxn/projects/demos/mandelbrot.usm

123 lines
2.9 KiB
Plaintext

( a blank file )
%+ { ADD } %- { SUB } %* { MUL } %/ { DIV }
%< { LTH } %> { GTH } %= { EQU } %! { NEQ }
%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 }
%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }
( fixed-point )
%RESF { #0008 }
%TO2F { RESF #0040 SFT2 SFT2 }
%MUL2F { MUL2 RESF SFT2 }
%DIV2F { SWP2 TO2F SWP2 DIV2 }
%RTN { JMP2r }
%TOB { SWP POP }
%MOD2 { OVR2 OVR2 DIV2 MUL2 SUB2 }
%MOD { DUP2 / * - }
%SFL2 { #0040 SFT2 SFT2 }
%DEBUG { .Console/byte DEO #0a .Console/char DEO }
%DEBUG2 { .Console/short DEO2 #0a .Console/char DEO }
%WIDTH { #0080 }
%HEIGHT { #0080 }
( devices )
|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 ]
|10 @Console [ &pad $8 &char $1 &byte $1 &short $2 &string $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ]
|30 @Audio0 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|40 @Audio1 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|50 @Audio2 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|60 @Audio3 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|70 @Midi [ &vector $2 &channel $1 &note $1 &velocity $1 ]
|80 @Controller [ &vector $2 &button $1 &key $1 ]
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &chord $1 ]
|a0 @File [ &vector $2 &success $2 &offset $2 &pad $2 &name $2 &length $2 &load $2 &save $2 ]
|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ]
( variables )
|0000
@zoom $1
@iter $1
@fractal [ &c_re $2 &c_im $2 &x $2 &y $2 ]
( program )
|0100 ( -> )
( theme )
#f840 .System/r DEO2
#f840 .System/g DEO2
#f840 .System/b DEO2
#20 .iter POK
#04 .zoom POK
#0000 #0080
&ver
( col ) OVR2 .Screen/y DEO2
#0000 #0080
&hor
( row ) OVR2 .Screen/x DEO2
,mandelbrot JSR
( incr ) SWP2 #0001 ++ SWP2
OVR2 OVR2 LTH2 ,&hor JNZ
POP2 POP2
( incr ) SWP2 #0001 ++ SWP2
OVR2 OVR2 LTH2 ,&ver JNZ
POP2 POP2
BRK
@mandelbrot ( -- )
(
.Screen/x DEI2
.Screen/y DEI2 )
(
double c_re = [col - width/2.0]*4.0/width;
double c_im = [row - height/2.0]*4.0/width;
double x = 0, y = 0;
int iteration = 0;
while [x*x+y*y <= 4 && iteration < max] {
double x_new = x*x - y*y + c_re;
y = 2*x*y + c_im;
x = x_new;
iteration++;
}
if [iteration < max] putpixel[col, row, white];
else putpixel[col, row, black];
)
( c_re = [col - width / 2.0] * 4.0 / width )
(
.Screen/x DEI2 TO2F
WIDTH TO2F
#0002 TO2F
DIV2F
SUB2
#0002 TO2F
WIDTH TO2F
DIV2F
MUL2F
.fractal/c_re POK2
)
#01 .Screen/color DEO
RTN