An image of 4x8 pixels using two colours is easy to do, as you just increment an integer value up to its limit, and check its bits.
#constant BLOCKSIZE 10
#constant STARTVALUE 3294967295
#constant STEPVALUE 1
sync on
sync rate 0
global myBits as dword
myBits = MakeBitArray(32)
for x=STARTVALUE to 4294967295 step STEPVALUE
cls rgb(255, 0, 0)
DrawInteger(x)
if escapekey() then end
sync
next x
FreeBitArray(myBits)
wait key
function DrawInteger(myInt as integer)
lock pixels
ink rgb(255, 255, 255), 0
text 0, 0, str$(myInt) + "/" + "4294967295"
for x=0 to 31
mX = x/8
mY = x mod 8
*myBits = myInt
if BitIsSet(myBits, x)
ink rgb(255, 255, 255), 0
else
ink 0, 0
endif
box mX*BLOCKSIZE, mY*BLOCKSIZE+13, mX*BLOCKSIZE+BLOCKSIZE, mY*BLOCKSIZE+BLOCKSIZE+13
next x
unlock pixels
endfunction
`----------------
function MakeBitArray(sizeInBits as integer)
local byteSize as integer
byteSize = int(sizeInBits/8)
if not (sizeInBits mod 8) then inc byteSize
ptr = make memory(byteSize)
fill memory ptr, 0, byteSize
endfunction ptr
function FreeBitArray(arrayPtr as dword)
delete memory arrayPtr
endfunction
function SetBit(arrayPtr as dword, bitNumber as integer, state as boolean)
local addr as dword
addr = arrayPtr+(bitNumber/8)
`If bit is not opposite of state, switch it
if state <> BitIsSet(arrayPtr, bitNumber)
*addr = (*addr) ~~ (1 << (bitNumber mod 8))
endif
endfunction
function BitIsSet(arrayPtr as dword, bitNumber as integer)
local addr as dword
local state as boolean
addr = arrayPtr+(bitNumber/8)
state = (*addr) && (1 << (bitNumber mod 8))
endfunction state
Tempest - P2P UDP Multiplayer Plugin - 70%