There's no need to calculate all rows since they are equal(only the first one)
Code: Select all
function draw_lrgrad(c1 as ulong,c2 as ulong,x as integer,y as integer,_
w as integer,h as integer,sw as integer,dst as ulong ptr)as integer
'''''''''''''''''
if c1 = c2 or dst = 0 then return 0
dim as ubyte r1,g1,b1,r2,g2,b2
'1st color
r1 = (c1 shr 16) and 255
g1 = (c1 shr 8) and 255
b1 = c1 and 255
'2nd color
r2 = (c2 shr 16) and 255
g2 = (c2 shr 8) and 255
b2 = c2 and 255
dim as single sr,sg,sb,cr,cg,cb
'get the step
sr = (r2-r1)/w
sg = (g2-g1)/w
sb = (b2-b1)/w
cr = r1
cg = g1
cb = b1
dim as ulong ptr p = @dst[y*sw+x],p1 = p 'save the 1st row
if p = 0 then return 0
screenlock()
'update the 1st row 1st
for x1 as integer = 0 to w-1
p[x1] = (cr shl 16) or (cg shl 8) or cb
cr += sr
cg += sg
cb += sb
next x1
p += sw '2nd row
'update the 2nd row to the last row
for y1 as integer = 1 to h-1
for x1 as integer = 0 to w-1
p[x1] = p1[x1] 'just use the 1st row
next x1
p += sw
next y1
screenunlock()
return 1
end function
const sw = 800,sh = 600,sd = 32
screenres sw,sh,sd
dim as ulong ptr p = screenptr()
draw_lrgrad(&hff0000,&hff00,50,50,500,500,sw,p)
sleep