June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,23 +1,27 @@
function line(img, x0::Int, y0::Int, x1::Int, y1::Int, col)
dx = int(abs(x1-x0))
dy = int(abs(y1-y0))
function drawline!(img::Matrix{T}, x0::Int, y0::Int, x1::Int, y1::Int, col::T) where T
δx = abs(x1 - x0)
δy = abs(y1 - y0)
δe = abs(δy / δx)
er = 0.0
sx = x0<x1 ? 1 : -1
sy = y0<y1 ? 1 : -1;
y = y0
for x in x0:x1
img[x, y] = col
er += δe
if er > 0.5
y += 1
er -= 1.0
end
end
err = (dx>dy ? dx : -dy)/2
while true
@inbounds img[x0,y0]=col
if (x0==x1 && y0==y1); break; end
e2 = err;
if e2 > -dx
err -= dy
x0 += sx
end
if e2 < dy
err += dx
y0 += sy
end
end
return img
end
using Images
img = fill(Gray(255.0), 5, 5);
println("\nImage:")
display(img); println()
drawline!(img, 1, 1, 5, 5, Gray(0.0));
println("\nModified image:")
display(img); println()