void RGBAudio::calculateColors(int barsHeight) { if (barsHeight > 0) { m_barColors.clear(); if (endColor() == QColor()) { for (int i = 0; i < barsHeight; i++) m_barColors.append(startColor().rgb()); } else { int crDelta = (endColor().red() - startColor().red()) / (barsHeight - 1); int cgDelta = (endColor().green() - startColor().green()) / (barsHeight - 1); int cbDelta = (endColor().blue() - startColor().blue()) / (barsHeight - 1); QColor pixelColor = startColor(); for (int i = 0; i < barsHeight; i++) { m_barColors.append(pixelColor.rgb()); pixelColor = QColor(pixelColor.red() + crDelta, pixelColor.green() + cgDelta, pixelColor.blue() + cbDelta); } } } }
bool RGBMatrix::saveXML(QXmlStreamWriter *doc) { Q_ASSERT(doc != NULL); /* Function tag */ doc->writeStartElement(KXMLQLCFunction); /* Common attributes */ saveXMLCommon(doc); /* Speeds */ saveXMLSpeed(doc); /* Direction */ saveXMLDirection(doc); /* Run order */ saveXMLRunOrder(doc); /* Algorithm */ if (m_algorithm != NULL) m_algorithm->saveXML(doc); /* Dimmer Control */ doc->writeTextElement(KXMLQLCRGBMatrixDimmerControl, QString::number(dimmerControl())); /* Start Color */ doc->writeTextElement(KXMLQLCRGBMatrixStartColor, QString::number(startColor().rgb())); /* End Color */ if (endColor().isValid()) { doc->writeTextElement(KXMLQLCRGBMatrixEndColor, QString::number(endColor().rgb())); } /* Fixture Group */ doc->writeTextElement(KXMLQLCRGBMatrixFixtureGroup, QString::number(fixtureGroup())); /* Properties */ QHashIterator<QString, QString> it(m_properties); while(it.hasNext()) { it.next(); doc->writeStartElement(KXMLQLCRGBMatrixProperty); doc->writeAttribute(KXMLQLCRGBMatrixPropertyName, it.key()); doc->writeAttribute(KXMLQLCRGBMatrixPropertyValue, it.value()); doc->writeEndElement(); } /* End the <Function> tag */ doc->writeEndElement(); return true; }
bool RGBMatrix::saveXML(QDomDocument* doc, QDomElement* wksp_root) { QDomElement root; QDomElement tag; QDomText text; QString str; Q_ASSERT(doc != NULL); Q_ASSERT(wksp_root != NULL); /* Function tag */ root = doc->createElement(KXMLQLCFunction); wksp_root->appendChild(root); /* Common attributes */ saveXMLCommon(&root); /* Speeds */ saveXMLSpeed(doc, &root); /* Direction */ saveXMLDirection(doc, &root); /* Run order */ saveXMLRunOrder(doc, &root); /* Algorithm */ if (m_algorithm != NULL) m_algorithm->saveXML(doc, &root); /* Start Color */ tag = doc->createElement(KXMLQLCRGBMatrixStartColor); root.appendChild(tag); text = doc->createTextNode(QString::number(startColor().rgb())); tag.appendChild(text); /* End Color */ if (endColor().isValid()) { tag = doc->createElement(KXMLQLCRGBMatrixEndColor); root.appendChild(tag); text = doc->createTextNode(QString::number(endColor().rgb())); tag.appendChild(text); } /* Fixture Group */ tag = doc->createElement(KXMLQLCRGBMatrixFixtureGroup); root.appendChild(tag); text = doc->createTextNode(QString::number(fixtureGroup())); tag.appendChild(text); return true; }
void ApplicationLayer::Views::XYScatterView::OnDraw(ApplicationLayer::DrawEventArgs& e) { for (auto&& point : m_Trail) { e.graphicContext.FillCircle(point.x, point.y, 5, e.colorScheme.Background); } e.graphicContext.DrawVerticalLine(e.graphicContext.Width() / 2, 0, e.graphicContext.Height(), e.colorScheme.Foreground); e.graphicContext.DrawHorizontalLine(0, e.graphicContext.Height() / 2, e.graphicContext.Width(), e.colorScheme.Foreground); std::rotate(m_Trail.begin(), m_Trail.begin() + 1, m_Trail.end()); m_Trail[0].x = Common::Math::Map(m_XModel.GetRawValue(), -1000, 1000, 0, e.graphicContext.Width()); m_Trail[0].y = Common::Math::Map(m_YModel.GetRawValue(), -1000, 1000, 0, e.graphicContext.Height()); float step = 0; float stepSize = 1.0f / m_Trail.size(); PeripheralLayer::Color::RGB beginColor(e.colorScheme.Text); PeripheralLayer::Color::RGB endColor(e.colorScheme.Background); for (auto&& point : m_Trail) { PeripheralLayer::Color::RGB currentColor = PeripheralLayer::Color::Interpolate(beginColor, endColor, step, &Common::Interpolation::Linear<int>); step += stepSize; e.graphicContext.FillCircle(point.x, point.y, 5, currentColor.ToRGBA(0xFF)); } }
void FractalCreator::drawFractal() { RGB startColor(0, 0, 0); RGB endColor(0, 0, 255); RGB colorDiff = endColor - startColor; for (int y = 0; y < m_height; y++) { for (int x = 0; x < m_width; x++) { uint8_t red = 0; uint8_t green = 0; uint8_t blue = 0; int iterations = m_fractal[y * m_width + x]; if (iterations != Mandelbrot::MAX_ITERATIONS) { double hue = 0.0; for (int i = 0; i <= iterations; i++) { hue += ((double) m_histogram[i]) / m_total; } red = startColor.r + colorDiff.r*hue; green = startColor.g + colorDiff.g*hue; blue = startColor.b + colorDiff.b*hue; } m_bitmap.setPixel(x, y, red, green, blue); } } }
void BaseParticleGroup::draw() { // this is a "group" drawing feature ofPushStyle(); ofNoFill(); // ofMesh mesh; // mesh.setMode(OF_PRIMITIVE_TRIANGLES); ofMesh trails; trails.setMode(OF_PRIMITIVE_LINES); trails.enableColors(); for(std::size_t i = 0; i < members.size(); ++i) { // ofVec2f position = members[i]->position; // // ofVec2f up = position + ofVec2f(0,-4); // ofVec2f right = position + ofVec2f(4,4); // ofVec2f left = position + ofVec2f(-4,4); // // // mesh.addVertex(up); // mesh.addVertex(right); // mesh.addVertex(left); // // ofFloatColor myColor = ofFloatColor::white; ofFloatColor endColor(color); endColor.a = 0; myColor.lerp(color, members[i]->getLife()); // mesh.addColor(myColor); // mesh.addColor(myColor); // mesh.addColor(myColor); trails.addVertex(members[i]->position); trails.addColor(myColor); ofVec2f diff = members[i]->position - members[i]->velocity; trails.addVertex(diff); ofFloatColor c = myColor; c.a = 0; trails.addColor(c); } // mesh.draw(); trails.draw(); ofPopStyle(); }
void ParticlePerformTest4::doTest() { auto s = Director::getInstance()->getWinSize(); auto particleSystem = (ParticleSystem*) getChildByTag(kTagParticleSystem); // duration particleSystem->setDuration(-1); // gravity particleSystem->setGravity(Vec2(0,-90)); // angle particleSystem->setAngle(90); particleSystem->setAngleVar(0); // radial particleSystem->setRadialAccel(0); particleSystem->setRadialAccelVar(0); // speed of particles particleSystem->setSpeed(180); particleSystem->setSpeedVar(50); // emitter position particleSystem->setPosition(Vec2(s.width/2, 100)); particleSystem->setPosVar(Vec2(s.width/2,0)); // life of particles particleSystem->setLife(2.0f); particleSystem->setLifeVar(1); // emits per frame particleSystem->setEmissionRate(particleSystem->getTotalParticles() / particleSystem->getLife()); // color of particles Color4F startColor(0.5f, 0.5f, 0.5f, 1.0f); particleSystem->setStartColor(startColor); Color4F startColorVar(0.5f, 0.5f, 0.5f, 1.0f); particleSystem->setStartColorVar(startColorVar); Color4F endColor(0.1f, 0.1f, 0.1f, 0.2f); particleSystem->setEndColor(endColor); Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.2f); particleSystem->setEndColorVar(endColorVar); // size, in pixels particleSystem->setEndSize(64.0f); particleSystem->setStartSize(64.0f); particleSystem->setEndSizeVar(0); particleSystem->setStartSizeVar(0); // additive particleSystem->setBlendAdditive(false); }
void DemoScreenParticleActors::Start() { // Create the particle actor via the Actor Definition system (.adf files) pa = new ParticleActor(); pa->SetColor(1.0f, 1.0f, 1.0f); //Sets the initial color of the particles. // Since the image file we'll be using already // has a color, we set this to pure white. pa->SetSize(Vector2(0.2f, 0.2f)); //The size of each particle, in GL units pa->SetSprite("Resources/Images/Test.png"); //The image file we want to use (otherwise // it'll just be colored squares). pa->SetMaxParticles(500); //The maximum number of particles this system will ever handle. pa->SetParticlesPerSecond(10.0f); //Emission Rate pa->SetParticleLifetime(1.5f); //How long each particles lasts before disappearing pa->SetSpread(MathUtil::Pi); //The angle in radians at which particles will be emitted. pa->SetEndScale(1.0f); //If you want the particles to change size over their lifetimes Color endColor(1.0f, 1.0f, 1.0f, 0.0f); pa->SetEndColor(endColor); //Our particles disappear over time pa->SetEndScale(2.0f); pa->SetSpeedRange(3.0f, 4.0f); //The minimum and maximum range of speeds (so you can have // some variation). pa->SetGravity(Vector2::Zero); //You can pull the particles in a particular direction (default is // downwards, so zero it out if you need to). theWorld.Add(pa); _isActive = true; //lets the mouse events know that they should care //Demo housekeeping below this point. #pragma region Demo Housekeeping t = new TextActor("Console", "Here's a ParticleActor. (Try moving and clicking the mouse!)"); t->SetPosition(0, 3.5); t->SetAlignment(TXT_Center); theWorld.Add(t); t2 = new TextActor("Console", "Press [B] to change its properties."); t2->SetPosition(0, 2.5); t2->SetAlignment(TXT_Center); theWorld.Add(t2); TextActor *fileLoc = new TextActor("ConsoleSmall", "DemoScreenParticleActors.cpp"); fileLoc->SetPosition(MathUtil::ScreenToWorld(5, 763)); fileLoc->SetColor(.3f, .3f, .3f); theWorld.Add(fileLoc); _objects.push_back(fileLoc); _objects.push_back(t); _objects.push_back(t2); _objects.push_back(pa); #pragma endregion }
void TestScene::emit() { auto _emitter = ParticleSystemQuad::createWithTotalParticles(100); addChild(_emitter, 10); _emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("images/test_lizi.png")); _emitter->setDuration(1.f); // gravity _emitter->setGravity(Vec2::ZERO); // angle _emitter->setAngle(90); _emitter->setAngleVar(0); // speed of particles _emitter->setSpeed(260); _emitter->setSpeedVar(0); // radial _emitter->setRadialAccel(-260); _emitter->setRadialAccelVar(0); // tagential _emitter->setTangentialAccel(00); _emitter->setTangentialAccelVar(0); // emitter position // _emitter->setPosition( Vec2(160,240) ); _emitter->setPosVar({2,10}); // life of particles _emitter->setLife(1); _emitter->setLifeVar(0); // spin of particles _emitter->setStartSpin(10000); _emitter->setStartSizeVar(360); _emitter->setEndSpin(0); _emitter->setEndSpinVar(360); // color of particles Color4F startColor(0.f, 0.5f, 0.f, 1.0f); _emitter->setStartColor(startColor); Color4F startColorVar(0.f, 0.1f, 0.f, 1.0f); _emitter->setStartColorVar(startColorVar); Color4F endColor(0.1f, 0.5f, 0.1f, 1.0f); _emitter->setEndColor(endColor); Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.2f); _emitter->setEndColorVar(endColorVar); // size, in pixels _emitter->setStartSize(5.0f); _emitter->setStartSizeVar(1.0f); _emitter->setEndSize(ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE); // emits per second _emitter->setEmissionRate(_emitter->getTotalParticles()/_emitter->getLife()); // additive _emitter->setBlendAdditive(true); //addChild(_emitter); _emitter->setPosition(genPos({0.5,0.5})); // _emitter->runAction(RotateBy::create(10.f, 1000)); }
ParticleSystemQuad* BaseScene::createComplexParticle(int type){ if (type == 0){ _emitter = ParticleSystemQuad::createWithTotalParticles(50); addChild(_emitter, 10); _emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/stars.png")); _emitter->setDuration(-1); // gravity _emitter->setGravity(Vec2::ZERO); // angle _emitter->setAngle(90); _emitter->setAngleVar(360); // speed of particles _emitter->setSpeed(160); _emitter->setSpeedVar(20); // radial _emitter->setRadialAccel(-120); _emitter->setRadialAccelVar(0); // tagential _emitter->setTangentialAccel(30); _emitter->setTangentialAccelVar(0); // emitter position _emitter->setPosition(Vec2(160, 240)); _emitter->setPosVar(Vec2::ZERO); // life of particles _emitter->setLife(4); _emitter->setLifeVar(1); // spin of particles _emitter->setStartSpin(0); _emitter->setStartSizeVar(0); _emitter->setEndSpin(0); _emitter->setEndSpinVar(0); // color of particles Color4F startColor(0.5f, 0.5f, 0.5f, 1.0f); _emitter->setStartColor(startColor); Color4F startColorVar(0.5f, 0.5f, 0.5f, 1.0f); _emitter->setStartColorVar(startColorVar); Color4F endColor(0.1f, 0.1f, 0.1f, 0.2f); _emitter->setEndColor(endColor); Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.2f); _emitter->setEndColorVar(endColorVar); // size, in pixels _emitter->setStartSize(80.0f); _emitter->setStartSizeVar(40.0f); _emitter->setEndSize(ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE); // emits per second _emitter->setEmissionRate(_emitter->getTotalParticles() / _emitter->getLife()); // additive _emitter->setBlendAdditive(true); } else if (type == 1){ _emitter = ParticleSystemQuad::createWithTotalParticles(300); _emitter->retain(); addChild(_emitter, 10); ////_emitter->release(); // win32 : Remove this line _emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/stars.png")); // duration _emitter->setDuration(-1); // gravity _emitter->setGravity(Vec2::ZERO); // angle _emitter->setAngle(90); _emitter->setAngleVar(360); // speed of particles _emitter->setSpeed(160); _emitter->setSpeedVar(20); // radial _emitter->setRadialAccel(-120); _emitter->setRadialAccelVar(0); // tagential _emitter->setTangentialAccel(30); _emitter->setTangentialAccelVar(0); // emitter position _emitter->setPosition(Vec2(160, 240)); _emitter->setPosVar(Vec2::ZERO); // life of particles _emitter->setLife(3); _emitter->setLifeVar(1); // spin of particles _emitter->setStartSpin(0); _emitter->setStartSpinVar(0); _emitter->setEndSpin(0); _emitter->setEndSpinVar(2000); // color of particles Color4F startColor(0.5f, 0.5f, 0.5f, 1.0f); _emitter->setStartColor(startColor); Color4F startColorVar(0.5f, 0.5f, 0.5f, 1.0f); _emitter->setStartColorVar(startColorVar); Color4F endColor(0.1f, 0.1f, 0.1f, 0.2f); _emitter->setEndColor(endColor); Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.2f); _emitter->setEndColorVar(endColorVar); // size, in pixels _emitter->setStartSize(30.0f); _emitter->setStartSizeVar(00.0f); _emitter->setEndSize(ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE); // emits per second _emitter->setEmissionRate(_emitter->getTotalParticles() / _emitter->getLife()); // additive _emitter->setBlendAdditive(false); } return _emitter; }
void GameSceneQuattro::addPartcleStella(Vec2 posizione) { _boom = ParticleSystemQuad::createWithTotalParticles(900); _boom->setTexture(Director::getInstance()->getTextureCache()->addImage("gugut_01.png")); //The code below we can use both in 2.x and 3.x _boom->setDuration(-1); _boom->setGravity(Point(0, -240)); // in Cocos2d-x-2.x CCPoint(0, -240) is used _boom->setAngle(90); _boom->setAngleVar(360); _boom->setRadialAccel(50); _boom->setRadialAccelVar(0); _boom->setTangentialAccel(30); _boom->setTangentialAccelVar(0); _boom->setPosition(Point(_visibleSize.width / 2 , _visibleSize.width / 2 )); _boom->setPosVar(Point(400, 0)); _boom->setLife(4); _boom->setLifeVar(2); _boom->setStartSpin(30); _boom->setStartSpinVar(60); _boom->setEndSpin(60); _boom->setEndSpinVar(60); _boom->setStartColor(Color4F(255,255,255,1)); _boom->setStartColorVar(Color4F(0,0,0,0)); _boom->setEndColor(Color4F(255, 255, 255, 1)); _boom->setEndColorVar(Color4F(0, 0, 0, 0)); _boom->setStartSize(30); _boom->setStartSizeVar(0); _boom->setEndSize(20.0f); _boom->setEndSizeVar(0); _boom->setEmissionRate(100); _boom->stopSystem(); addChild(_boom,10); _emitter = ParticleSystemQuad::createWithTotalParticles(300); _emitter->retain(); addChild(_emitter, 15); ////_emitter->release(); // win32 : Remove this line _emitter->setTexture( Director::getInstance()->getTextureCache()->addImage("star.png") ); // duration _emitter->setDuration(-1); // gravity _emitter->setGravity(Vec2::ZERO); // angle _emitter->setAngle(90); _emitter->setAngleVar(360); // speed of particles _emitter->setSpeed(160); _emitter->setSpeedVar(20); // radial _emitter->setRadialAccel(-120); _emitter->setRadialAccelVar(0); // tagential _emitter->setTangentialAccel(30); _emitter->setTangentialAccelVar(0); // emitter position _emitter->setPosition( Vec2(160,240) ); _emitter->setPosVar(Vec2::ZERO); // life of particles _emitter->setLife(3); _emitter->setLifeVar(1); // spin of particles _emitter->setStartSpin(0); _emitter->setStartSpinVar(0); _emitter->setEndSpin(0); _emitter->setEndSpinVar(2000); // color of particles Color4F startColor(0.5f, 0.5f, 0.5f, 1.0f); _emitter->setStartColor(startColor); Color4F startColorVar(0.5f, 0.5f, 0.5f, 1.0f); _emitter->setStartColorVar(startColorVar); Color4F endColor(0.1f, 0.1f, 0.1f, 0.2f); _emitter->setEndColor(endColor); Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.2f); _emitter->setEndColorVar(endColorVar); // size, in pixels _emitter->setStartSize(30.0f); _emitter->setStartSizeVar(00.0f); _emitter->setEndSize(ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE); // emits per second _emitter->setEmissionRate(_emitter->getTotalParticles()/_emitter->getLife()); // additive _emitter->setBlendAdditive(false); _emitter->setPosition(Point(_visibleSize.width / 2 , _visibleSize.height / 2 )); _emitter->stopSystem(); }
bool RGBMatrix::saveXML(QDomDocument* doc, QDomElement* wksp_root) { QDomElement root; QDomElement tag; QDomText text; QString str; Q_ASSERT(doc != NULL); Q_ASSERT(wksp_root != NULL); /* Function tag */ root = doc->createElement(KXMLQLCFunction); wksp_root->appendChild(root); /* Common attributes */ saveXMLCommon(&root); /* Speeds */ saveXMLSpeed(doc, &root); /* Direction */ saveXMLDirection(doc, &root); /* Run order */ saveXMLRunOrder(doc, &root); /* Algorithm */ if (m_algorithm != NULL) m_algorithm->saveXML(doc, &root); /* Dimmer Control */ tag = doc->createElement(KXMLQLCRGBMatrixDimmerControl); root.appendChild(tag); text = doc->createTextNode(QString::number(dimmerControl())); tag.appendChild(text); /* Start Color */ tag = doc->createElement(KXMLQLCRGBMatrixStartColor); root.appendChild(tag); text = doc->createTextNode(QString::number(startColor().rgb())); tag.appendChild(text); /* End Color */ if (endColor().isValid()) { tag = doc->createElement(KXMLQLCRGBMatrixEndColor); root.appendChild(tag); text = doc->createTextNode(QString::number(endColor().rgb())); tag.appendChild(text); } /* Fixture Group */ tag = doc->createElement(KXMLQLCRGBMatrixFixtureGroup); root.appendChild(tag); text = doc->createTextNode(QString::number(fixtureGroup())); tag.appendChild(text); /* Properties */ QHashIterator<QString, QString> it(m_properties); while(it.hasNext()) { it.next(); tag = doc->createElement(KXMLQLCRGBMatrixProperty); tag.setAttribute(KXMLQLCRGBMatrixPropertyName, it.key()); tag.setAttribute(KXMLQLCRGBMatrixPropertyValue, it.value()); root.appendChild(tag); } return true; }
void FloatingEffectManager::toast_cure(const cocos2d::Vec2& srcPos, const cocos2d::Vec2& desPos, DDElementType elementType, int level) { const float speed = 300; float len = (desPos-srcPos).length(); if (len == 0) { return; } auto _emitter = ParticleSystemQuad::createWithTotalParticles(500); _emitter->setAutoRemoveOnFinish(true); _layer->addChild(_emitter, 10); _emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("images/test_lizi.png")); _emitter->setDuration(len/speed); // gravity _emitter->setGravity(Vec2::ZERO); // angle _emitter->setAngle(vector2angel(desPos-srcPos)); _emitter->setAngleVar(0.5f* std::atan(DDConfig::battleCubeWidth()/len) * 180.f/3.1415926f); // speed of particles _emitter->setSpeed(speed); _emitter->setSpeedVar(0); // radial _emitter->setRadialAccel(-(speed/(2*len/speed))); _emitter->setRadialAccelVar(0); // tagential _emitter->setTangentialAccel(00); _emitter->setTangentialAccelVar(0); // emitter position // _emitter->setPosition( Vec2(160,240) ); _emitter->setPosVar({0,0}); // life of particles _emitter->setLife(2*len/speed); _emitter->setLifeVar(0); // spin of particles _emitter->setStartSpin(720); _emitter->setStartSizeVar(360); _emitter->setEndSpin(0); _emitter->setEndSpinVar(360); // color of particles Color4F startColor(0.f, 0.5f, 0.f, 0.8f); _emitter->setStartColor(startColor); Color4F startColorVar(0.f, 0.1f, 0.f, 0.1f); _emitter->setStartColorVar(startColorVar); Color4F endColor(0.1f, 0.5f, 0.1f, 0.8f); _emitter->setEndColor(endColor); Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.1f); _emitter->setEndColorVar(endColorVar); // size, in pixels _emitter->setStartSize(3.0f); _emitter->setStartSizeVar(1.0f); _emitter->setEndSize(ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE); // emits per second _emitter->setEmissionRate(_emitter->getTotalParticles()/_emitter->getLife()); // additive _emitter->setBlendAdditive(true); _emitter->setPosition(srcPos); }
void PlexyDayWidget::paintFrontView(QPainter *painter, const QRectF &rect) { if (!painter->isActive()) { return; } if (isObscured()) { return; } /* Painter settings */ painter->setRenderHint(QPainter::Antialiasing, true); painter->setRenderHint(QPainter::TextAntialiasing, true); painter->setRenderHint(QPainter::HighQualityAntialiasing, true); /* Draw the background. */ float headerHight = 64.0; #ifdef Q_WS_QPA headerHight = 64.0 * 2; #endif QPainterPath backgroundPath; backgroundPath.addRect(QRectF(0.0, headerHight, rect.width(), rect.height())); QLinearGradient linearGrad(QPointF(0, 0), QPointF(0.0, rect.height())); linearGrad.setColorAt(1, QColor(189, 191, 196)); linearGrad.setColorAt(0, QColor(231, 235, 238)); painter->fillPath(backgroundPath, linearGrad); QPen pen(QColor(98, 101, 108), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); painter->setPen(pen); painter->drawPath(backgroundPath); /* Draw the top header date box */ QRectF titleCornerRect = QRect(0.0, 0.0, headerHight, headerHight); QLinearGradient titleCornerGrad(QPointF(0, 0), QPointF(0.0, titleCornerRect.height())); titleCornerGrad.setColorAt(0, QColor(81, 168, 201)); titleCornerGrad.setColorAt(1, QColor(21, 108, 169)); painter->fillRect(titleCornerRect, titleCornerGrad); QPointF start(0.0, 0.0); QPointF end(0.0, titleCornerRect.height()); QList<QColor> colors; QColor startColor(235, 238, 241); QColor endColor(220, 225, 228); colors << startColor << endColor; QLinearGradient titleHeaderGrad = genGrad(start, end, colors); QRectF titleHeaderRect(titleCornerRect.width(), 0.0, rect.width() - titleCornerRect.width(), titleCornerRect.height()); drawBox(painter, titleHeaderGrad, rect, titleHeaderRect); }
/*绘制*/ void CheckersPicture::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); painter.setViewport(p.x(),p.y(),side,side); painter.setWindow(0, 0, zoom*(n), zoom*(n)); QColor dark(0xcc,0xcc,0xcc,200); QColor endColor(0x78,0xff,0x21,200); /*终点颜色*/ QColor startColor(0xea,0x76,0x0f,200); /*起点颜色*/ QColor capturedColor(0xed,0x50,0x62,200); /*捕获颜色*/ QColor normalColor(0xd6,0xb8,0x2c,200); /*正常色*/ QColor black(0x00, 0x00, 0x00, 200); QColor white(0xff, 0xff, 0xff, 220); QColor light(0xed,0xfc,0xdf,200); QColor deep(0x5a,0x61,0x54,200); /*绘制棋盘*/ for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { QRect rect = pixelRect(i, j); if( !((i+j%2)%2) ) { painter.fillRect(rect, deep); } else { painter.fillRect(rect, light); } } } int ix,jx; if(v.size()) { int type; for(unsigned i=0; i< v.size(); i++) { color==WHITE ? jx = n-1-v.at(i).y : jx = v.at(i).y; color==WHITE ? ix = n-1-v.at(i).x : ix = v.at(i).x; QRect rect = pixelRect(ix, jx); type = v.at(i).type; if(type == MOVEDFROM) painter.fillRect(rect, startColor); else if(type == MOVEDTO || type == TOKING) painter.fillRect(rect, endColor); else if(type == MOVEDTHROUGH) painter.fillRect(rect, normalColor); else if(type == DELETED) painter.fillRect(rect, capturedColor); } } int s = zoom*0.4; int sd = zoom*0.3; /*画白棋*/ if(curstate){ /*如果棋局状态发生了改变*/ painter.setPen(QPen(black,zoom*0.025)); painter.setBrush(QBrush(white)); for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { /*如果是白色则从最后一行开始画*/ color==WHITE ? jx = j+1 : jx = n-j; color==WHITE? ix = n-i : ix = i+1; if(curstate->at(i,j)==WHITE) painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),s,s); if(curstate->at(i,j)==WHITEKING) { painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),s,s); painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),sd,sd); } } } /*画黑棋*/ painter.setBrush(QBrush(black)); for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { color==WHITE ? jx = j+1 : jx = n-j; color==WHITE ? ix = n-i : ix = i+1; if(curstate->at(i,j)==BLACK) painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),s,s); if(curstate->at(i,j)==BLACKKING) { painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),s,s); painter.setPen(QPen(white,zoom*0.1)); painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),sd,sd); painter.setPen(QPen(black,zoom*0.1)); } } } } if (thinking && showHourglass) { painter.setWindow(painter.viewport()); painter.drawImage((width() - hourglass.width()) / 2, (height() - hourglass.height()) / 2, hourglass); } }