Bitmap/Bresenham's line algorithm: Difference between revisions
Content added Content deleted
m (→{{header|Nim}}) |
m (→{{header|Phix}}: minor tidy) |
||
Line 2,795: | Line 2,795: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Modified copy of [[Bitmap/Bresenham%27s_line_algorithm#Euphoria|Euphoria]], with a bigger bitmap and a simpler pattern. |
Modified copy of [[Bitmap/Bresenham%27s_line_algorithm#Euphoria|Euphoria]], with a bigger bitmap and a simpler pattern. |
||
Requires new_image() from [[Bitmap#Phix|Bitmap]], write_ppm() from [[Bitmap/Write_a_PPM_file#Phix|Write_a_PPM_file]]. |
Requires new_image() from [[Bitmap#Phix|Bitmap]], write_ppm() from [[Bitmap/Write_a_PPM_file#Phix|Write_a_PPM_file]]. <br> |
||
Note that demo\rosetta\Bresenham_line.exw is just the last 6 lines below preceded by include ppm.e since that contains bresLine() which is also used by several other examples, and covers the above requirements, as shown commented out. Results may be verified with demo\rosetta\viewppm.exw |
|||
<lang Phix>-- demo\rosetta\Bresenham_line.exw (runnable version) |
|||
⚫ | |||
-- The line algorithm |
|||
integer deltaX = abs(x1-x0), |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
-- The line algorithm |
|||
integer dimx = length(image), |
|||
dimy = length(image[1]), |
|||
deltaX = abs(x1-x0), |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
while true do |
|||
if x0>=1 and x0<=dimx |
|||
and y0>=1 and y0<=dimy then |
|||
image[x0][y0] = colour |
|||
end if |
end if |
||
if x0=x1 and y0=y1 then exit end if |
if x0=x1 and y0=y1 then exit end if |
||
Line 2,823: | Line 2,826: | ||
end if |
end if |
||
end while |
end while |
||
return |
return image |
||
end function |
end function |
||
--include ppm.e -- red, green, blue, white, new_image(), write_ppm(), bresLine() (as distributed, instead of the above) |
|||
sequence screenData = new_image(400,300,black) |
sequence screenData = new_image(400,300,black) |