Treat color as a variable?



  • I was thinking of a project to teach my nephew programming, and wanted to pick a random color from a list by name, but none of the the blocks in Graphic or Screen treat color as a variable.

    I did find this old feature suggestion in the forum, which is how I would expect it to work, given a presumed "set variable to RGB values" block...

    RE: UiFlow interface suggestions

    Is there some other way I am missing?



  • I just checked and if you look at the attached image: 0_1627631253447_Screenshot 2021-07-30 at 08.47.14.png

    It is possible to set variable for the individual colours on a numerical value.



  • Yes, but that only works if you drag a line to the screen and manually pre-define the placement and dimensions. You can then alter those later, but it's just the one line.

    I want to programmatically draw multiple lines (via LCD.line) with random color(s) and there does not seem to be a Blockly way to achieve that (I'd prefer not to delve into executing Python code for this...)



  • Ahh I see.
    No, that just the way the blockly GUI options work in that you have to drag the UI element to the virtual screen to access the functions.
    Have you considered
    0_1627716155995_Screenshot 2021-07-31 at 08.21.26.png

    Which then creates a hidden placeholder line which then give you access to the functions?
    and then you create a function to create a line with a random colour.
    0_1627716826585_Screenshot 2021-07-31 at 08.33.25.png

    Edit Ahh I see, UI line and lcd line have different color functions