Results 1 to 13 of 13

Thread: How to set new Color every time draw() loop is executed?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: How to set new Color every time draw() loop is executed?

    Just assign a qrand() to the r, g, b variables and perform a while cicle, until the randow values are diferent from the range values of the grey color.

    In the case of Krish, and if you would have a maxim limit of curves to draw, like 100, another aproach would be to create a array/list of color's. That way you could give the user the change to personalize each curve color.
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

  2. #2
    Join Date
    Aug 2009
    Location
    Lviv
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to set new Color every time draw() loop is executed?

    Now, I just make simple check whether r, g an b values not equal (instead of while). But there are the colours that are not actually grey but very similar and lays bad on gray. And what does you mean "assign a qrand() to the r, g, b variables? I just do :

    Qt Code:
    1. srand( time(0) );//somewhere in main
    2.  
    3. //and then in function then generate randoms
    4. QColor crand = QColor(rand()%256, rand()%256, rand()%256);
    To copy to clipboard, switch view to plain text mode 

    But I think there are should be standard solutions (algorithms) for good colours combinations.

  3. #3
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Wink Re: How to set new Color every time draw() loop is executed?

    I mean something like:

    Qt Code:
    1. int r;
    2. int g;
    3. int b;
    4.  
    5. //define the followin values for a range of grey defined by you
    6. int r_upper_grey = ...;
    7. int r_lower_grey = ...;
    8. int g_upper_grey = ...;
    9. int g_lower_grey = ...;
    10. int b_upper_grey = ...;
    11. int b_lower_grey = ...;
    12.  
    13. do
    14. {
    15. r= qrand() % 256;
    16. g= qrand() % 256;
    17. b= qrand() % 256;
    18.  
    19. }while ( ( r < r_upper_grey && r > r_lower_grey) &&
    20. ( g < g_upper_grey && g > g_lower_grey) &&
    21. ( b < b_upper_grey && b > b_lower_grey) );
    To copy to clipboard, switch view to plain text mode 

    Get the picture ? Define a range of grey to avoid and keep random the numbers
    until they out of the grey zone
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.