Skip to content
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

Feature grid lines aka cartesian coordinate system #422

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

Wikunia
Copy link
Member

@Wikunia Wikunia commented Sep 18, 2021

PR Checklist

If you are contributing to Javis.jl, please make sure you are able to check off each item on this list:

  • Did I update CHANGELOG.md with whatever changes/features I added with this PR?
  • Did I make sure to only change the part of the file where I introduced a new change/feature?
  • Did I cover all corner cases to be close to 100% test coverage (if applicable)?
  • Did I properly add Javis dependencies to the Project.toml + set an upper bound of the dependency (if applicable)?
  • Did I properly add test dependencies to the test directory (if applicable)?
  • Did I check relevant tutorials that may be affected by changes in this PR?
  • Did I clearly articulate why this PR was made the way it was and how it was made?

Link to relevant issue(s)
Closes #38 #302

How did you address these issues with this PR? What methods did you use?
One can now draw a grid given the points for the x and y axis. It's also possible to animate the creation of the grid but it's more an object that is just there now instead of everything build for animation like the current draw_grid function. I also removed the draw_grid function as I don't think it got used as it wasn't possible to have it in an non animated fashion.

An example of using the new coordinate_system function:

cs = coordinate_system(Point(-100, 0), Point(200, 0), Point(0, 100), Point(0, -200); 
                    fct=arrow)
cs_obj = Object(1:nframes, cs())

act!(cs_obj, Action(1:30, appear(cs, :top_left)))

One thing that is a bit not so user friendly is that one needs to both have a variable for the coordinate system cs as well as for the object itself cs_obj to be able to use it in appear.

The PR includes a new folder and file objects/CoordinateSystem.jl and it can be template for similar objects which are of use for several people. Maybe it's something @gpucce is interested in as well for a JUtitls kind of thing.
It uses a callable struct which calls @JShape but saves all the information in a struct which can be then used for animating it. For this you can have a look at the new appear function which is also in the objects/CoordinateSystem.jl file.

@TheCedarPrince let me know what you think about the general idea and I can add some more features like disappear at least but maybe also drawing ticks on the grid. I think a combination together with #412 would be helpful which I can add when one of them gets merged.

As an example for that: Maybe define the coordinate system and pass it in as the 3rd argument of scale_linear which can replace the current 3rd and fourth argument. The other way around might also make sense as then the step size for the grid could be calculated such that there is a line for each increase by 1 in the coordinate system one wants to work with using scale_linear.

Example

using Javis

function ground(args...)
    background("black")
    sethue("white")
end

function sin_curve(cs, left, right; cleft=left, cright=right)
    @JShape begin
        mapping = scale_linear(Point(left,-2), Point(right,2), cs)
        @scale_layer mapping begin
            x = collect(cleft:0.1:cright)
            y = sin.(x)
            circle.(Point.(x,y), 0.02, :fill)
        end
    end cleft=cleft cright=cright
end

function main()
    vid = Video(500, 500)
    nframes = 100
    Background(1:nframes, ground)

    cs = coordinate_system(Point(-100, 0), Point(100, 0), Point(0, 100), Point(0, -100); 
                    fct=arrow, step_size_x=0, step_size_y=0)

    cs_obj = Object(1:nframes, cs())
    sin_obj = Object(31:nframes, sin_curve(cs, -5,5))

    act!(cs_obj, Action(1:30, appear(cs, :top_right)))
    act!(sin_obj, Action(1:30, change(:cright, -5 => 5)))

    render(vid; pathname="grid.gif")
end

grid

New example with easier syntax. One can create the mapping first and design the coordinate_system based on that.

using Javis

function ground(args...)
    background("black")
    sethue("white")
end

function sin_curve(mapping, left, right; cleft=left, cright=right)
    @JShape begin
        @scale_layer mapping begin
            x = collect(cleft:0.1:cright)
            y = sin.(x)
            circle.(Point.(x,y), 0.02, :fill)
        end
    end cleft=cleft cright=cright
end

function main()
    vid = Video(500, 500)
    nframes = 100
    Background(1:nframes, ground)

    xstart = -5
    xend = 5
    coord_size_x = 400
    coord_size_y = 200
    mapping = scale_linear(Point(xstart,-2), Point(xend,2), Point(-coord_size_x/2, coord_size_y/2), Point(coord_size_x/2, -coord_size_y/2))
    cs = coordinate_system(mapping; fct=arrow, step_size_x=1, step_size_y=1)

    cs_obj = Object(1:nframes, cs())
    sin_obj = Object(31:nframes, sin_curve(mapping, xstart, xend))

    act!(cs_obj, Action(1:30, appear(cs, :top_right)))
    act!(sin_obj, Action(1:30, change(:cright, xstart => xend)))

    render(vid; pathname="grid.gif")
end

grid

@Wikunia Wikunia linked an issue Sep 18, 2021 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Sep 18, 2021

Codecov Report

Merging #422 (17346bf) into master (5781699) will decrease coverage by 0.29%.
The diff coverage is 95.27%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #422      +/-   ##
==========================================
- Coverage   96.19%   95.90%   -0.30%     
==========================================
  Files          36       39       +3     
  Lines        1604     1661      +57     
==========================================
+ Hits         1543     1593      +50     
- Misses         61       68       +7     
Impacted Files Coverage Δ
src/Javis.jl 96.03% <ø> (ø)
src/scales.jl 88.88% <85.71%> (-11.12%) ⬇️
src/objects/CoordinateSystem.jl 97.91% <97.91%> (ø)
src/structs/Interval.jl 100.00% <100.00%> (ø)
src/structs/LinearScale.jl 100.00% <100.00%> (ø)
src/structs/objects/CoordinateSystem.jl 100.00% <100.00%> (ø)
src/structs/Frames.jl 95.00% <0.00%> (-1.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5781699...17346bf. Read the comment docs.

@Wikunia Wikunia mentioned this pull request Sep 19, 2021
7 tasks
@Wikunia Wikunia mentioned this pull request Sep 28, 2021
@Wikunia
Copy link
Member Author

Wikunia commented Sep 29, 2021

For anyone subscribed: I've added an example as the main comment. I think it makes sense as a next step to use the scale_linear mapping as an input to the coordinate_system as this could make grid lines easier to map.
Maybe it would be nice to define the scale and use that already as the attributes for the coordinate system such that the definition of the coordinate system is done with input coords and not with canvas coords.

@Wikunia Wikunia changed the base branch from master to main February 25, 2022 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Fixing the grid function Improving Grid Line Animations
1 participant