Results 1 to 2 of 2

Thread: Howto: generate random Colors for multiple curves (random numbers)

  1. #1
    Join Date
    May 2009
    Location
    Vienna
    Posts
    91
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Howto: generate random Colors for multiple curves (random numbers)

    Hello Everyone!,
    i have to draw some curves in one plot. (~100) and i want to do have different random colors for each curve.

    e.g. i found
    Random random = new Random();
    QColor color = new QColor(random.nextInt(256), random.nextInt(256), random.nextInt(256));


    http://qt.nokia.com/doc/qtjambi-4.5....work-code.html
    http://java.sun.com/javase/6/docs/ap...il/Random.html

    But this java is only working in QT Jambi and wount work in my project??


    Or Is there a better way to do this as shown below:

    for(int i =0; i<size; i++)
    {
    // Generate some Data....
    ...
    //Plot All Data...

    QwtPlotCurve *Curve = new QwtPlotCurve();
    // Set different colors...
    QColor color;
    color.setRgb(i,i,i,i);
    }
    thanks in Advance,
    Astronomy

  2. #2
    Join Date
    May 2009
    Location
    Vienna
    Posts
    91
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Howto: generate random Colors for multiple curves (random numbers)

    Until now i found a minimal working solution (-:
    i am printing periodically the 20 default colors from Qt.

    greetz Astronomy

    MyPrintFunction()
    {
    // this are the numbers of the QT default colors
    int QtColours[]= { 3,2,7,13,8,14,9, 15, 10, 16, 11, 17, 12, 18, 5, 4, 6, 19, 0, 1 };
    int start=0;
    int Index = 0;
    QColor Color;

    for(...search trough all data files...)
    {
    // read out Datafiles...

    // Do calculation....

    // and finally draw the Curves...
    QwtPlotCurve *mycurces = new QwtPlotCurve(Filename);
    #if QT_VERSION >= 0x040000
    mycurces->setRenderHint(QwtPlotItem::RenderAntialiased);
    #endif

    // Set different colors...
    Color.setRgb(QtColours[start]);
    start++;
    if(start == sizeof(QtColours))
    {
    startColour = 0;
    }

    mycurces->setPen(QPen(Color) );
    mycurces->attach(manyGraphs);
    mycurces->setData(Wavelength, Flux);

    }

Similar Threads

  1. Qt large random numbers
    By timmu in forum Qt Programming
    Replies: 11
    Last Post: 31st August 2009, 09:22
  2. QGroupBox appearing in random colors (Qt 3.3)
    By jgver in forum Qt Programming
    Replies: 0
    Last Post: 11th February 2009, 22:16
  3. random
    By raphaelf in forum General Programming
    Replies: 9
    Last Post: 6th June 2007, 13:33
  4. opimize random
    By raphaelf in forum Newbie
    Replies: 2
    Last Post: 16th May 2007, 01:01
  5. Random No Generator in C/C++
    By ankurjain in forum General Programming
    Replies: 1
    Last Post: 6th July 2006, 12:33

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.