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

Partial drawing of any Object #469

Closed

Conversation

ArbitRandomUser
Copy link
Contributor

@ArbitRandomUser ArbitRandomUser commented Mar 4, 2022

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?
    will add later
  • Did I make sure to only change the part of the file where I introduced a new change/feature?
  • (Hopefully) 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)?
  • (NA) Did I properly add test dependencies to the test directory (if applicable)?
  • (NA) 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 #
#218

How did you address these issues with this PR? What methods did you use?

This PR introduces the "show_creation" function for Action ;
Using Cassette we intercept any call to strokepath , strokepreserve , fillpath and fillpreserve .
they are replaced with custom set of strokes that stroke the path/fill upto a particular fraction.

for example , this bit of code makes ...

using Javis
using Animations
using LaTeXStrings

video=Video(600,600)

function circle_line()
    sethue("red")
    circle(O,100,:stroke)
    sethue("green")
    line(O,O+100,:stroke)
    sethue("blue")
    rect(O-100,50,50,:fill)
    sethue("orange")
    rect(O+100,60,90,:path)
    #the usuall fillstroke calls fill first then stroke
    #the partial drawing happens in the order you call
    #these luxor functions. Since i want the outline
    #first then the fill...
    strokepreserve()
    fillpath()
end

nframes=200
exf=30
Background(1:nframes+exf, (args...)-> background("black"))
obj = Object(1:nframes+exf, (_,_,_)-> ( circle_line());)
act!(obj,Action(1:nframes,linear(),show_creation()))
render(video, pathname="circle_line_rect.gif")

will give ...
circle_line_rect

@ArbitRandomUser ArbitRandomUser changed the title Partial draw branch1 Partial drawing of any Object Mar 4, 2022
@codecov-commenter
Copy link

codecov-commenter commented Mar 4, 2022

Codecov Report

Merging #469 (b8b2bc3) into main (b4fd6bd) will decrease coverage by 1.28%.
The diff coverage is 85.71%.

@@            Coverage Diff             @@
##             main     #469      +/-   ##
==========================================
- Coverage   96.47%   95.18%   -1.29%     
==========================================
  Files          35       36       +1     
  Lines        1617     1829     +212     
==========================================
+ Hits         1560     1741     +181     
- Misses         57       88      +31     
Impacted Files Coverage Δ
src/Javis.jl 96.80% <ø> (-0.08%) ⬇️
src/draw_partial.jl 85.71% <85.71%> (ø)

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 b4fd6bd...b8b2bc3. Read the comment docs.

src/draw_partial.jl Show resolved Hide resolved
Project.toml Show resolved Hide resolved
@ArbitRandomUser
Copy link
Contributor Author

i'm thinking of writing some tests ,

  1. a the animation above in the P.R .
  2. scaling, translating, rotating and fading along with show_creation
  3. anything else ???
    @Wikunia @gpucce @TheCedarPrince @Sov-trotter
    let me know your comments (if any) on other things i should test

@Sov-trotter
Copy link
Member

This looks really solid!
I have one question, can we make it work with the JObject syntax?

@ArbitRandomUser
Copy link
Contributor Author

ArbitRandomUser commented Mar 13, 2022

This looks really solid! I have one question, can we make it work with the JObject syntax?

if you meant something like this ...

using Javis
using Animations

video=Video(600,600)
nframes=100
Background(1:nframes, (args...)-> background("black"))

obj = Object(JCircle(O,100,color="white"))
obj2= Object(JRect(O+100,60.0,90.0,color="orange",action=:fill))

act!(obj,Action(1:nframes,linear(),show_creation()))
act!(obj2,Action(1:nframes,linear(),show_creation()))
render(video, pathname="circle_line_rect.gif")

yup it works outta the box !
circle_line_rect

anything that ultimately calls luxors strokepath/strokepreserve/fillpath/fillpreserve to draw on the canvas will be covered by this

@ArbitRandomUser
Copy link
Contributor Author

i've commited the intermediate refs images , should i commit the gifs that are generated also ?

circle_move_creation
circle_scale_creation
rect_rotate_creation
show_creation

@Wikunia
Copy link
Member

Wikunia commented Mar 14, 2022

Currently we only test reference images and I think that works quite well. If there is anything you can test without images it's always appreciate but often it can't be done.

const dp_state = DrawPartialState([0], 0, 0, true, [], 0)

"""
pathtopoly(co_state::Symbol)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change this to dispatch on value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what symbol should we use though ?

@@ -0,0 +1,474 @@
import Cassette: @context, prehook, overdub
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should move imports into Javis.jl

#polydistance(poly) returns Vector{Float64}
#polydistances.(many_polys) returns Vector{Vector{Float64}}
#stroke_polydists is a vector of this ^, i.e Vector{Vector{Vector{Float64}}}
stroke_polydists::Vector{Vector{Vector{Float64}}} #accumulates polydistances
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was added to improve performance , but i'm not seeing any improvement , maybe i'm doing something wrong ?

(dp_state.target_len_partial - dp_state.cur_len_partial) /
nextpolylength
poly(polyportion(poly_i, frac, closed = co, pdist = pdist_i))
#poly(polyportion(poly_i, frac, closed = co))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there seems to be no difference in performance if i switch this line for the line above (with pdist = pdist_i) ;
atleast for the example i tried (hilbert curve)
we would expect passing the polydistances to polyportion to make it faster .

#hue
#="""for some reason parsing colors fails to furthur overdub , so we just
return as is"""=#
function overdub(c::ctx_strokelength, ::typeof(Colors.parse), args...)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Colors.parse simply doesn't play well with Cassette , might be something related to this JuliaLabs/Cassette.jl#130

@Ved-Mahajan
Copy link
Contributor

WOW, THIS IS ABSOLUTELY BEAUTIFUL!!!

@ArbitRandomUser
Copy link
Contributor Author

ArbitRandomUser commented Aug 17, 2022

feature merged in #482

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants