So, below I have this little program, which is a kind of a graphic war. Or screensaver. First, it needs me to create a R:\Gwar.bmp 1920x1080 bitmap with 8 bit color depth (256 colors). But loading and saving the picture (when hitting Esc), is very slow. How can I speed that up?
CLS: DEFINT A-Z: DEFSNG N: DEFSTR F, S: DIM r(255), g(255), b(255)
v = 1920: w = 1080: SCREEN _NEWIMAGE(v, w, 256)
f = COMMAND$: IF f = "" THEN f = "r:\Gwar.bmp"
IF INSTR(f, "/") GOTO help ELSE IF INSTR(f, ".") = 0 THEN f = f + ".bmp"
IF NOT _FILEEXISTS(f) GOTO err1
OPEN f FOR RANDOM AS 1 LEN = 1: FIELD 1, 1 AS s: N = -1 'Read palette (55-1078)
FOR a = 55 TO 1075 STEP 4: N = N + 1: GET 1, a
r(N) = INT(ASC(s) / 4): GET 1, a + 1: g(N) = INT(ASC(s) / 4): GET 1, a + 2: b(N) = INT(ASC(s) / 4): NEXT
FOR a = 0 TO 255: PALETTE a, b(a) + 256 * g(a) + 65536 * r(a): NEXT: N = 1079 + v * w
'DRAW pic:
FOR a = 0 TO w - 1: N = N - v: FOR b = 0 TO v - 1: GET 1, N + b: PSET (b, a), ASC(s): NEXT: NEXT
WHILE INKEY$ <> CHR$(27)
x = RND * (v - 1): y = RND * (w - 1): c = POINT(x, y) 'find a pixel and it's color. Next = war algorithm
d = 3: PSET (x, y), c
PSET (x, y - d), c
PSET (x + d, y), c
PSET (x, y + d), c
PSET (x - d, y), c
r1 = RND * 20 + 1: CIRCLE (x, y), r1, c
WEND
'SAVE pic:
save: N = 1079 + v * w: FOR a = 0 TO w - 1: N = N - v: FOR b = 0 TO v - 1: LSET s = CHR$(POINT(b, a)): PUT 1, N + b: NEXT
NEXT: PLAY "l16c": CLOSE: CLS: SYSTEM
err1: CLOSE: SCREEN 0: PRINT "r:\Gwar.bmp not found.": SLEEP: SYSTEM
help: CLOSE: SCREEN 0: PRINT "Graphwar x*y*256 bmp. Esc=Save. Command$ = filename.": SLEEP: SYSTEM