From 8f62037e362c8682cfaa5ef8575b549a3320fa7e Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Sat, 14 Aug 2021 14:23:51 -0400 Subject: [PATCH 01/21] Exported the JImage function from the JImage shorthand --- src/Javis.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Javis.jl b/src/Javis.jl index 719fcbff7..2c2b976d2 100644 --- a/src/Javis.jl +++ b/src/Javis.jl @@ -682,6 +682,7 @@ include("shorthands/JEllipse.jl") include("shorthands/JStar.jl") include("shorthands/JPoly.jl") include("shorthands/JShape.jl") +include("shorthands/JImage.jl") export render, latex export Video, Object, Background, Action, RFrames, GFrames @@ -696,7 +697,7 @@ export act! export anim_translate, anim_rotate, anim_rotate_around, anim_scale export @Frames, prev_start, prev_end, startof, endof -export JBox, JCircle, JEllipse, JLine, JPoly, JRect, JStar, @JShape +export JBox, JCircle, JEllipse, JImage, JLine, JPoly, JRect, JStar, @JShape # custom override of luxor extensions export setline, setopacity, fontsize, get_fontsize, scale, text From f1e0822624865e753f2e0178057d353a759c8fc1 Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Sat, 14 Aug 2021 14:24:24 -0400 Subject: [PATCH 02/21] Possible implementation of adding an image easily to JObjects --- src/shorthands/JImage.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/shorthands/JImage.jl diff --git a/src/shorthands/JImage.jl b/src/shorthands/JImage.jl new file mode 100644 index 000000000..dbb8ba015 --- /dev/null +++ b/src/shorthands/JImage.jl @@ -0,0 +1,17 @@ +function _JImage(pos, img, centering, clipargs, clipshape) + if clipshape != false + clipshape(clipargs...) + end + placeimage(img, pos, centered = centering) + return pos +end + +JImage(pos::Point, img, centering = true; clipargs = (), clipshape = false) = + ( + args...; + pos = pos, + img = img, + centering = centering, + clipargs = clipargs, + clipshape = clipshape, + ) -> _JImage(pos, img, centering, clipargs, clipshape) From e1f5cd8b4c3125ff02fd42d2131696ba65491961 Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Sat, 14 Aug 2021 15:25:05 -0400 Subject: [PATCH 03/21] Made argument names less confusing --- src/shorthands/JImage.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/shorthands/JImage.jl b/src/shorthands/JImage.jl index dbb8ba015..e4db2ca79 100644 --- a/src/shorthands/JImage.jl +++ b/src/shorthands/JImage.jl @@ -1,17 +1,17 @@ -function _JImage(pos, img, centering, clipargs, clipshape) - if clipshape != false - clipshape(clipargs...) +function _JImage(pos, img, centering, shapeargs, shape) + if shape != false + shape(shapeargs...) end placeimage(img, pos, centered = centering) return pos end -JImage(pos::Point, img, centering = true; clipargs = (), clipshape = false) = +JImage(pos::Point, img, centering = true; shapeargs = (), shape = false) = ( args...; pos = pos, img = img, centering = centering, - clipargs = clipargs, - clipshape = clipshape, - ) -> _JImage(pos, img, centering, clipargs, clipshape) + shapeargs = shapeargs, + shape = shape, + ) -> _JImage(pos, img, centering, shapeargs, shape) From 7ffc1ba5db601b6bee82cff22124ca302913b5aa Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Mon, 27 Sep 2021 22:07:45 -0400 Subject: [PATCH 04/21] Added scaling capabilities --- src/shorthands/JImage.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/shorthands/JImage.jl b/src/shorthands/JImage.jl index e4db2ca79..fc01d0a58 100644 --- a/src/shorthands/JImage.jl +++ b/src/shorthands/JImage.jl @@ -1,12 +1,13 @@ -function _JImage(pos, img, centering, shapeargs, shape) +function _JImage(pos, img, centering, shapeargs, shape, scaleargs) if shape != false shape(shapeargs...) end + scale(scaleargs) placeimage(img, pos, centered = centering) return pos end -JImage(pos::Point, img, centering = true; shapeargs = (), shape = false) = +JImage(pos::Point, img, centering = true; shapeargs = (), shape = false, scaleargs = 1) = ( args...; pos = pos, @@ -14,4 +15,5 @@ JImage(pos::Point, img, centering = true; shapeargs = (), shape = false) = centering = centering, shapeargs = shapeargs, shape = shape, - ) -> _JImage(pos, img, centering, shapeargs, shape) + scaleargs = scaleargs, + ) -> _JImage(pos, img, centering, shapeargs, shape, scaleargs) From e908f6d829ad2a6a89bb8298407bd9d336f6e816 Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Mon, 4 Oct 2021 23:35:27 -0400 Subject: [PATCH 05/21] Added docstring, changed default for shape --- src/shorthands/JImage.jl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/shorthands/JImage.jl b/src/shorthands/JImage.jl index fc01d0a58..21be516d5 100644 --- a/src/shorthands/JImage.jl +++ b/src/shorthands/JImage.jl @@ -1,5 +1,5 @@ function _JImage(pos, img, centering, shapeargs, shape, scaleargs) - if shape != false + if !isnothing(shape) shape(shapeargs...) end scale(scaleargs) @@ -7,7 +7,15 @@ function _JImage(pos, img, centering, shapeargs, shape, scaleargs) return pos end -JImage(pos::Point, img, centering = true; shapeargs = (), shape = false, scaleargs = 1) = +""" + JImage(pos::Point, img, centering = true; shapeargs = (), shape = nothing, scaleargs = 1) + +Place a given image at a given location as a `Javis` object. +Images can be cropped to different shapes and scaled to different sizes while being placed. + +Returns the position of the image location. +""" +JImage(pos::Point, img, centering = true; shapeargs = (), shape = nothing, scaleargs = 1) = ( args...; pos = pos, From da0184c4b1ac8e0ec41827da47bf18f93c058dbf Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Mon, 4 Oct 2021 23:35:46 -0400 Subject: [PATCH 06/21] In process of adding tests for JImage --- test/shorthands.jl | 91 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/test/shorthands.jl b/test/shorthands.jl index ac236cf0b..8ccb5a9f4 100644 --- a/test/shorthands.jl +++ b/test/shorthands.jl @@ -147,3 +147,94 @@ video = Video(800, 800) rm("images/palette.png") rm("shorthands.gif") end + +@testset "Image Placement" begin + function ground(args...) + background("white") + sethue("black") + end + + Background(1:90, ground) + + circle_img = Object( + 1:5, + JImage( + O, + readpng("image.png"), + true; + shape = circle, + shapeargs = nothing, + scaleargs = 1, + ), + ) + poly_img = Object( + 1:10, + JImage( + O, + readpng("image.png"), + true; + shape = poly, + shapeargs = nothing, + scaleargs = 1, + ), + ) + rect_img = Object( + 1:15, + JImage( + O, + readpng("image.png"), + true; + shape = rect, + shapeargs = nothing, + scaleargs = 1, + ), + ) + star_img = Object( + 1:20, + JImage( + O, + readpng("image.png"), + true; + shape = star, + shapeargs = nothing, + scaleargs = 1, + ), + ) + ellipse_img = Object( + 1:25, + JImage( + O, + readpng("image.png"), + true; + shape = ellipse, + shapeargs = nothing, + scaleargs = 1, + ), + ) + box_img = Object( + 1:30, + JImage( + O, + readpng("image.png"), + true; + shape = box, + shapeargs = nothing, + scaleargs = 1, + ), + ) + + render(video; tempdirectory = "images", pathname = "shorthands.gif") + + for i in ["01", 20, 21, 39, 40, 59, 65, 85] + @test_reference "refs/shorthands$i.png" load("images/00000000$i.png") + @test isfile("shorthands.gif") + end + + for i in 1:90 + rm("images/$(lpad(i, 10, "0")).png") + end + + rm("images/palette.png") + rm("shorthands.gif") + +end From c8911180fde40e0fbbaaab0db8b4230f06e78b1d Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Wed, 29 Dec 2021 20:40:51 -0500 Subject: [PATCH 07/21] Added type signature from Cairo --- src/Javis.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Javis.jl b/src/Javis.jl index 86f56a8db..06f7c9bc1 100644 --- a/src/Javis.jl +++ b/src/Javis.jl @@ -1,7 +1,7 @@ module Javis using Animations -import Cairo: CairoImageSurface, image +import Cairo: CairoImageSurface, CairoSurfaceBase, image using FFMPEG using Gtk using GtkReactive From 27620ba0a14208fb694f0debb1b2abef8ef6b74b Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Wed, 29 Dec 2021 20:41:08 -0500 Subject: [PATCH 08/21] Reference image for JImage --- test/refs/dispatch.png | Bin 0 -> 15481 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/refs/dispatch.png diff --git a/test/refs/dispatch.png b/test/refs/dispatch.png new file mode 100644 index 0000000000000000000000000000000000000000..4ebf9d5cd9fcd3deedd6af265f49a4286a560cbe GIT binary patch literal 15481 zcmb8Wby!th*Efoif*^{3goKpT29%Z#iA@OzN{93Yqy?lzqy&^s>6X}ZcSv`4w@5df zxxAm}Iq&<``OY6)7kjNaN6#^SW309Ol@z3Ku}QH}P*8AXq$QM5P;PO9zZ)zJaAihw zZv+K}3PnajRP{srPJ)xYs?qh$E*}P;%X>w%!*{KcPC-~d3*mPpsKSEZiJ`>Mx)Y#2 z${uuw-_homwr->qc{&mO`5nFBbDJGzB1A6LA`=nSH-$UeJ|EpZOpC;&R~2riFS;+> zdbhARKD#D5{|;QMR1Bj<6MYz?va)j6bGmovQ!nf`SU~CKLguDn zUUadJ5=~Tqm*F0HQh_gCsjQY0Hdr@V;E_9b5%E%-Vf5#hd3-b*U8dO&-oamdhcd6u z2TZP3(v82@S>Dv&;Dw|;zq#f?^QH2$IM^A^K8z8(y*1~u^^;5JU`z4FZIh8-@Eumd zox5qp7Gq*oSf48Br8GAj-50;A#hq1`U0-dqQ;VUT6cJm8kQ%W=Z~Ei*;{i&1o1KCGvXZd&|)c7JU>oNb$7SK>DeALX=+;EuD?dF zq{cGPRiNaT&=oiehrctPbrW1%lgjihft8N(5)i#KnRUjr6~}KmCMS88wxbqVJez%X zHXy_7;}|#n<(}_2J{po$H-vO$-^o1jcx!A^#H&=5mL3xPP1LS>o^9Z8-5#ZB`EabJ zRUEe{xcqAkM_9OhF1h3KhVANdy(ImKxtxjcITm1)wnH8gQZA!+TxW6N{)fs} z)1pT%4g*PzHR$5bYyT_%HF}XpMl0GZ4N-<;NkF%snPdY#|Izu@H?mJuPOGQU99GWd z$KKC1E#z(E1j!7<@t1o)a_D(>r5`6=UnRgwhi=`nr)S59ZX9108U<=DoAv0V>P(wK%ePfRhz9slb)c!%_v4;xr+PrO%A;=-p+T zPNKIHg{ac4r+X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+Q60S6^joapEp30?;b!l?)AKb zL2qEV0jeH8X;YkR>UZ-*w@6@OUhfm@P6qzie3-66#G@UF@bKc+R#j+-zyXgRG0mcW za{H6Yqp>KKWOKP9$?$k4Lah8}PyJwKrQ>{`V-ks3lI(o(L{0r%lwJQ&F?@Xeq zA}6`iSQ$fxL#*8MVpjy*RC)bIx^!h%N1am_}!WsEIY-}-}5e=a3^ zA77>>1B38Z))87MM0>J+#&1!M)wIF>_Er;og`(oEwl%Q3NV>GNu^G#ydU3vmPx@&* zbTa&5j(=ckF*e2ftUGs-!G|w1ho5EYZEWl9HY?+|@MTX_MVS9^Q$y}9G2M25 z5w>9aF6~Vyc!?2At0ag60;!*)*%;+GZ6{T=NaU#f!J`2K_+k9}$(@g10zpL7%dA@O zY+^MGo7)X=*lUszJXmjAY#sjgLt*6RoLJ%ul{sA727K~!_+X^1jj3!) zgOFTqt+{Dk`5o=dBfh~63w3LSSP6CYf{Z}$4UspUJk}HAO`7I)Xzz*O*6P$u)%*iia5B8MY}iUVzLdARNZHnKA- z@4&34v=hjt+*91A9Hf?;#oFIz%Bh+;GT4eV+!#!ewC7_Df|1@;y;+UJfAoo}EHmfl zS93h_q}ZOgY{w1doW$q8oAh!?u>cS_uae{h`6V&sMKXztXFuZ%2houAjQvmW$ww2e z*tt522ZNWjuf=_pEhW%KzLLvuA(5(K(b5h#rGaJjyd(sH$((Fr2BmS8h Date: Wed, 29 Dec 2021 20:41:46 -0500 Subject: [PATCH 09/21] Fixed docstrings --- src/shorthands/JImage.jl | 45 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/src/shorthands/JImage.jl b/src/shorthands/JImage.jl index 21be516d5..a3f853f18 100644 --- a/src/shorthands/JImage.jl +++ b/src/shorthands/JImage.jl @@ -8,14 +8,24 @@ function _JImage(pos, img, centering, shapeargs, shape, scaleargs) end """ - JImage(pos::Point, img, centering = true; shapeargs = (), shape = nothing, scaleargs = 1) + JImage(pos::Point, img::CairoSurfaceBase{UInt32}, centering = true; shapeargs = (), shape = nothing, scaleargs = 1) Place a given image at a given location as a `Javis` object. Images can be cropped to different shapes and scaled to different sizes while being placed. -Returns the position of the image location. +# Arguments +- `pos::Point`: Where to place the image inside a shape. +- `img::CairoSurfaceBase{UInt32}`: Expects a CairoSurfaceBase object via `readpng("your_image.png")` +- `centering::Bool`: Centers the object at `pos` +- `shapeargs`: Arguments to be passed to a given shape type +- `shape`: A Luxor shape function such as `circle`, `box`, etc. +- `scaleargs`: The arguments used for scaling the image used on the shape + +# Return + +Returns the position of the image location, `pos`. """ -JImage(pos::Point, img, centering = true; shapeargs = (), shape = nothing, scaleargs = 1) = +JImage(pos::Point, img::CairoSurfaceBase{UInt32}, centering::Bool = true; shapeargs = (), shape = nothing, scaleargs = 1) = ( args...; pos = pos, @@ -25,3 +35,32 @@ JImage(pos::Point, img, centering = true; shapeargs = (), shape = nothing, scale shape = shape, scaleargs = scaleargs, ) -> _JImage(pos, img, centering, shapeargs, shape, scaleargs) + +""" + JImage(pos::Point, img::CairoSurfaceBase{UInt32}, centering = true; shapeargs = (), shape = nothing, scaleargs = 1) + +Place a given image at a given location as a `Javis` object. +Images can be cropped to different shapes and scaled to different sizes while being placed. + +# Arguments +- `pos::Point`: Where to place the image inside a shape +- `img::String`: Expects the path to an image +- `centering::Bool`: Centers the object at `pos` +- `shapeargs`: Arguments to be passed to a given shape type +- `shape`: A Luxor shape function such as `circle`, `box`, etc. +- `scaleargs`: The arguments used for scaling the image used on the shape + +# Return + +Returns the position of the image location, `pos`. +""" +JImage(pos::Point, img::String, centering::Bool = true; shapeargs = (), shape = nothing, scaleargs = 1) = + ( + args...; + pos = pos, + img = readpng(img), + centering = centering, + shapeargs = shapeargs, + shape = shape, + scaleargs = scaleargs, + ) -> _JImage(pos, img, centering, shapeargs, shape, scaleargs) From 6017adc81bb7cb650c9c58d016b6bd99e6c4c9f1 Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Wed, 29 Dec 2021 20:44:30 -0500 Subject: [PATCH 10/21] Revised using dispatch image --- test/shorthands.jl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/shorthands.jl b/test/shorthands.jl index 8ccb5a9f4..5e168553c 100644 --- a/test/shorthands.jl +++ b/test/shorthands.jl @@ -148,6 +148,7 @@ video = Video(800, 800) rm("shorthands.gif") end +video = Video(800, 800) @testset "Image Placement" begin function ground(args...) background("white") @@ -160,7 +161,7 @@ end 1:5, JImage( O, - readpng("image.png"), + readpng("refs/dispatch.png"), true; shape = circle, shapeargs = nothing, @@ -171,7 +172,7 @@ end 1:10, JImage( O, - readpng("image.png"), + readpng("refs/dispatch.png"), true; shape = poly, shapeargs = nothing, @@ -182,7 +183,7 @@ end 1:15, JImage( O, - readpng("image.png"), + readpng("refs/dispatch.png"), true; shape = rect, shapeargs = nothing, @@ -193,7 +194,7 @@ end 1:20, JImage( O, - readpng("image.png"), + readpng("refs/dispatch.png"), true; shape = star, shapeargs = nothing, @@ -204,7 +205,7 @@ end 1:25, JImage( O, - readpng("image.png"), + readpng("refs/dispatch.png"), true; shape = ellipse, shapeargs = nothing, @@ -215,7 +216,7 @@ end 1:30, JImage( O, - readpng("image.png"), + readpng("refs/dispatch.png"), true; shape = box, shapeargs = nothing, From 68a452a990f29cf920f13865e229cfb66182ea68 Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Tue, 4 Jan 2022 22:37:58 -0500 Subject: [PATCH 11/21] Added TODO for scaling logic --- src/shorthands/JImage.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/shorthands/JImage.jl b/src/shorthands/JImage.jl index a3f853f18..1c0045752 100644 --- a/src/shorthands/JImage.jl +++ b/src/shorthands/JImage.jl @@ -1,3 +1,5 @@ +# TODO: Add scaling logic for each shape; see https://github.com/JuliaAnimators/Javis.jl/pull/399#issuecomment-1003549900 for details on what to do + function _JImage(pos, img, centering, shapeargs, shape, scaleargs) if !isnothing(shape) shape(shapeargs...) From 36bbcbda46d5481809636289874edffee390bd92 Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Tue, 4 Jan 2022 22:38:13 -0500 Subject: [PATCH 12/21] Temporary disabling of tests --- test/runtests.jl | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 849f1dfd3..0ff074ca8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -35,28 +35,28 @@ function circle_with_color(position, radius, action, color) end @testset "Javis" begin - @testset "Unit" begin - include("unit.jl") - end - @testset "SVG LaTeX tests" begin - include("svg.jl") - end - @testset "Animations" begin - include("animations.jl") - end - @testset "Morphing" begin - include("morphing.jl") - end - @testset "Javis Viewer" begin - include("viewer.jl") - end + # @testset "Unit" begin + # include("unit.jl") + # end + # @testset "SVG LaTeX tests" begin + # include("svg.jl") + # end + # @testset "Animations" begin + # include("animations.jl") + # end + # @testset "Morphing" begin + # include("morphing.jl") + # end + # @testset "Javis Viewer" begin + # include("viewer.jl") + # end @testset "Shorthands" begin include("shorthands.jl") end - @testset "Layers" begin - include("layers.jl") - end - @testset "Postprocessing" begin - include("postprocessing.jl") - end + # @testset "Layers" begin + # include("layers.jl") + # end + # @testset "Postprocessing" begin + # include("postprocessing.jl") + # end end From 5811f1a7267776d0e5987fcbf684de0e3f36c410 Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Tue, 4 Jan 2022 22:38:52 -0500 Subject: [PATCH 13/21] Added TODO for tests, fixed test cases, and fixed references --- test/shorthands.jl | 70 ++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/test/shorthands.jl b/test/shorthands.jl index 5e168553c..879a7ce9d 100644 --- a/test/shorthands.jl +++ b/test/shorthands.jl @@ -148,14 +148,15 @@ video = Video(800, 800) rm("shorthands.gif") end -video = Video(800, 800) -@testset "Image Placement" begin +video = Video(400, 400) +origin(Point(200, 200)) +@testset "JImage for J-Objects" begin function ground(args...) background("white") sethue("black") end - Background(1:90, ground) + Background(1:30, ground) circle_img = Object( 1:5, @@ -164,76 +165,83 @@ video = Video(800, 800) readpng("refs/dispatch.png"), true; shape = circle, - shapeargs = nothing, + shapeargs = (pt = O, r = 40, action = :clip), scaleargs = 1, ), ) poly_img = Object( - 1:10, + 6:10, JImage( O, readpng("refs/dispatch.png"), true; shape = poly, - shapeargs = nothing, + shapeargs = ( + pointlist = [ + Point(-100, 0), + Point(0, -100), + Point(100, 0), + Point(80, 100), + Point(-80, 100), + ], + action = :clip, + ), scaleargs = 1, ), ) - rect_img = Object( - 1:15, + box_img = Object( + 11:15, JImage( O, readpng("refs/dispatch.png"), true; - shape = rect, - shapeargs = nothing, + shape = box, + shapeargs = (points = [O, Point(-100, -100)], action = :clip), scaleargs = 1, ), ) star_img = Object( - 1:20, + 16:20, JImage( O, readpng("refs/dispatch.png"), true; shape = star, - shapeargs = nothing, + shapeargs = ( + center = O, + radius = 100, + npoints = 5, + ratio = 0.5, + orientation = 0, + action = :clip, + ), scaleargs = 1, ), ) ellipse_img = Object( - 1:25, + 21:25, JImage( O, readpng("refs/dispatch.png"), true; shape = ellipse, - shapeargs = nothing, - scaleargs = 1, - ), - ) - box_img = Object( - 1:30, - JImage( - O, - readpng("refs/dispatch.png"), - true; - shape = box, - shapeargs = nothing, + shapeargs = (cpt = O, w = 200, h = 100, action = :clip), scaleargs = 1, ), ) render(video; tempdirectory = "images", pathname = "shorthands.gif") - for i in ["01", 20, 21, 39, 40, 59, 65, 85] - @test_reference "refs/shorthands$i.png" load("images/00000000$i.png") - @test isfile("shorthands.gif") + # TODO: Unpack this as individual tests rather than loop + for i in ["01", "06", 11, 16, 21] + @test_reference "refs/jimage$i.png" load("images/00000000$i.png") + # @test isfile("shorthands.gif") end - for i in 1:90 - rm("images/$(lpad(i, 10, "0")).png") - end + # TODO: Add tests for scaling + # for i in 1:90 + # rm("images/$(lpad(i, 10, "0")).png") + # end rm("images/palette.png") rm("shorthands.gif") From 2debc170a4858e09878e6d589cf89ea77688f28e Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Sun, 9 Jan 2022 20:29:43 -0500 Subject: [PATCH 14/21] Added individual tests; working on scaling --- test/shorthands.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/shorthands.jl b/test/shorthands.jl index 879a7ce9d..ac0f4c4e9 100644 --- a/test/shorthands.jl +++ b/test/shorthands.jl @@ -232,11 +232,11 @@ origin(Point(200, 200)) render(video; tempdirectory = "images", pathname = "shorthands.gif") - # TODO: Unpack this as individual tests rather than loop - for i in ["01", "06", 11, 16, 21] - @test_reference "refs/jimage$i.png" load("images/00000000$i.png") - # @test isfile("shorthands.gif") - end + @test_reference "refs/jimage01.png" load("images/0000000001.png") + @test_reference "refs/jimage06.png" load("images/0000000006.png") + @test_reference "refs/jimage11.png" load("images/0000000011.png") + @test_reference "refs/jimage16.png" load("images/0000000016.png") + @test_reference "refs/jimage21.png" load("images/0000000021.png") # TODO: Add tests for scaling # for i in 1:90 From 545268c9d4d2eae0320ab02eedd92a1c82b0326a Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Sun, 9 Jan 2022 20:30:12 -0500 Subject: [PATCH 15/21] Begin adding autoscaling support for JImage --- src/shorthands/JImage.jl | 83 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 7 deletions(-) diff --git a/src/shorthands/JImage.jl b/src/shorthands/JImage.jl index 1c0045752..e7e1df13e 100644 --- a/src/shorthands/JImage.jl +++ b/src/shorthands/JImage.jl @@ -2,9 +2,64 @@ function _JImage(pos, img, centering, shapeargs, shape, scaleargs) if !isnothing(shape) - shape(shapeargs...) + bbox = BoundingBox(shape(shapeargs...)) end - scale(scaleargs) + + if scaleargs == :inset + if Symbol(shape) == :box + boxside = max(boxwidth(bbox), boxheight(bbox)) + imageside = max(img.width, img.height) + + scalefactor = boxside / imageside + + box(bbox, :clip) + + translate(boxmiddlecenter(bbox)) + scale(scalefactor) + elseif Symbol(shape) == :star + bbox = BoundingBox(circle(shapeargs.center, shapeargs.radius * shapeargs.ratio)) + boxside = max(boxwidth(bbox), boxheight(bbox)) + imageside = max(img.width, img.height) + circle(shapeargs.center, shapeargs.radius * shapeargs.ratio, action = :clip) + + scalefactor = boxside / imageside + + translate(boxmiddlecenter(bbox)) + scale(scalefactor) + end + elseif scaleargs == :clip + if Symbol(shape) == :box + boxside = min(boxwidth(bbox), boxheight(bbox)) + imageside = min(img.width, img.height) + + box(bbox, :clip) + + scalefactor = boxside / imageside + + translate(boxmiddlecenter(bbox)) + scale(scalefactor) + elseif Symbol(shape) == :star + boxside = min(boxwidth(bbox), boxheight(bbox)) + imageside = min(img.width, img.height) + + star( + shapeargs.center, + shapeargs.radius, + shapeargs.npoints, + shapeargs.ratio, + shapeargs.orientation, + action = :clip, + ) + + scalefactor = boxside / imageside + + translate(boxmiddlecenter(bbox)) + scale(scalefactor) + end + else + scale(scaleargs) + end + placeimage(img, pos, centered = centering) return pos end @@ -27,7 +82,14 @@ Images can be cropped to different shapes and scaled to different sizes while be Returns the position of the image location, `pos`. """ -JImage(pos::Point, img::CairoSurfaceBase{UInt32}, centering::Bool = true; shapeargs = (), shape = nothing, scaleargs = 1) = +JImage( + pos::Point, + img::CairoSurfaceBase{UInt32}, + centering::Bool = true; + shapeargs = (), + shape = nothing, + scaleargs = :inset, +) = ( args...; pos = pos, @@ -35,11 +97,11 @@ JImage(pos::Point, img::CairoSurfaceBase{UInt32}, centering::Bool = true; shapea centering = centering, shapeargs = shapeargs, shape = shape, - scaleargs = scaleargs, + scaleargs = scaleargs, ) -> _JImage(pos, img, centering, shapeargs, shape, scaleargs) """ - JImage(pos::Point, img::CairoSurfaceBase{UInt32}, centering = true; shapeargs = (), shape = nothing, scaleargs = 1) + JImage(pos::Point, img::String, centering = true; shapeargs = (), shape = nothing, scaleargs = 1) Place a given image at a given location as a `Javis` object. Images can be cropped to different shapes and scaled to different sizes while being placed. @@ -56,7 +118,14 @@ Images can be cropped to different shapes and scaled to different sizes while be Returns the position of the image location, `pos`. """ -JImage(pos::Point, img::String, centering::Bool = true; shapeargs = (), shape = nothing, scaleargs = 1) = +JImage( + pos::Point, + img::String, + centering::Bool = true; + shapeargs = (), + shape = nothing, + scaleargs = :inset, +) = ( args...; pos = pos, @@ -64,5 +133,5 @@ JImage(pos::Point, img::String, centering::Bool = true; shapeargs = (), shape = centering = centering, shapeargs = shapeargs, shape = shape, - scaleargs = scaleargs, + scaleargs = scaleargs, ) -> _JImage(pos, img, centering, shapeargs, shape, scaleargs) From 80ca14e3f1a191fa214587f5410ac91d86cc42a5 Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Sun, 16 Jan 2022 18:37:45 -0500 Subject: [PATCH 16/21] Added image support dispatch for JBox --- src/shorthands/JBox.jl | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/shorthands/JBox.jl b/src/shorthands/JBox.jl index 27c002b4f..1b3200b1e 100644 --- a/src/shorthands/JBox.jl +++ b/src/shorthands/JBox.jl @@ -117,3 +117,73 @@ JBox( color = color, action = action, ) -> _JBox(pt, width, height, cornerradius, color, action) + +""" +TODO: Add documentation +""" +JBox( + pt::Point, + width::Real, + height::Real, + color = "", + action = :stroke, + vertices::Bool = false, + image_path::String = "", + scale_factor::Symbol = :inset, +) = + ( + args...; + pt = pt, + width = width, + height = height, + color = color, + action = action, + vertices = vertices, + image_path = image_path, + scale_factor = scale_factor, + ) -> _JBox(pt, width, height, color, action, vertices, image_path, scale_factor) + +function _JBox( + pt::Point, + width::Real, + height::Real, + color, + action::Symbol, + vertices::Bool, + image_path::String, + scale_factor::Symbol, +) + bbox = BoundingBox(box(pt, width, height, :path, vertices = vertices)) + + if !isnothing(color) + sethue(color) + box(pt, width, height, :fill, vertices = vertices) + end + + img = readpng(image_path) + + if scale_factor == :inset + boxside = max(boxwidth(bbox), boxheight(bbox)) + imageside = max(img.width, img.height) + + scaling = boxside / imageside + + box(bbox, :clip) + + translate(boxmiddlecenter(bbox)) + scale(scaling) + elseif scale_factor == :clip + boxside = min(boxwidth(bbox), boxheight(bbox)) + imageside = min(img.width, img.height) + + box(bbox, :clip) + + scaling = boxside / imageside + + translate(boxmiddlecenter(bbox)) + scale(scaling) + end + + placeimage(img, pt, centered = true) + return Point(pt.x - width / 2, pt.y + height / 2) +end From 92f36cab13d0b6391b331ed2f83b5e61d1a2524e Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Sun, 16 Jan 2022 18:37:59 -0500 Subject: [PATCH 17/21] Added image support dispatch for JPoly --- src/shorthands/JPoly.jl | 70 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/src/shorthands/JPoly.jl b/src/shorthands/JPoly.jl index dd2df48ef..cf5b4a2e5 100644 --- a/src/shorthands/JPoly.jl +++ b/src/shorthands/JPoly.jl @@ -13,7 +13,7 @@ Draw a polygon around points in the pointlist. - `color` specifies the color of the outline or the fill of it (depends on action) - `linewidth` linewidth of the outline - `action` can be `:stroke`, `:fill` or other symbols (check the Luxor documentation for details) (default: :stroke) -- `close` whether the polygon should be closed or not (default: closed) +- `close` whether the polygon should be closed or not (default: closed) - `reversepath` can be set to `true` to reverse the path and create a polygon hole """ JPoly( @@ -31,3 +31,71 @@ JPoly( linewidth = linewidth, action = action, ) -> _JPoly(pointlist, color, linewidth, action, close, reversepath) + +""" +TODO: Add documentation +""" +JPoly( + pointlist, + color = "white", + linewidth = 1, + action = :stroke, + close = true, + reversepath = false, + image_path = "", + scale_factor = :inset, +) = + ( + args...; + pointlist = pointlist, + color = color, + linewidth = linewidth, + action = action, + image_path = image_path, + scale_factor = scale_factor, + ) -> _JPoly( + pointlist, + color, + linewidth, + action, + close, + reversepath, + image_path, + scale_factor, + ) + +function _JPoly( + pointlist, + color, + linewidth, + action, + close, + reversepath, + image_path, + scale_factor, +) + img = readpng(image_path) + bbox = BoundingBox(poly(pointlist, :path)) + + if !isnothing(color) + sethue(color) + setline(linewidth) + poly(pointlist, action; close = close, reversepath = reversepath) + end + + if scale_factor == :inset + boxside = max(boxwidth(bbox), boxheight(bbox)) + imageside = max(img.width, img.height) + elseif scale_factor == :clip + boxside = min(boxwidth(bbox), boxheight(bbox)) + imageside = min(img.width, img.height) + end + + poly(pointlist, :clip) + scalefactor = boxside / imageside + + translate(boxmiddlecenter(bbox)) + scale(scalefactor) + placeimage(img, centered = true) + +end From 6e91da7c7bbfa030f5b7ec3958f07d4efa1b1047 Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Sun, 16 Jan 2022 18:38:42 -0500 Subject: [PATCH 18/21] Added image support dispatch for JStar --- src/shorthands/JStar.jl | 94 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/src/shorthands/JStar.jl b/src/shorthands/JStar.jl index 306e5cbcb..a0dcc498a 100644 --- a/src/shorthands/JStar.jl +++ b/src/shorthands/JStar.jl @@ -20,7 +20,7 @@ end 2. JStar(xcenter, ycenter, radius; kwargs...) - same as 1. with `center = Point(xcenter, ycenter)` -Draw a star centered at a position. +Draw a star centered at a position. Return the center of the star. # Keywords for all @@ -65,3 +65,95 @@ JStar( JStar(xcenter, ycenter, radius; kwargs...) = JStar(Point(xcenter, ycenter), radius; kwargs...) + +""" +TODO: Add documentation docstring +""" +JStar( + center::Point, + radius, + color = "black", + linewidth = 1, + npoints = 5, + ratio = 0.5, + orientation = 0, + action = :stroke, + reversepath = false, + image_path = "", + scale_factor = :inset, +) = + ( + args...; + center = center, + radius = radius, + color = color, + linewidth = linewidth, + orientation = orientation, + action = action, + npoints = npoints, + image_path = image_path, + scale_factor = scale_factor, + ) -> _JStar( + center, + radius, + color, + linewidth, + npoints, + ratio, + orientation, + action, + reversepath, + image_path, + scale_factor, + ) + +function _JStar( + center, + radius, + color, + linewidth, + npoints, + ratio, + orientation, + action, + reversepath, + image_path, + scale_factor, +) + img = readpng(image_path) + bbox = BoundingBox( + star(center, radius, npoints, ratio, orientation, :path, reversepath = reversepath), + ) + if !isnothing(color) + sethue(color) + star(center, radius, npoints, ratio, orientation, :fill, reversepath = reversepath) + end + if scale_factor == :inset + bbox = BoundingBox(circle(center, radius * ratio)) + boxside = max(boxwidth(bbox), boxheight(bbox)) + imageside = max(img.width, img.height) + circle(center, radius * ratio, action = :clip) + + scalefactor = boxside / imageside + + translate(boxmiddlecenter(bbox)) + scale(scalefactor) + elseif scale_factor == :clip + boxside = min(boxwidth(bbox), boxheight(bbox)) + imageside = min(img.width, img.height) + + star(center, radius, npoints, ratio, orientation, action = :clip) + + scalefactor = boxside / imageside + + translate(boxmiddlecenter(bbox)) + scale(scalefactor) + end + + sethue(color) + setline(linewidth) + + placeimage(img, center, centered = true) + + return center +end From 2c18b27145c9c43a367b621ea1a518a68dcc0862 Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Sun, 16 Jan 2022 19:51:13 -0500 Subject: [PATCH 19/21] Added image support dispatch for JRect --- src/shorthands/JRect.jl | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/shorthands/JRect.jl b/src/shorthands/JRect.jl index bd76be7cb..4ab98df53 100644 --- a/src/shorthands/JRect.jl +++ b/src/shorthands/JRect.jl @@ -45,3 +45,67 @@ JRect( JRect(xmin::Int64, ymin::Int64, w::Real, h::Real; kwargs...) = JRect(Point(xmin, ymin), w, h; kwargs...) + + +""" +TODO: Add Documentation +""" +JRect( + cornerpoint::Point, + w::Real, + h::Real, + color = "black", + linewidth = 1, + action = :stroke, + image_path = "", + scale_factor = :inset +) = + ( + args...; + cornerpoint = cornerpoint, + w = w, + h = h, + color = color, + linewidth = linewidth, + action = action, + image_path = image_path, + scale_factor = scale_factor + ) -> _JRect(cornerpoint, w, h, color, linewidth, action, image_path, scale_factor) + +function _JRect( + cornerpoint::Point, + w::Real, + h::Real, + color, + linewidth::Real, + action::Symbol, + image_path, + scale_factor +) + bbox = BoundingBox(box(cornerpoint, w, h, :path)) + + if !isnothing(color) + sethue(color) + box(cornerpoint, w, h, :fill) + end + + img = readpng(image_path) + + if scale_factor == :inset + side = minimum([w, h]) + bbox = BoundingBox(box(cornerpoint, side, side, action = :path)) + boxside = max(boxwidth(bbox), boxheight(bbox)) + imageside = max(img.width, img.height) + box(cornerpoint, side, side, action = :clip) + elseif scale_factor == :clip + bbox = BoundingBox(rect(O, w, h, action = :path)) + boxside = min(boxwidth(bbox), boxheight(bbox)) + imageside = min(img.width, img.height) + rect(O, w, h, action = :clip) + end + + translate(boxmiddlecenter(bbox)) + scale(boxside / imageside) + placeimage(img, centered = true) + return cornerpoint +end From d6331a254f576e940af2cb5e16c622c414806e6d Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Sun, 16 Jan 2022 19:51:23 -0500 Subject: [PATCH 20/21] Added image support dispatch for JCircle --- src/shorthands/JCircle.jl | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/shorthands/JCircle.jl b/src/shorthands/JCircle.jl index 638b8c686..fd7488715 100644 --- a/src/shorthands/JCircle.jl +++ b/src/shorthands/JCircle.jl @@ -39,3 +39,58 @@ JCircle(p1::Point, p2::Point; kwargs...) = JCircle(midpoint(p1, p2), distance(p1, p2) / 2; kwargs...) JCircle(radius::Real; kwargs...) = JCircle(O, radius; kwargs...) + +""" +TODO: Add Documentation! +""" +JCircle( + center::Point, + radius::Real, + color = "black", + linewidth = 1, + action = :stroke, + image_path = "", + scale_factor = :inset, +) = + ( + args...; + center = center, + radius = radius, + color = color, + linewidth = linewidth, + action = action, + image_path = image_path, + scale_factor = scale_factor, + ) -> _JCircle(center, radius, color, linewidth, action, image_path, scale_factor) + +function _JCircle(center, radius, color, linewidth, action, image_path, scale_factor) + + bbox = BoundingBox(circle(center, radius, :path)) + + if !isnothing(color) + sethue(color) + circle(center, radius, :fill) + end + + img = readpng(image_path) + + if scale_factor == :inset + side = sqrt((radius * 2)^2 / 2) + bbox = BoundingBox(box(O, side, side, action = :path)) + boxside = max(boxwidth(bbox), boxheight(bbox)) + imageside = max(img.width, img.height) + box(O, side, side, action = :clip) + elseif scale_factor == :clip + bbox = BoundingBox(circle(O, radius, action = :path)) + boxside = min(boxwidth(bbox), boxheight(bbox)) + imageside = min(img.width, img.height) + circle(O, radius, action = :clip) + end + + scalefactor = boxside / imageside + + translate(boxmiddlecenter(bbox)) + scale(scalefactor) + placeimage(img, centered = true) + return center +end From 51dde2c0cc21d863a815e9465fe9cbeb57137c89 Mon Sep 17 00:00:00 2001 From: Jacob Zelko Date: Sun, 16 Jan 2022 19:51:36 -0500 Subject: [PATCH 21/21] Added image support dispatch for JEllipse --- src/shorthands/JEllipse.jl | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/shorthands/JEllipse.jl b/src/shorthands/JEllipse.jl index 894eb348a..d144d665c 100644 --- a/src/shorthands/JEllipse.jl +++ b/src/shorthands/JEllipse.jl @@ -95,3 +95,70 @@ JEllipse( linewidth = linewidth, action = action, ) -> _JEllipse(focus1, focus2, pt, color, linewidth, action, stepvalue, reversepath) + + +""" +TODO: Add documentation +""" +JEllipse( + cpt::Point, + w::Real, + h::Real, + color = "black", + linewidth = 1, + action = :stroke, + image_path::String = "", + scale_factor::Symbol = :inset, +) = + ( + args...; + cpt = cpt, + w = w, + h = h, + color = color, + linewidth = linewidth, + action = action, + image_path = image_path, + scale_factor = scale_factor, + ) -> _JEllipse(cpt, w, h, color, linewidth, action, image_path, scale_factor) + +function _JEllipse( + cpt::Point, + w::Real, + h::Real, + color, + linewidth, + action::Symbol, + image_path::String = "", + scale_factor = :inset, +) + + bbox = BoundingBox(ellipse(O, w, h, :path)) + + if !isnothing(color) + sethue(color) + ellipse(O, w, h, :fill) + end + + img = readpng(image_path) + + if scale_factor == :inset + inset_radius = minimum([w, h]) / 2 + bbox = BoundingBox(circle(O, inset_radius, :path)) + boxside = max(boxwidth(bbox), boxheight(bbox)) + imageside = max(img.width, img.height) + circle(O, inset_radius, :clip) + elseif scale_factor == :clip + boxside = min(boxwidth(bbox), boxheight(bbox)) + imageside = min(img.width, img.height) + ellipse(O, 200, 100, :clip) + end + + scalefactor = boxside / imageside + + translate(boxmiddlecenter(bbox)) + scale(scalefactor) + placeimage(img, centered = true) + return cpt +end +