Created
October 12, 2018 14:48
-
-
Save SimonDanisch/17542fc88c48dfe6860485fb48acc7c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code taken from article: http://www.tylermw.com/throwing-shade/ | |
# Author: Tyler Morgan-Wall | |
function shadows( | |
A, volcanoshadow = fill(1.0, size(A)); | |
sunangle = 45 / 180*pi, | |
angle = -90 / 180 * pi, | |
diffangle = 90 / 180 * pi, | |
numberangles = 25, | |
anglebreaks = range(angle, stop = diffangle, length = numberangles), | |
maxdistance = floor(Int, sqrt(sum(size(A).^2))), | |
) | |
tan_angles = tan.(anglebreaks) | |
sunangle_sin, sunangle_cos = sincos(sunangle) | |
@inbounds for j in 1:size(A, 2) | |
for i in 1:size(A, 1) | |
aij = A[i, j] | |
for tana in tan_angles | |
for k in 1:maxdistance | |
tanangheight = aij + tana * k | |
xcoord = (i + sunangle_sin * k) | |
ycoord = (j + sunangle_cos * k) | |
(xcoord >= size(A, 1) || | |
ycoord >= size(A, 2) || | |
xcoord < 0 || ycoord < 0) && break | |
cx = ceil(Int, xcoord); cy = ceil(Int, ycoord) | |
fx = floor(Int, xcoord); fy = floor(Int, ycoord) | |
coords = (A[cx, cy], A[fx, cy], A[cx, fy], A[fx, fy]) | |
all(coords .< tanangheight) && continue | |
if tanangheight < faster_bilinear(A, xcoord, ycoord) | |
volcanoshadow[i, j] = volcanoshadow[i, j] - 1 / length(anglebreaks) | |
break | |
end | |
end | |
end | |
end | |
end | |
volcanoshadow | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment