The following code should produce a rectangle of random dots in the centre of the screen - but will only work correctly if I remove the lock/unlock pair of statements. This seems to defeat the purpose of having a lock/unlock pair.
The code works correctly, with or without the lock/unlock pair, if I use IanM's
fill circle function.
sync on: sync rate 0: sync
colour as dword
colour = rgb(255, 255, 255)
ink colour, 0
autocam off
position camera 0, 0, -100
point camera 0, 0, 0
randomize 140549
occurrence = 10
sw = screen width()
sh = screen height()
create bitmap 1, sw, sh
cls 0
` the following block of code does not work correctly unless you remove the
` lock/unlock pair
lock pixels
for x = sw/4 to 3*sw/4
for y = sh/4 to 3*sh/4
paint = (rnd(10000) < occurrence)
if paint
radius = rnd(3) + 1
FilledCircle(x, y, radius)
endif
next y
next x
unlock pixels
set current bitmap 0
copy bitmap 1, 0
sync
wait key
get image 1, 0, 0, sw, sh
save image "background bug.png", 1
end
function FilledCircle( CX as integer, CY as integer, R as integer )
` this method is the fastest by far - IanM's code !!
local x as integer
local y as integer
local i as integer
local s as integer
` Precalculate the square of the radius - this is the hypotenuse
i=R*R
` Calculate the size of the central square
s=R*0.70710678 : ` this number is sin(45)
` Draw it
box CX-s, CY-s, CX+s+1, CY+s+1
s=s+1
` Loop through the bit we have not yet drawn
for y=s to R
x=sqrt( i-(y*y) )
` Draw top and bottom
box CX-x, CY-y, CX+x+1, CY-y+1
box CX-x, CY+y, CX+x+1, CY+y+1
` Draw left and right
box CX-y, CY-x, CX-y+1, CY+x+1
box CX+y, CY-x, CX+y+1, CY+x+1
next y
endfunction
Edit Forgot to add that this bug is present in both U7.3 and U7.4beta9.
Edit2 This may be a Vista problem - I can't reproduce the bug on my laptop (XP) but have just confirmed that the bug is also present in U7.1 on my Vista machine.
Could someone else with Vista test this and report back?
Edit3
Here are screenshots of what I get. The first is what the image should look like:
The second is what I get with the lock/unlock pixels pair included on my Vista machine:
[
Edit4 Help!! Black pixels don't show up as black - had to change both images to a near black background!