I've noticed that some FB programmers first fill an array with the pixel information and then dump this to the screen in a second loop. (When I tried this technique on a 200,000-pixel fractal on a PII (used deliberately) without SCREENLOCK it was just 0.2 seconds faster than PSET-ing to the screen directly. With SCREENLOCK used, the array-loop and direct screen plots gave identical plot times.) Other programmers have used SCREENSET with SWAP in addition to filling an array. Using an 8bpp mode , rather than a 32bpp mode, is noticeably faster on slower PCs. marzec suggests the use of gfxlib or tinyptc:
http://www.freebasic.net/forum/viewtopi ... ast+pixels
What are the better/best techniques for pixel plotting?
Below is a fractal generator using one of the simplest fractal equations around. I don't have the knowledge or programming background to make this program plot any faster.
With the large number of pixels plotted, the program might make a good demo for anyone willing to demonstrate advanced plotting techniques.
Thanks
Code: Select all
' Hopalong - Barry Martin fractals
' modified from a one line fractal equation, 7/11/06 by MSL
SCREEN 19
OPTION EXPLICIT
DIM AS DOUBLE j, k, x, xx, y
DIM AS INTEGER i
DIM AS SHORT xp, yp, ridx, xoffs, yoffs
DIM AS UBYTE c1, c2, c3
DIM AS STRING msg
xoffs = (800 / 2)
yoffs = (600 / 2) - 60
SUB intro
#define itext(msg) locate ,(100-len((msg)))/2:print msg
LOCATE 10,0 ' vertical pos
itext("Hopalong")
PRINT
itext("Barry Martin fractals")
PRINT
PRINT
itext("Press any key to start / regenerate")
getkey
END SUB
'#########
RANDOMIZE TIMER
intro
DO
CLS
j = RND(1) * 100
k = RND(1) * 100
x = 0
y = 0
c1 = RND(1) * 255
c2 = RND(1) * 255
c3 = RND(1) * 255
SCREENLOCK
FOR i = 0 TO 500000
ridx = RND(1) * 4000
IF ridx > 3998 THEN
c1 = RND(1) * 255
c2 = RND(1) * 255
c3 = RND(1) * 255
END IF
xx = y - SGN(x) * SQR (ABS (k * x - 1))
y = j - x
x = xx
xp = (x * 2) + xoffs
yp = (y * 2) + yoffs
PSET (xp , yp) , RGB(c1, c2, c3)
NEXT
SCREENUNLOCK
SLEEP
LOOP UNTIL INKEY = CHR(255) + "k"
END