The last rect is the the top most rect.
Code: Select all
type scr
as integer w,h
as uinteger ptr p
end type
type rect
as integer x,y,w,h
as ulong c
end type
sub init_rect(r as rect ptr,x as integer,y as integer,_
w as integer,h as integer,c as ulong)
r->x = x
r->y = y
r->w = w
r->h = h
r->c = c
end sub
sub clear_scr(s as SCR ptr,c as ulong)
for i as integer = 0 to s->w * s->h -1
s->p[i] = c
next i
end sub
sub draw_rect(s as SCR ptr,r as rect ptr)
dim as integer xx = r->x,yy = r->y,w = r->w,h = r->h
dim as uinteger ptr p = @s->p[yy*s->w +xx]
for y as integer = 0 to h -1
for x as integer = 0 to w -1
if p[x] shr 24 = 0 then
p[x] = r->c
end if
next x
p += s->w
next y
end sub
sub draw_rect1(s as SCR ptr,r as rect ptr)
dim as integer xx = r->x,yy = r->y,w = r->w,h = r->h
dim as uinteger ptr p = @s->p[yy*s->w +xx]
for y as integer = 0 to h -1
for x as integer = 0 to w -1
p[x] = r->c
next x
p += s->w
next y
end sub
dim as scr sc
sc.w = 800
sc.h = 600
screenres sc.w,sc.h,32
sc.p = screenptr()
dim as rect r(40)
for i as integer = 1 to 40
init_rect(@r(i-1),i*10,i*10,300,180,rnd*&hff0000ff)
next i
clear_scr(@sc,&h0000007f)
dim as double t = timer()
screenlock()
for i as integer = 0 to 39
draw_rect1(@sc,@r(i))
next i
screenunlock()
print using "##.####";timer()-t
sleep 100
t = timer()
screenlock()
for i as integer = 39 to 0 step -1
draw_rect(@sc,@r(i))
next i
screenunlock()
print using "##.####";timer()-t
sleep