Why is the drawing with striped?

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
In need of some credit
In need of some credit
Posts: 1
Joined: Fri Jun 09, 2017 12:33 am

Why is the drawing with striped?

Post by zj13002 » Fri Jun 09, 2017 12:46 am

windows 7 64bit
wxWidgets 3.1
gcc 5.4 64bit

I draw a circle of color gradients with wxGraphicsPath,through many triangular way to draw; But the graphic of drawing has water ripples.

How to solve the problem of water ripples?
circle.png (64.31 KiB) Viewed 863 times

Code: Select all

    wxGCDC &gdc = (wxGCDC&)dc;
    wxGraphicsContext           *gc = gdc.GetGraphicsContext();
    wxGraphicsPath              pth;
    int angle = 1;
    int num = 360;
    int n = (int) num / angle;
    for(int i=0; i< n; i+=1)
        wxImage::RGBValue val = wxImage::HSVtoRGB(wxImage::HSVValue(float(i)/n, 1.0, 1.0));
        wxColour bgcolour = wxColour(val.red, val.green, val.blue);
        pth = gc->CreatePath();
        pth.MoveToPoint(pos.x, pos.y);
        pth.AddLineToPoint(pos.x + radius*cos(i*angle*M_PI/180), pos.y+radius*sin(i*angle*M_PI/180));
        pth.AddArc(wxPoint(pos.x, pos.y), radius, i*angle*M_PI/180, (i+1)*angle*M_PI/180,true);
        pth.AddLineToPoint(pos.x + radius*cos((i+1)*angle*M_PI/180), pos.y+radius*sin((i+1)*angle*M_PI/180));


Experienced Solver
Experienced Solver
Posts: 80
Joined: Wed Oct 19, 2016 1:41 pm

Re: Why is the drawing with striped?

Post by MagickPanda » Thu Jun 22, 2017 4:36 am

hmm not familiar with wx drawing functions, but from my experiences it's generally not good to use integer to store/calculate float or double values, try explicitly convert integer to double in your variable calculations to see if it helps.

User avatar
Posts: 14895
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Why is the drawing with striped?

Post by doublemax » Thu Jun 22, 2017 6:29 am

These are Moiré patterns: https://en.wikipedia.org/wiki/Moire

I think you'll need a scanline-based approach and calculate every pixel of the circle individually. This will be much slower, but should prevent the Moiré pattern.

I found some Delphi and C# code here:
https://stackoverflow.com/questions/102 ... to-c-sharp
Use the source, Luke!

Post Reply