-
Notifications
You must be signed in to change notification settings - Fork 72
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
passing more parameters in the Scene function #30
Comments
Hi there! I really appreciate your input about how this currently works - perhaps the design can be improved. (Surely it can!) I’ve noticed the problem before (and it relates to the general theme about avoiding global variables in Julia code for performance reasons). You need to worry only about the initial despatch of the function specified in using Luxor
function drawframe(scene, framenumber, array)
sethue("cyan")
fontsize(200)
text(string(array[framenumber]))
end
function main()
bigarray=collect(rand(1:6, 1000))
m = Movie(400, 400, "test", 1:100)
animate(m, [
Scene(m, (s, f) -> drawframe(s, f, bigarray)) # <————
],
pathname="/tmp/example.gif",
creategif=true)
end
main()
Another technique I use to pass information around is to define a frame function that accepts keyword arguments, as well as the two obligatory arguments:
Then you call the frame functions like this: animate(heartlines, [
Scene(heartlines, backdrop, 1:700),
Scene(heartlines, (s, f) -> frame(s, f, k = 10), 1:50),
Scene(heartlines, (s, f) -> frame(s, f, k = 9), 51:100),
... |
What is the solution to having global variables? Can a formation of a module or struct work? This code you wrote (s, f) -> drawframe(s, f, bigarray)) ,...looks interesting. Could you explain how this is working? Is it a use of 'dispatch' of a function to the correct most applicable method? |
This is using an anonymous function that takes two arguments which is defined to simply call another one that takes 3, thus splicing another argument in. What’s being passed is a function definition (I think). This (s, f) -> drawframe(s, f, bigarray) is a function. The problem being solved here is that you’re passing your new user-defined functions to an previously-defined and compiled function in Luxor that was written expecting any future functions to have two predictable arguments. I’ll have to read the section in the manual about scope and global variables again... I didn’t quite get it last time. ;) |
When using the animate function, the array of Scenes; how can it be used to pass to the different function parameters to 'backdrop'/ 'frame' etc? I would like to pass in data computed in the iterative cycles which is stored in a composite type and although I am not sure this is the best way, to update the state I wish to pass the type through the function calls of each frame
The text was updated successfully, but these errors were encountered: