RosettaCodeData/Task/Image-noise/Liberty-BASIC/image-noise.basic

73 lines
1.4 KiB
Plaintext

WindowWidth =411
w =320
WindowHeight =356
h =240
open "Noise" for graphics_nsb as #w
#w "trapclose [quit]"
#w "down"
print "Creating BMP header"
'bitmap header, 320x240 pixels 256 colors
data 66,77,54,48,1,0,0,0,0,0,54,4,0,0,40,0,0,0,64,1
data 0,0,240,0,0,0,1,0,8,0,0,0,0,0,0,44,1,0,0,0
data 0,0,0,0,0,0,0,1,0,0,0,1,0,0
head$=""
for i = 1 to 54
read c
head$=head$+chr$(c)
next
print "Creating BMP grayscale palette"
pal$=""
for i = 0 to 255
pal$ = pal$ _
+ chr$(i) _
+ chr$(i) _
+ chr$(i) _
+ chr$(0)
next
print "Creating BMP random body"
'create bitmap body
body$=""
for x =1 To w
l$=""
for y =1 To h
l$=l$+chr$((rnd(1)>0.5)*255)
next
body$=body$+l$
next
[main]
scan
ts =time$( "ms")
'randomly "splice" the body: 1111222222-> 2222221111
splice=int(len(body$)*rnd(1))+1
body$= mid$(body$,splice+1)+left$(body$,splice)
'write BMP
open "noise.bmp" for output as #1
#1 head$;pal$;
#1 body$;
close #1
'load bmp
loadbmp "noise", "noise.bmp"
#w "cls"
'drawbmp
#w "drawbmp noise 0 0"
tf =time$( "ms")
dt =tf -ts
if dt = 0 then dt = 1
print "Framerate per second ="; using( "#.###", 1/(dt/1000)), "Ms per frame =";dt
goto [main]
[quit]
unloadbmp "noise"
close #w
end