这是一个使用带有Luxor.jl的图元绘制它的快速示例
using Luxor
function b()
Drawing(300, 300, "hello-world.png")
background("black")
sethue("white")
#Luxor.scale(1,1)
Luxor.translate(150, 30)
Luxor.rotate(10 * pi / 180)
w = 40
h = 200
rect(O, w, h, :fill)
finish()
preview()
end
现在,您可以提取转换矩阵并在其他地方使用,而不是直接使用 Luxor 绘制它。
using Plots
using GR
using LinearAlgebra
gr(size = (300, 300), legend = false)
function a(transform=Matrix{Int}(I, 3, 3))
side = 300
width = side
height = side
xs = [string("x", i) for i = 1:width]
ys = [string("y", i) for i = 1:height]
z = float((1:height) * reshape(1:width, 1, :))
# Plots.heatmap(xs, ys, z, aspect_ratio = 1)
white = maximum(z)
# Draw a rectangle with a rotation matrix applied
for x in 0:40
for y in 0:200
t = transform*[x;y;1]
z[round(Int, t[2]), round(Int, t[1])] = white
end
end
Plots.heatmap(xs, ys, z, aspect_ratio = 1)
end
using Luxor
function b()
Drawing(300, 300, "hello-world.png")
background("black")
sethue("white")
#Luxor.scale(1,1)
Luxor.translate(100, 60)
Luxor.rotate(-10 * pi / 180)
w = 40
h = 200
rect(O, w, h, :fill)
finish()
preview()
tranformation_matrix = Luxor.cairotojuliamatrix(Luxor.getmatrix())
a(tranformation_matrix)
end
请注意,这会留下杂散像素,因为我的 for 循环在栅格化填充方面效率不高。从 Luxor 访问像素数据可能会更好,或者使用其他一些将仿射变换应用于矩阵的函数。
注意朱莉娅的情节:
第一次绘图的时间很慢。要对其进行任何真正的迭代,您应该利用Revise.jl 并将您的测试函数保存在一个文件中,并将其包含在includet("test.jl") 中。然后你的 julia 会话是持久的,你只需要等待你的 using 语句一次。