JuliaAnimators/Javis.jl

Add Functionality to Easily Add Images to J-Objects

Open

#388 创建于 2021年8月11日

在 GitHub 查看
 (6 评论) (0 反应) (0 负责人)Julia (50 fork)batch import
enhancementgood first issue

仓库指标

Star
 (847 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Is your feature request related to a problem? Please explain. After some fun experiments today, I realized that we do not have a way to easily add images to J-Objects!

Describe the solution you'd like

Here is the syntax I created for a function call:

JCircle(dog_positions[i], 27; img = readpng("tiny_doggo.png"))

Then, here is what I changed in base Javis to the JCircle function:

JCircle(
    center::Point,
    radius::Real;
    color = "black",
    linewidth = 1,
    action = :stroke,
    img = nothing,
) =
    (
        args...;
        center = center,
        radius = radius,
        color = color,
        linewidth = linewidth,
        action = action,
        img = img,
    ) -> _JCircle(center, radius, color, linewidth, action, img)

and here is the internal method:

function _JCircle(center, radius, color, linewidth, action, img)
    sethue(color)
    setline(linewidth)

    if !isnothing(img)
        circle(center, radius, :stroke)
        circle(center, radius, :clip)
        placeimage(img, center, centered = true)
    else
        circle(center, radius, action)
    end

    return center
end

Describe alternatives you've considered

I considered writing an external function outside of Javis to do this, but it felt like too much work for such a small new feature addition. Then, I thought about creating a new base Javis function. That didn't make much sense as it is not much different from the base JCircle J-Object implementation. So, I added it to the base Javis JCircle definition.

What do you think @Wikunia and @Sov-trotter ? I tested out the above changes and none of the tests we had in place failed using this new functionality.

贡献者指南