Numeral keys [3] and [4] will change the number of squares.
The checker pattern can be moved by holding down the left mouse button.
I probably should have written this as a checker pattern object.
Code: Select all
screenres 800,600,32
color rgb(0,0,0),rgb(255,255,255):cls
dim as integer mx,my,ox,oy,mb,xd,yd
type CheckerPattern
as integer x
as integer y
as integer w 'in squares
as integer h 'in squares
as integer s 'size of square
as ulong c1 'alternate colors
as ulong c2
end type
dim shared as CheckerPattern cp1
cp1.x = 10
cp1.y = 10
cp1.w = 8 'in squares not pixels
cp1.h = 8
cp1.c1 = rgb(100,50,0)
cp1.c2 = rgb(200,100,0)
cp1.s = 40
sub drawCheckerPattern(cp as CheckerPattern)
dim as integer counter,s,px,py
s = cp.s
px = cp.x
py = cp.y
for j as integer = 0 to cp.h-1
for i as integer = 0 to cp.w-1
if counter mod 2 = 0 then
line (i*s+px,j*s+py)-(i*s+s+px,j*s+s+py),cp.c1,bf
else
line (i*s+px,j*s+py)-(i*s+s+px,j*s+s+py),cp.c2,bf
end if
counter = counter + 1
next i
if cp.w mod 2 = 0 then counter = counter + 1
next j
end sub
sub update()
screenlock
cls
drawCheckerPattern(cp1)
screenunlock
end sub
dim as string key
do
update()
getmouse mx,my,,mb
if mb = 1 then
if mx>cp1.x and mx<cp1.x+cp1.w*cp1.s and my>cp1.y and my<cp1.y+cp1.h*cp1.s then 'over grid
ox = mx
oy = my
update()
while mb = 1
getmouse mx,my,,mb
if mx<>ox or my<>oy then 'mouse has moved
xd = mx-ox
yd = my-oy
cp1.x = cp1.x + xd 'add movement to checkerPattern position
cp1.y = cp1.y + yd
ox = mx 'save new position
oy = my
update()
end if
sleep 2 'put in loop
wend
end if
end if
key = inkey
while inkey<>"":wend
if key="1" then cp1.s = cp1.s - 1
if key="2" then cp1.s = cp1.s + 1
if cp1.s < 1 then cp1.s = 1
if key="3" then
cp1.w = cp1.w + 1
cp1.h = cp1.h + 1
end if
if key="4" then
cp1.w = cp1.w - 1
if cp1.w < 1 then cp1.w = 1
cp1.h = cp1.w
end if
sleep 2
loop until multikey(&H01)
sleep