Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
removed Luxor from the docs project and fixed the Vis.drawhexcells to…
Browse files Browse the repository at this point in the history
… support the native julia way of displaying a drawing by using the Luxor.preview function which will return a drawing that will be drawn according to the correct context. (#245)
  • Loading branch information
galran authored Jul 20, 2021
1 parent 14a09f8 commit f53b5f8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
1 change: 0 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Luxor = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
OpticSim = "24114763-4efb-45e7-af0e-cde916beb153"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Expand Down
3 changes: 0 additions & 3 deletions docs/src/repeat.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,19 @@ There are a few visualization functions for special 2D lattices. [`Vis.drawhexce
```@example
using OpticSim
Vis.drawhexcells(50,Repeat.hexcellsinbox(2,2))
HTML(Vis.drawhexcells(50,Repeat.hexcellsinbox(2,2), format=:svg)) #hide
```

There is also a function to compute the n rings of a cell x, i.e., the cells which can be reached by taking no more than n steps along the lattice from x:

```@example
using OpticSim
Vis.drawhexcells(50,Repeat.neighbors(Repeat.HexBasis1,(0,0),2))
HTML(Vis.drawhexcells(50,Repeat.neighbors(Repeat.HexBasis1,(0,0),2), format=:svg)) #hide
```

You can also draw all the cells contained within an n ring:

```@example
using OpticSim
Vis.drawhexcells(50,Repeat.region(Repeat.HexBasis1,(0,0),2))
HTML(Vis.drawhexcells(50,Repeat.region(Repeat.HexBasis1,(0,0),2), format=:svg)) #hide
```

13 changes: 7 additions & 6 deletions src/Vis/VisRepeatingStructures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ function drawhex(hexbasis::Repeat.Basis,hexsize,i,j,color)
Luxor.translate(-offset)
end

function drawhexcells(hexsize,cells, color::Union{AbstractArray,Nothing} = nothing; format=:png)
Luxor.Drawing(500, 500, format)
function drawhexcells(hexsize,cells, color::Union{AbstractArray,Nothing} = nothing; format=:png, resolution=(500,500))
Luxor.Drawing(resolution[1], resolution[2], format)
Luxor.origin()
Luxor.background(Colors.RGBA(0, 1, 1, 0.0))
if color === nothing
distcolors = Colors.distinguishable_colors(length(cells),lchoices = range(40,stop=100,length = 15))
for (i,cell) in pairs(cells)
Expand All @@ -49,14 +50,14 @@ function drawhexcells(hexsize,cells, color::Union{AbstractArray,Nothing} = nothi
drawhex(Repeat.HexBasis1(),hexsize,cell[1],cell[2],color[i])
end
end
if (format == :png)
res = RGB.(Luxor.image_as_matrix())
end
Luxor.finish()
if (format == :svg)
res = Luxor.svgstring()
return res
end
if (format == :png)
Luxor.preview()
end
return res
end

function draw(lattice::Repeat.Basis, scale = 50.0)
Expand Down

0 comments on commit f53b5f8

Please sign in to comment.