Problems with setColor and drawLine

Posted on
  • What am I doing wrong here?

    Bangle.setLCDMode();                                // use normal display mode
      g.clear();
    
      const Width = g.getWidth();
      const Height = g.getHeight();
      
      for (let x = 0; x < Width; x++) {
        g.setColor(x,0,0);
        g.drawLine(x,0, x,Height-1);
      }
    

    In the emulator, the screen is filled with a constant red color - and not the gradient I would expect.

    So where is the mistake?

    Thanks in advance for any help!

    Kind regards,

    Andreas Rozek

  • setColor takes values between 0 and 1, so I think everything is just clipped to maximum red :)

  • Indeed,

    my mind was simply too "embedded"...the following works as expected:

      Bangle.setLCDMode();                                // use normal display mode
      g.clear();
    
      const Width = g.getWidth();
      const Height = g.getHeight();
      
      for (let x = 0; x < Width; x++) {
        let Color = x/Width;
        g.setColor(Color,0,0);
        g.drawLine(x,0, x,Height-1);
      }
    

    Thank you very much for your help!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Problems with setColor and drawLine

Posted by Avatar for Andreas_Rozek @Andreas_Rozek

Actions