Skip to content

Instantly share code, notes, and snippets.

@tommy-mor
Last active June 7, 2016 01:14
Show Gist options
  • Save tommy-mor/32476edbcc59d9e35c34a47c268042c7 to your computer and use it in GitHub Desktop.
Save tommy-mor/32476edbcc59d9e35c34a47c268042c7 to your computer and use it in GitHub Desktop.
#Pkg.add("Images")
#Pkg.add("ImageView")
#Pkg.add("Colors")
#Pkg.add("FixedPointNumbers")
#Pkg.add("Colors")
#Pkg.add("Drawing")
using Drawing
using Images
using ImageView
println("asdasdasd")
function dist(x1, y1, x2, y2)
abs(x1 - x2) + abs(y2 - y1)
end
function direct(x, mult)
mult * x + 50 * mult / 4
end
xp = 50
yp = 25
width = 100
# plot(layer(x=[100],y=[100], Geom.point, Theme(default_color=color("red"))),
# layer([direct],0,500, Geom.line),
# layer(x=xa, y=ya, Geom.point, Theme(default_color=color("orange"))),
# layer(x=[100],y=[100], Geom.point, Theme(default_color=color("red"))))
println("asd")
#=
plot(layer(x=rand(10), y=rand(10), Geom.point),
layer(x=rand(10), y=rand(10), Geom.line))
=#
function dos(mult)
xa = []
xa, ya = [], []
point = (10, 10)
tic()
for x in [1:1:100;]
for y in [1:1:100;]
for xl in [1:1:100;]
dist1 = dist(x, y, xp, yp)
dist2 = dist(x,y,xl, direct(xl, mult))
if abs(dist1 - dist2) < 4
push!(xa,(x,y))
end
end
#=
if dist(x,y, 100,100) == 100
push!(xa,x)
push!(ya,y)
end
=#
end
end
println("calc took $(toc()) seconds")
with(PNG("test2 no $(mult).png", 1000, 1000), Ink("red"), Pen(1.0,cap="butt"), Axes(; scale=100, border=0,centred=false)) do
tic()
paint(Ink("blue")) do
for p in xa
x , y = p
move(x, y)
rectangle(1,1)
end
end
println("points took $(toc()) seconds")
paint(Ink("red")) do
move(xp,yp)
rectangle(0.5,0.5)
end
tic()
paint(Ink("red")) do
for a in [0:0.5:500;]
move(a, direct(a, mult))
rectangle(0.5,0.5)
end
end
println("line took $(toc()) seconds")
draw() do # the Ink is red here - the scope above has closed
end
end
end
for m in [-5:0.5:5;]
dos(m)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment