TradingView
LuxAlgo
7. Jun. 2021 14:32

PineGIF - Display Gifs & Images In Tradingview [LuxAlgo] 

Ethereum / U.S. dollarBitstamp

Beschreibung

Pinescript is not designed to create or display images, let alone gifs, but it's very fun to try, and that's what this script does. This script allows the user to display three different gifs. In this post, we explain how we managed to display images/gif's using pinescript tables.

1. Image Pre-Processing

Due to pinescript limitations, we can't possibly display images with an excessively high resolution. As such we targeted pixel art as a primary image source. We used a pixel art gif of the magnificent Octocat (the mascot for the source-code hosting service GitHub) for our first try.

We first extract each frame from the gif and resize them to a 50x50 resolution which returns frames made of 2500 pixels. This process was done using python.

Getting Individual Pixels RGBA Values

Python can easily return a matrix containing each pixel's rgba value. For convenience, we converted the rgba values to hex.

We then create a simple code allowing us to return a pinescript array containing the 2500 pixel hex colors. We do this process for each frame.

2. Defining Table Cell Color

In the code, each frame is its own array. We create a new table with dimensions equal to len(frame1)^2 (we assume height = width).

The color of a cell is defined by the color of the image pixel at the same exact location. When a new bar is created, we do this exact process using a different frame which ultimately allows a new frame to be displayed.

3. Playing The GIFs

By default, the script will play the gif of the Tradingview cloud logo raining. In order to play the gif, simply use the replay mode. The replay speed allows the user to determine the frame rate (0.1 for the raining cloud and Nyan cat works best, 0.5 for Octocat).

We included the frames of the Octocat and Nyan cat gifs in the script.

4. Some Other Cool Images

Displaying static images is possible and involves the same process described above.







An original idea of the lizard, implemented by the wizard.

Versionshinweise

Minor changes.
Kommentare
Time_Out_2021
Cool !!!
Thank you for publishing this script :)
I wonder what seriously creative scripts can come form this ?
I would like to have an indicator with water waves crashing !
The best charts can now have meme indicators
Pratik_4Clover
That's some fun project, thank you ^^
Gunzo_TV
Wow congratulations ! I didn't knew somebody already tried to display animations on the TradingView platform.
I fully understand the constraints you may had during your development (matrix size, iteration time, etc.), as I'm at the moment also trying to create pixel animations for my next script (still working on optimization at the moment). I would have love to discover you script sooner...
Great work !
Duyck
Hi Alex,
if you use varip and change on close changes, like I did in my "Matrix" script,
tradingview.com/script/sKWZwst3-The-Matrix-JD/

you don't need the "replay" trick for gifs. ;-)

Gr, JD.
alexgrover
@Duyck, we tried using varip, it will generally break after some time, the replay mode proves to be more useful in this special case, at least at the moment :) Thanks for your comment.
ICEKI
Amazing cool and funny post!
Kapil-Mittal
This is so cool mate!
Mehr