Source code:
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsEllipseItem>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
const int size = 500;
QGraphicsScene scene;
scene.setSceneRect( 0.0, 0.0, size+100, size+100 );
QPen penWhite(Qt::white);
QBrush brushWhite(Qt::white); //QBrush to fill-up shape with the color
QPen penBlack(Qt::black);
QBrush brushBlack(Qt::black); //QBrush to fill-up shape with the color
//draw white big circle
QPainterPath whiteBigCirlePainter;
QPoint pointCircleCenter;
pointCircleCenter.setX((size+100)/2);
pointCircleCenter.setY((size+100)/2);
whiteBigCirlePainter.addEllipse(pointCircleCenter, size/2, size/2);
scene.addPath(whiteBigCirlePainter, penWhite, brushWhite);
//draw black big semicircle to the right
QPainterPath rightBlackSemicirclePath;
rightBlackSemicirclePath.arcMoveTo((size+100)/2.0 - (size/2.0),
(size+100)/2.0 - (size/2.0),
size, size, 270);
rightBlackSemicirclePath.arcTo((size+100)/2.0 - (size/2.0),
(size+100)/2.0 - (size/2.0),
size, size, 270, 180);
scene.addPath(rightBlackSemicirclePath, penBlack, brushBlack);
//draw black circle bottom
QPainterPath blackCircleBottomPainter;
QPoint pointCircleBottomCenter;
pointCircleBottomCenter.setX((size+100)/2.0);
pointCircleBottomCenter.setY((size+100)/2.0 + size/4.0);
blackCircleBottomPainter.addEllipse(pointCircleBottomCenter, size/2/2, size/2/2);
scene.addPath(blackCircleBottomPainter, penBlack, brushBlack);
//draw white circle top
QPainterPath whiteCircleTopPainter;
QPoint pointCircleTopCenter;
pointCircleTopCenter.setX((size+100)/2.0);
pointCircleTopCenter.setY((size+100)/2.0 - size/4.0);
whiteCircleTopPainter.addEllipse(pointCircleTopCenter, size/2/2, size/2/2);
scene.addPath(whiteCircleTopPainter, penWhite, brushWhite);
//draw white circle bottom eye
QPainterPath whiteCircleBottomEyePainter;
QPoint pointCircleBottomEyeCenter;
pointCircleBottomEyeCenter.setX((size+100)/2.0);
pointCircleBottomEyeCenter.setY((size+100)/2.0 + size/4.0);
whiteCircleBottomEyePainter.addEllipse(pointCircleBottomEyeCenter, size/2/2/2/2, size/2/2/2/2);
scene.addPath(whiteCircleBottomEyePainter, penWhite, brushWhite);
//draw black circle top eye
QPainterPath blackCircleTopEyePainter;
QPoint pointCircleTopEyeCenter;
pointCircleTopEyeCenter.setX((size+100)/2.0);
pointCircleTopEyeCenter.setY((size+100)/2.0 - size/4.0);
blackCircleTopEyePainter.addEllipse(pointCircleTopEyeCenter, size/2/2/2/2, size/2/2/2/2);
scene.addPath(blackCircleTopEyePainter, penBlack, brushBlack);
//draw big circle black outline
QPainterPath bigCircleBlackOutlinePainter;
bigCircleBlackOutlinePainter.addEllipse(pointCircleCenter, size/2, size/2);
scene.addPath(bigCircleBlackOutlinePainter, penBlack, Qt::NoBrush);
QGraphicsView view( &scene );
view.setRenderHint(QPainter::Antialiasing); //antialias edges of primitives if possible
view.setRenderHint(QPainter::HighQualityAntialiasing); //an OpenGL-specific rendering hint
view.setWindowTitle("My Yin Yang Painting");
view.show();
return app.exec();
}
Project Output: ☯
No comments:
Post a Comment