How do I make a rainbow drawing line

I would like to make my sprite draw a rainbow line

I do not think that X can currently do that. You would need simple plot capacity, the means to draw a line from a position (X1,Y1) to (X2,Y2), with a colour control. That exists in Classic, but not in X.
(And I even wrote the logic to generate the RGB spectral distribution from deep red to violet, in a continuous fashion; so sorry, you cannot use it)

Edit: looks I was wrong and that the drawing of a line was recently added (still missing however is the writing of text, the sampling of pixel colour at (x,y), and the event for canvas touch at location (x,y)).

Here is how you mix colour:

This is taken form a Classic application, but should be adaptable to X.

You call up “spectrum” with argument “Hue” ranging from 0 (for deep red) to 1 (for deep violet).The “Alpha” value would control how transparent the colour would be (showing the background shade or blocking it entirely) you may decide to omit this, or to selectively have it set to a very low value for the 0.0 to 0.1 and 0.9 to 1.0 range, as those appear almost black. The Alpha setting exists in Classic to specify a colour using optional RGBA components (as opposed to only RGB). This does not exist in X, so you may have to use colour blending instead (bending with the background value)
The darker shades in that range are hard to distinguish, so for a more colourful display, you may want to restrict the hue between 0.1 and 0.9.
Note that this is a continuous function, based on the digitization of the actual spectrum, if you want to go from red to violet in 100 pixels, that means you should paint one pixel at 0.01, then one at 0.02 and so on. In 200 pixels, you go with 0.005 increments (1/200). Mathematical analysis of the function shows that you will need to have over 400 steps before two adjacent colours end up being indistinguishable, in the blue portion of the spectrum.

1 Like

Check it

1 Like

I think some of the blocks got moved around?

I can move the sprite and pull up a color pallate but not draw.

I showed an example of a rainbow output. If you need to draw with such a line, then you need to independently implement the line drawing, and then apply a gradient when displaying individual sections of the line. Since there is no event handler for moving a Polish across the canvas, you can only draw broken lines.


The Alpha setting exists in Classic to specify a colour using optional RGBA components (as opposed to only RGB). This does not exist in X,

RGBA exists in Thunkable X.

1 Like

The only colour making component is “color with red, green, blue”, lacking the possibility of adding an alpha channel (and with the mouse hover information claiming that the values having to be between 0 and 100 when the default example has the red at 255 and the green at 128).
One can presumably mix the colour with the background, but that involves knowing what the background current value is, which cannot be directly determined if there is anything besides the default background since there is not component to extract the current value at position (x,y).

Kindly educate me here.

How to set a color besides using a color block?


Transparency changes from 0 to 1. It is also possible to set the format to #rgb, #rgba, HSL (hue, saturation, brightness) or HSLA (with transparency component), for example:

hsl(200, 100%, 50%)
hsla(200, 100%, 50%, 0.1)

Transparent color can be set as follows:

rgba(0,0,0,0) or the string “transparent”.


How can I do broken colour changing then? Would the changes have to be timed?

That is setting a label colour. We are talking about setting the colour of a line being plotted in a canvas.

Or are you suggesting that one sets the colour in a different and unrelated component only to then import it as the colour of the plot?

I showed an example of setting color in different ways. Have you tried the RGBA method and the color of the line for the canvas has not changed?