peterbrittain / asciimatics

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations
Apache License 2.0
3.62k stars 237 forks source link

Is there any way to redraw an image that constantly changes? #293

Closed Sarif-HK closed 3 years ago

Sarif-HK commented 3 years ago

I've tried ColourImageFile but that for some reason only renders it once then doesnt render it ever again, it would probably destroy my CPU if it did so but its a risk im willing to take, is there any way to constantly re render this image and pass it onto a Print effect? Sorry if this isnt the right place to ask questions but I really have no idea where to post this

peterbrittain commented 3 years ago

Hi. For general questions, you can always use the asciimatics lobby on gitter.

I'm not sure what you're asking... ColourImageFile will pull out all the images from an animated image and display them at the desired rate (that you specify as the speed in the Print Effect).

Do you mean that some other application is constantly writing a new (single) image to the file and so you want to be able to read that every time the file changes? If so, you will have to create a new ColourImageFile object each time the file changes. You could do that using a separate thread to monitor the file and build the object as needed. Finally you'd also need to update the Scene in some way to pick up the new object... Easiest way to do that would be to remove the old Print Effect and add a new one for the new image instead.

Sarif-HK commented 3 years ago

Hi. For general questions, you can always use the asciimatics lobby on gitter.

I'm not sure what you're asking... ColourImageFile will pull out all the images from an animated image and display them at the desired rate (that you specify as the speed in the Print Effect).

Do you mean that some other application is constantly writing a new (single) image to the file and so you want to be able to read that every time the file changes? If so, you will have to create a new ColourImageFile object each time the file changes. You could do that using a separate thread to monitor the file and build the object as needed. Finally you'd also need to update the Scene in some way to pick up the new object... Easiest way to do that would be to remove the old Print Effect and add a new one for the new image instead.

Thanks this is exactly what i had in mind, and by that i mean the draw with every update to the file, tomorrow ill give it a go and update you if i have any issues, thanks in advance!

Sarif-HK commented 3 years ago

Hi. For general questions, you can always use the asciimatics lobby on gitter. I'm not sure what you're asking... ColourImageFile will pull out all the images from an animated image and display them at the desired rate (that you specify as the speed in the Print Effect). Do you mean that some other application is constantly writing a new (single) image to the file and so you want to be able to read that every time the file changes? If so, you will have to create a new ColourImageFile object each time the file changes. You could do that using a separate thread to monitor the file and build the object as needed. Finally you'd also need to update the Scene in some way to pick up the new object... Easiest way to do that would be to remove the old Print Effect and add a new one for the new image instead.

Thanks this is exactly what i had in mind, and by that i mean the draw with every update to the file, tomorrow ill give it a go and update you if i have any issues, thanks in advance!

Also i would appreciate it if i could get an example since i tried something similar before and didnt get the expected results, sorry for the inconvenience

peterbrittain commented 3 years ago

For an example of adding and removing effects, see the code to handle the mini map in the ray_casting demo. You just need to do that from another thread and then force an update.

peterbrittain commented 3 years ago

I'm assuming that did the trick.

Sarif-HK commented 3 years ago

Oh yeah, that did work, sorry for not closing the issue myself! Here's the code if anyone needs an example:

def fetchImage(screen):
    image = ColourImageFile(screen, r'FILEHERE', height= screen.height)
    screen.play([Scene([Print(screen, image, y=0)])])

@ManagedScreen
def Main(screen):
    fetcher = thr.Thread(target=fetchImage, daemon=True, args=(screen, ))
    fetcher.start()
    screen.force_update()
    screen.refresh()
    sleep(10)
Main()