-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JImage
Implementation for J-Objects
#399
Open
TheCedarPrince
wants to merge
24
commits into
main
Choose a base branch
from
tcp-image-jobjects
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8f62037
Exported the JImage function from the JImage shorthand
TheCedarPrince f1e0822
Possible implementation of adding an image easily to JObjects
TheCedarPrince e1f5cd8
Made argument names less confusing
TheCedarPrince de8f54f
Merge branch 'master' into tcp-image-jobjects
TheCedarPrince 7ffc1ba
Added scaling capabilities
TheCedarPrince e908f6d
Added docstring, changed default for shape
TheCedarPrince da0184c
In process of adding tests for JImage
TheCedarPrince 1ac4713
Merge branch 'master' into tcp-image-jobjects
TheCedarPrince c891118
Added type signature from Cairo
TheCedarPrince 27620ba
Reference image for JImage
TheCedarPrince 80957f1
Fixed docstrings
TheCedarPrince 6017adc
Revised using dispatch image
TheCedarPrince 10c9686
Merge branch 'master' into tcp-image-jobjects
TheCedarPrince 68a452a
Added TODO for scaling logic
TheCedarPrince 36bbcbd
Temporary disabling of tests
TheCedarPrince 5811f1a
Added TODO for tests, fixed test cases, and fixed references
TheCedarPrince 2debc17
Added individual tests; working on scaling
TheCedarPrince 545268c
Begin adding autoscaling support for JImage
TheCedarPrince 80ca14e
Added image support dispatch for JBox
TheCedarPrince 92f36ca
Added image support dispatch for JPoly
TheCedarPrince 6e91da7
Added image support dispatch for JStar
TheCedarPrince 2c18b27
Added image support dispatch for JRect
TheCedarPrince d6331a2
Added image support dispatch for JCircle
TheCedarPrince 51dde2c
Added image support dispatch for JEllipse
TheCedarPrince File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# 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) | ||
bbox = BoundingBox(shape(shapeargs...)) | ||
end | ||
|
||
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) | ||
TheCedarPrince marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return pos | ||
end | ||
|
||
""" | ||
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. | ||
TheCedarPrince marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# 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::CairoSurfaceBase{UInt32}, | ||
centering::Bool = true; | ||
shapeargs = (), | ||
shape = nothing, | ||
scaleargs = :inset, | ||
) = | ||
( | ||
args...; | ||
pos = pos, | ||
img = img, | ||
centering = centering, | ||
shapeargs = shapeargs, | ||
shape = shape, | ||
scaleargs = scaleargs, | ||
) -> _JImage(pos, img, centering, shapeargs, shape, scaleargs) | ||
|
||
""" | ||
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. | ||
|
||
# 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would have |
||
- `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 = :inset, | ||
) = | ||
( | ||
args...; | ||
pos = pos, | ||
img = readpng(img), | ||
centering = centering, | ||
shapeargs = shapeargs, | ||
shape = shape, | ||
scaleargs = scaleargs, | ||
) -> _JImage(pos, img, centering, shapeargs, shape, scaleargs) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently I have no idea what
:inset
and:clip
mean to be honest 😄Seems like
:clip
positions the image somewhere else but I don't really have the option to move the image or have I?Also for me a
scale_factor
is a number and not a symbol. Maybescale_type
or something but I would first need to know what they do to give my comment on that 😄