• Hey!
    I'm trying to stock the RGB color code in variables but I don't know how to use it in an argument like the argument of the g.setColor() function.
    Here is my code

    // set up the parameters of the dial
    var xC = 120;
    var yC = 120;
    var rC = 100;
    
    // define the RGB code for each color
    var red = (1,0,0);
    var blue = (0,0,1);
    var green = (0,1,0);
    var yellow = (1,1,0);
    var cyan = (0,1,1);
    var purple = (1,0,1);
    var pink = (1,0,0.5);
    var pulpit = (1,0.5,0.5);
    var lightBlue = (0.5,0.5,1);
    var lime = (0,1,0.2);
    var orange = (1,0.5,0);
    var darkGreen = (0.2,0.5,0.2);
    var brown = (0.5,0.2,0);
    var bordeaux = (0.4,0,0.2);
    var gris = (0.5,0.5,0.5);
    
    
    function drawCircle() {
     //here is the function where I want to put the variable in argument (this actually doesn't work but its to show you my idea
      g.setColor (blue);
      g.drawCircle(xC, yC, rC);
    }
    
    g.clear();
    drawCircle();
    

    (this code doesn't work )
    I don't know how to transfer the values of one variable in the arguments
    I hope you see what I'm trying to do if not ask me ;)
    Thanks for your help

  • Sun 2021.01.10

    Hi @Guillaume_G chew on this for a while

    The issue appears to be L26 with an incorrect parameter list.



    Espruino reference for setColor() function:

    http://www.espruino.com/Reference#l_Grap­hics_setColor



    This is a great web site to test Javascript concepts:

    Tutorial and Examples along with a 'TryIt' editor

    https://www.w3schools.com/js/js_function­s.asp



    This may also be solved using either Arrays or JSON object notation.

    https://www.w3schools.com/jsref/jsref_en­tries.asp
    https://www.w3schools.com/jsref/jsref_ob­j_json.asp



    If you wish to stay in base10 then these snippets might be one way

    aryRGB =[
      { "r": 255, "g": 0, "b": 0 },
      { "r": 171, "g": 85, "b": 0 },
      { "r": 171, "g": 171, "b": 0 },
      { "r": 0, "g": 255, "b": 0 },
      { "r": 0, "g": 171, "b": 85 },
      { "r": 0, "g": 0, "b": 255 },
      { "r": 85, "g": 0, "b": 171 },
      { "r": 171, "g": 0, "b": 85 }
     ]
    
    
        var aryRGB = new Uint8ClampedArray( this.aryColors.length );
        aryRGB = this.aryColors;
    
    
        var r = aryRGB[i].r;
        var g = aryRGB[i].g;
        var b = aryRGB[i].b;
    
    



    or maybe in hex

    const RGB = {
      
      AliceBlue  : "F0F8FF",
      AntiqueWhite : "FAEBD7",
      Aqua       : "00FFFF",
      Aquamarine : "7FFFD4",
    
        . . . 
    
    
    // User defined functions required to extract each value
    
        this.decR = Color.cvrtHexToDec(this.colorR);
    
    
        var vals = {};
        vals.r = this.decR;
        vals.g = this.decG;
        vals.b = this.decB;
    



    and if you get stuck on the gristle, I'll check back in a few hours to get you over the goal post.

About

Avatar for Guillaume_G @Guillaume_G started