diff --git a/docs/src/howto/tables-grids.md b/docs/src/howto/tables-grids.md index 41cf8d2e..c4f59c85 100644 --- a/docs/src/howto/tables-grids.md +++ b/docs/src/howto/tables-grids.md @@ -7,14 +7,16 @@ end You often want to position graphics at regular locations on the drawing. The positions can be provided by: -- `Tiler`: a rectangular grid which you specify by enclosing area, and the number of rows and columns -- `Partition`: a rectangular grid which you specify by enclosing area, and the width and height of each cell -- `Grid` a rectangular grid, points supplied on demand -- `Table`: a rectangular grid which you specify by providing row and column numbers, row heights and column widths +- `Tiler`: a rectangular grid iterator which you specify by enclosing area, and the number of rows and columns +- `Partition`: a rectangular grid iterator which you specify by enclosing area, and the width and height of each cell +- `Grid` a rectangular grid iterator, where points are supplied on demand +- `Table`: a rectangular grid iterator which you specify by providing row and column numbers, row heights and column widths These are types which act as iterators. Their job is to provide you with centerpoints; you'll probably want to use these in combination with the cell's widths and heights. -There are also functions to make hexagonal grids. See [Hexagonal grids](@ref). +There are functions to make hexagonal grids. See [Hexagonal grids](@ref). + +There is [EquilateralTriangleGrid](@ref), a grid iterator which generates the vertices for a rectangular grid of equilateral triangles. ## Tiles and partitions @@ -490,3 +492,32 @@ for (n, h) in enumerate(hexspiral(hexagon, 10)) end end # hide ``` + +## EquilateralTriangleGrid + +To create a grid of equilateral triangles, you can use +[`EquilateralTriangleGrid`](@ref). Provide the starting point, the side length, +and the number of rows and columns. The iterator provides a tuple of the +vertices and number for each triangle. + +```@example +using Luxor, Colors +@drawsvg begin # hide + background("black") + nrows = 12 + ncols = 20 + side = 45 + startpoint = boxtopleft() + (50, 50) + eqtg = EquilateralTriangleGrid(startpoint, side, nrows, ncols) + + for e in eqtg + vertices, trianglenumber = e + sethue(HSB(rescale(trianglenumber, 0, nrows * ncols, 0, 360), + 0.7, 0.8)) + poly(vertices, :fillpreserve) + sethue("black") + strokepath() + text(string(trianglenumber), halign=:center, polycentroid(vertices)) + end +end # hide +``` diff --git a/src/basics.jl b/src/basics.jl index 64bdce2b..3f8a82ef 100644 --- a/src/basics.jl +++ b/src/basics.jl @@ -39,7 +39,7 @@ rescale(x, (from_min, from_max), (to_min, to_max)) ``` Examples -```jldoctest +```julia julia> rescale(15, 0, 100, 0, 1) 0.15 diff --git a/src/colors_styles.jl b/src/colors_styles.jl index dfa72556..00199698 100644 --- a/src/colors_styles.jl +++ b/src/colors_styles.jl @@ -10,7 +10,7 @@ Use `sethue()` for changing colors without changing current opacity level. `sethue()` and `setcolor()` return the three or four values that were used: -```jldoctest +```julia julia> setcolor(sethue("red")..., .8) (1.0N0f8, 0.0N0f8, 0.0N0f8, 0.8) diff --git a/src/drawings.jl b/src/drawings.jl index 1b2d193b..f7ecb440 100644 --- a/src/drawings.jl +++ b/src/drawings.jl @@ -1507,7 +1507,7 @@ The default drawing is 256 by 256 points. You don't need `finish()` (the macro calls it), and it's not previewed by `preview()`. -```jldoctest +```julia julia> m = @imagematrix begin sethue("red") box(O, 20, 20, :fill) @@ -1561,7 +1561,7 @@ Transparency The default value for the cells in an image matrix is transparent black. (Luxor's default color is opaque black.) -```jldoctest +```julia julia> @imagematrix begin end 2 2 2×2 reinterpret(ColorTypes.ARGB32, ::Matrix{UInt32}): @@ -1572,7 +1572,7 @@ julia> @imagematrix begin Setting the background to a partially or completely transparent value may give unexpected results: -```jldoctest +```julia julia> @imagematrix begin background(1, 0.5, 0.0, 0.5) # semi-transparent orange end 2 2 @@ -1584,7 +1584,7 @@ julia> @imagematrix begin here the semi-transparent orange color has been partially applied to the transparent background. -```jldoctest +```julia julia> @imagematrix begin sethue(1., 0.5, 0.0) paint() diff --git a/src/hexagons.jl b/src/hexagons.jl index 7cbe2b11..b1fd493b 100644 --- a/src/hexagons.jl +++ b/src/hexagons.jl @@ -215,7 +215,7 @@ For more information about making hexagons and hexagonal grids, see [Luxor.Hexag ## Example -```jldoctest +```julia julia> h = HexagonOffsetEvenR(0, 0, 70.0); julia> hexneighbors(h) diff --git a/src/point.jl b/src/point.jl index 931142b6..33912a68 100644 --- a/src/point.jl +++ b/src/point.jl @@ -54,7 +54,7 @@ Base.length(::Point) = 2 Transform a point `pt` by the 3×3 matrix `m`. -```jldoctest +```julia julia> M = [2 0 0; 0 2 0; 0 0 1] 3×3 Matrix{Int64}: 2 0 0 @@ -362,7 +362,7 @@ Find angle of a line starting at `pointA` and ending at `pointB`. Return a value between 0 and 2pi. Value will be relative to the current axes. -```jldoctest +```julia julia> slope(O, Point(0, 100)) |> rad2deg # y is positive down the page 90.0 @@ -429,7 +429,7 @@ intersectionlinecircle(p1::Point, p2::Point, cpoint::Point, r) = Convert a tuple of two numbers to a Point of x, y Cartesian coordinates. -```jldoctest +```julia julia> @polar 10, pi/4 Point(7.0710678118654755, 7.071067811865475) ``` @@ -452,7 +452,7 @@ end Convert a point specified in polar form (radius and angle) to a Point. -```jldoctest +```julia julia> polar(10, pi/4) Point(7.0710678118654755, 7.071067811865475) ``` diff --git a/src/shapes.jl b/src/shapes.jl index 24d7bbc5..bd3e6b5d 100644 --- a/src/shapes.jl +++ b/src/shapes.jl @@ -341,7 +341,7 @@ drawn below the positive x-axis. If you just want the raw points, use keyword argument `vertices=true`, which returns the array of points. Compare: -```jldoctest +```julia julia> ngon(0, 0, 4, 4, 0, vertices=true) # returns the polygon's points: 4-element Vector{Point}: Point(2.4492935982947064e-16, 4.0) diff --git a/src/tiles-grids.jl b/src/tiles-grids.jl index cc871af3..d451726c 100644 --- a/src/tiles-grids.jl +++ b/src/tiles-grids.jl @@ -135,7 +135,7 @@ For a column, set the `xspacing` to 0: grid = GridRect(O, 0, 40) To get points from the grid, use `nextgridpoint(g::Grid)`. -```jldoctest +```julia julia> grid = GridRect(O, 0, 40); julia> nextgridpoint(grid)