Create a line function that calculates each point individually...
I believe I have some code left, let's see...
if mouseclick() = 1
if started = 0
started = 1
startx = int((mousex() - mapx) / zoom#) + 1
starty = int((mousey() - mapy) / zoom#) + 1
`start boundries
if startx < 1 then startx = 1
if starty < 1 then starty = 1
if startx > width then startx = width
if starty > height then starty = height
else
endx = int((mousex() - mapx) / zoom#) + 1
endy = int((mousey() - mapy) / zoom#) + 1
`end boundries
if endx < 1 then endx = 1
if endy < 1 then endy = 1
if endx > width then endx = width
if endy > height then endy = height
`here comes the rendering
if startx = endx and starty = endy
ink tile(ctile,2),0
box mapx + startx*zoom# - zoom#, mapy + starty*zoom# - zoom#, mapx + startx*zoom#, mapy + starty*zoom#
else
ink tile(ctile,2),0
box mapx + startx*zoom# - zoom#, mapy + starty*zoom# - zoom#, mapx + startx*zoom#, mapy + starty*zoom#
`get distance between points
dx# = abs(endx - startx)
dy# = abs(endy - starty)
if endx > startx then xi = 1 else xi = -1
if endy > starty then yi = 1 else yi = -1
if dx# > dy#
for i = 0 to dx#*xi step xi
posx = startx + abs(i) * xi
posy = starty + abs(int(dy# / dx# * i)) * yi
ink tile(ctile,2),0
box mapx + posx*zoom# - zoom#, mapy + posy*zoom# - zoom#, mapx + posx*zoom#, mapy + posy*zoom#
next i
else
for i = 0 to dy#*yi step yi
posx = startx + abs(int(dx# / dy# * i)) * xi
posy = starty + abs(i) * yi
ink tile(ctile,2),0
box mapx + posx*zoom# - zoom#, mapy + posy*zoom# - zoom#, mapx + posx*zoom#, mapy + posy*zoom#
next i
endif
endif
endif
else
if started = 1
started = 0
`here comes the rendering to the map
if startx = endx and starty = endy
map_data(startx,starty) = tile(ctile,1)
else
`get distance between points
dx# = abs(endx - startx)
dy# = abs(endy - starty)
if endx > startx then xi = 1 else xi = -1
if endy > starty then yi = 1 else yi = -1
if dx# > dy#
for i = 0 to dx#*xi step xi
posx = startx + abs(i) * xi
posy = starty + abs(int(dy# / dx# * i)) * yi
map_data(posx,posy) = ctile
next i
else
for i = 0 to dy#*yi step yi
posx = startx + abs(int(dx# / dy# * i)) * xi
posy = starty + abs(i) * yi
map_data(posx,posy) = ctile
next i
endif
refresh = 1
endif
endif
endif
endif
This is code from my map-maker about a year ago or so...
function WriteMemLine(x1, y1, x2, y2)
`Draw line on memblock
dx# = x2 - x1
dy# = y2 - y1
local i as integer
i = 0
if abs(dx#) > abs(dy#)
repeat
`Get position
gx = x1 + i
gy = y1 + int(dy#*i/dx#)
`Change memblock
if gx >=0 and gy >=0 and gx < imgsx and gy < imgsy
pos = 12 + ( ((gy*imgsx)*4) + (gx*4) )
write memblock dword img, pos, ForColor
endif
`Increase/decrease
if dx# > 0 then inc i else : if dx# < 0 then dec i
until abs(i) >= abs(dx#)
else
repeat
`Get position
gx = x1 + (dx#/dy#*i)
gy = y1 + i
`Change memblock
if gx >=0 and gy >=0 and gx < imgsx and gy < imgsy
pos = 12 + ( ((gy*imgsx)*4) + (gx*4) )
write memblock dword img, pos, ForColor
endif
`Increase/decrease
if dy# > 0 then inc i else dec i
until abs(i) >= abs(dy#)
endif
endfunction
This is code I used in the challenge thread of Ric (DBP). It draws a line on an image memblock.
[edit]
I have also an algorithm for filled circle (I haven't seen any faster ones), filled ellips, blurring images using memblocks, fading images using memblocks, resizing images using memblocks and the thing ImageTrans does (blend 2 images together using a greyscale map).
If you want my code for the paint program challenge, I could post it here...
It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.