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

Output canvas to video or sequence of png's #155

Closed
ReneTC opened this issue Apr 15, 2020 · 7 comments
Closed

Output canvas to video or sequence of png's #155

ReneTC opened this issue Apr 15, 2020 · 7 comments

Comments

@ReneTC
Copy link
Contributor

ReneTC commented Apr 15, 2020

Not sure if it's possible, but I can't find anything online or in the documentation:
I think a useful feature would be to output the canvas to either video or a sequence of png's (maybe with alpha channel).

@jeremydouglass
Copy link
Contributor

I believe that saveFrame() isn't implemented yet -- that it was prototyped in #31 #33 but never reimplemented in vispy.

@arihantparsoya
Copy link
Member

arihantparsoya commented Apr 30, 2020

@ReneTC I have implemented save_frames, does this resolve the issue?

1885fda

@ReneTC
Copy link
Contributor Author

ReneTC commented May 1, 2020

Thank you very much! Do you mind given an example how to use it? I'm new to this package. I tried saving this from the example page:

from p5 import *

x = 0
y = 0
dim = 80.0

def setup():
        size(640, 360)
        no_stroke()

def draw():
        background(102)

        global x
        x = x + 0.8

        if x > width + dim:
                x = -dim

        translate(x, height/2 - dim/2)
        fill(255)
        rect((-dim/2, -dim/2), dim, dim)

        # Transforms accumulate. Notice how this rect moves
        # twice as fast as the other, but it has the same
        # parameter for the x-axis value
        translate(x, dim)
        fill(0)
        rect((-dim/2, -dim/2), dim, dim)

if __name__ == '__main__':
  run()

@arihantparsoya
Copy link
Member

arihantparsoya commented May 1, 2020

Use this code:

from p5 import *

x = 0
y = 0
dim = 80.0

def setup():
    size(640, 360)
    no_stroke()

def draw():
    background(102)

    global x
    x = x + 0.8

    if x > width + dim:
            x = -dim

    translate(x, height/2 - dim/2)
    fill(255)
    rect((-dim/2, -dim/2), dim, dim)

    # Transforms accumulate. Notice how this rect moves
    # twice as fast as the other, but it has the same
    # parameter for the x-axis value
    translate(x, dim)
    fill(0)
    rect((-dim/2, -dim/2), dim, dim)

def mouse_pressed():
	save_frame("export.png")

if __name__ == '__main__':
  run()

when the mouse is pressed, the save_frame() function exports a png file. If you want to save a image file for every frame, put the save_frame function inside draw()

@ReneTC
Copy link
Contributor Author

ReneTC commented May 1, 2020

Thank you for taking the time to help me out. I really appreicate that. Perfect!

@jeremydouglass
Copy link
Contributor

@ReneTC -- great -- can this be closed, then?

@ReneTC
Copy link
Contributor Author

ReneTC commented May 2, 2020

sorry, yes @jeremydouglass

@ReneTC ReneTC closed this as completed May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants