Implementing Color Fading Effects on Text in ProBuilder

01 Sep 2019
0 comment
0 attachment

This ProBuilder code snippet demonstrates how to create a fading color effect on text by adjusting the alpha transparency. The example uses a series of `DrawText` functions to display text with decreasing levels of opacity, creating a visual fade-out effect.


BACKGROUNDCOLOR(0,0,0) // color unimportant
R=235 // 1st 235
G=235 // 2nd 235
B=255 // last can have 255
Fade0=255 // bright
Fade1=128 // bit less
Fade2=64 // more less
Fade3=32 // even more less
Fade4=0 // invisible
DrawText("■",barindex,0.4,Monospaced,Bold,30) coloured(R,G,B,Fade0)
DrawText("■",barindex,0.2,Monospaced,Bold,30) coloured(R,G,B,Fade1)
DrawText("■",barindex,0,Monospaced,Bold,30) coloured(R,G,B,Fade2)
DrawText("■",barindex,-0.2,Monospaced,Bold,30) coloured(R,G,B,Fade3)
DrawText("■",barindex,-0.4,Monospaced,Bold,30) coloured(R,G,B,Fade4)
Return

The code snippet above uses several key functions and properties:

  • BACKGROUNDCOLOR: Sets the background color of the chart. Here, it is set to black (0,0,0).
  • RGB Values: Defines the color of the text. The RGB values used are close to white, with a slight emphasis on blue (R=235, G=235, B=255).
  • Fade Variables: These variables control the alpha transparency of the text color. Starting from fully opaque (Fade0=255) to completely transparent (Fade4=0).
  • DrawText: This function is used to draw text on the chart. It takes parameters for the text character, position on the x-axis (barindex), vertical position (y-axis), font style (Monospaced, Bold), font size (30), and the color including the alpha transparency.
  • The text character “■” (a solid square block) is used to better visualize the fading effect.
  • The vertical positions (0.4 to -0.4) are adjusted to spread the text blocks vertically, enhancing the visual representation of fading.

This example is useful for developers looking to implement visual effects in their ProBuilder applications, particularly for enhancing the UI elements with dynamic color changes.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/backgroundcolor-limits-white-drawing-color/#post-41150

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
AVT Senior
Currently debugging life, so my bio is on hold. Check back after the next commit for an update.
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
33
indicator
132
strategy
171

Recent Snippets

How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Calculating Break-Even Points in ProBuilder
strategy
This ProBuilder code snippet demonstrates how to calculate the break-even point for a trading position. The break-even [...]
Implementing Time and Day Restrictions in Trading Algorithms
strategy
This code snippet demonstrates how to set restrictions on trading activities based on specific days of the week and [...]
Implementing Partial Position Closure Based on Price Retracement in ProBuilder
strategy
This code snippet demonstrates how to partially close a trading position when the price retraces to a certain level in [...]
Logo Logo
Loading...