I would like to be able to draw a large number (100x100) of filled circles on a grid using a Raspberry PI 2 model B using wxWidgets 3.0 (Raspbian). The OnPaint function I currently have is shown below:
Code: Select all
void temp2Dialog::OnPaint(wxPaintEvent& event)
{
int borderSize = 4;
wxBufferedPaintDC pdc(Panel1);
wxGCDC dc(pdc);
PrepareDC(dc);
wxSize totalSize = dc.GetSize();
// Define where picture is to start (top left corner), noting presence of border
double g1Position[2] = {0};
g1Position[0] += borderSize;
g1Position[1] += borderSize;
// Define how big the picture can be (i.e. size of wxPanel Panel1), noting presence of border all around
double g1Size[2] = {0};
g1Size[0] = totalSize.GetWidth();
g1Size[1] = totalSize.GetHeight();
g1Size[0] -= borderSize*2;
g1Size[1] -= borderSize*2;
// Draw underlying black rectangle
dc.DrawRectangle(g1Position[0],g1Position[1],g1Size[0],g1Size[1]);
// Matrix of circles will be square. Work out the maximum length of the square
double picSize = 0;
if(g1Size[0] > g1Size[1]) picSize = g1Size[1];
else picSize = g1Size[0];
// Work out size of circles
int matrixSize = 100;
double deltaX = picSize / matrixSize;
int ideltaX = (int)deltaX;
double Radius = deltaX /2.0;
int iRadius = (int)Radius;
// Loop through the matrix of circles
for(int i=0;i<matrixSize;i++)
{
for(int j=0;j<matrixSize;j++)
{
// Define a random colour, and then draw a filled circle
wxColour randomColour(rand()%255,rand()%255,rand()%255);
dc.SetBrush(wxBrush(randomColour));
dc.SetPen(wxPen(randomColour));
int X = ideltaX*(i+1);
int Y = ideltaX*(j+1);
dc.DrawCircle(X,Y,iRadius);
}
}
}
Ideally, I would also like to retain the use of wxGCDC as this seems to be the only way to ensure the circles are drawn using anti-aliasing.
Thanks very much for reading.