int* SketchFilter::procImage() { changeImageToGray(pixels, width, height); int *originPixels = new int[width * height]; memcpy(originPixels, pixels, width * height * sizeof(int)); int threshold = 7; for (int i = 1; i < height - 1; i++) { for (int j = 1; j < width - 1; j++) { Color centerColor(originPixels[i * width + j]); int centerGray = centerColor.R(); int rightBottomIndex = (i + 1) * width + j + 1; if (rightBottomIndex < width * height) { Color rightBottomColor(originPixels[rightBottomIndex]); int rightBottomGray = rightBottomColor.R(); if (abs(centerGray - rightBottomGray) >= threshold) { pixels[i * width + j] = RGB2Color(0, 0, 0); // black } else { pixels[i * width + j] = RGB2Color(255, 255, 255); // white } } } } delete[] originPixels; return pixels; }
//-------------------------------------------------------------- void ofApp::draw(){ // Clear screen ofColor centerColor(85, 78, 68); ofColor edgeColor(0, 0, 0); ofBackgroundGradient(centerColor, edgeColor, OF_GRADIENT_CIRCULAR); ofEnableDepthTest(); // Use the camera easyCam.begin(); ofPushMatrix(); if (state == 0) { sphereMesh.draw(); } else if (state == 1) { // Place the camera to view the middle of the screen ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2); // Draw content genMesh.draw(); } ofPopMatrix(); easyCam.end(); ofDisableDepthTest(); // Draw ui frame.draw(); }
void LongPressSpinner::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { painter->save(); //painter->setClipRect( option->exposedRect ); int iconSize = boundingRect().size().toSize().width(); //painter->translate(-iconSize/2,-iconSize/2); if(m_goodPressFlag) { // Draw inner gradient QColor centerColor = Qt::green; QRadialGradient rg(boundingRect().center(),iconSize); rg.setColorAt(0, centerColor/*.lighter(100)*/); rg.setColorAt(1, centerColor.darker(500)); //p.setPen(Qt::black); painter->setBrush(QBrush(rg)); //painter->setPen(QPen(Qt::black,3)); painter->drawEllipse(boundingRect()); } else { painter->setOpacity(0.75); // Draw inner gradient QColor centerColor("#0277fd"); // cream blue QRadialGradient rg(boundingRect().center(),iconSize); rg.setColorAt(0, centerColor/*.lighter(100)*/); rg.setColorAt(1, centerColor.darker(500)); //p.setPen(Qt::black); painter->setBrush(QBrush(rg)); //qDebug() << "LongPressSpinner::paint(): progress:"<<m_progress<<", rect:"<<boundingRect()<<", iconSize:"<<iconSize; QPainterPath outerPath; outerPath.addEllipse(boundingRect()); QPainterPath innerPath; innerPath.addEllipse(boundingRect().adjusted(12.5,12.5,-12.5,-12.5)); // Clip center of circle painter->setClipPath(outerPath.subtracted(innerPath)); // Draw outline painter->setPen(QPen(Qt::black,3)); //painter->drawEllipse(0,0,iconSize,iconSize); painter->drawChord(boundingRect().adjusted(3,3,-3,-3), 0, -(int)(360 * 16 * m_progress)); // clockwise painter->setBrush(Qt::white); painter->drawChord(boundingRect().adjusted(10,10,-10,-10), 0, -(int)(360 * 16 * m_progress)); // clocwise } painter->restore(); }
//-------------------------------------------------------------- void ofApp::draw(){ ofClear(0, 0, 0); // ofColor centerColor = ofColor(85, 78, 68); ofColor centerColor(185, 131, 118); ofColor edgeColor(0); ofBackgroundGradient(centerColor, edgeColor, OF_GRADIENT_CIRCULAR); camera.begin(); headVolume.drawVolume(0, 0, 0, ofGetHeight(), 0); camera.end(); }
Tree::Branch* Tree::branchFractal(GLfloat cur_angle, GLfloat prev_angle, Vertex2d initPoint, GLfloat height, unsigned char depth, Floor* floor, bool behindLog) { Vertex2d finalPoint = Vertex2d( initPoint.x + height * cosf(prev_angle + cur_angle + M_PI_2), initPoint.y + height * sinf(prev_angle + cur_angle + M_PI_2) ); // Crea un ramo vuoto, direzionato Tree::Branch* fractal = new Branch(); fractal->angle = cur_angle; // Scegli un numero di foglie e creale int foglie = (depth > 4) ? 0 : rand() % (depth + 20) + 1; for (int i=0; i<foglie; i++) { GLfloat perc = std::max(rand() % 100, rand() % 100) / 100.0; Vertex2d position( initPoint.x * (1 - perc) + finalPoint.x * perc, initPoint.y * (1 - perc) + finalPoint.y * perc ); Vertex2d fallPoint( position.x, (float) (((behindLog) ? rand() % (int)(floor->height / 4) + floor->height / 4: rand() % (int)floor->height / 2)) ); position.x += rand() % 20 - 10.0f; GLfloat size = 5.0f; GLfloat leaf_angle = (cur_angle + prev_angle) * 180 / M_PI + rand() % 90 - 45.0f; RGBColor color((rand() % 4) / 10.0f, 1.0f - (rand() % 3) / 10.0f, (rand() % 3) / 10.0f, 1); int age = rand() % 256; fractal->leaves.push_back(Leaf(position, fallPoint, size, leaf_angle, color, age, behindLog)); } // Scegli un numero di fiori e frutti e creali int flowers = (depth > 4) ? 0 : rand() % 4; for (int i=0; i<flowers; i++) { GLfloat perc = std::max(rand() % 100, rand() % 100) / 100.0; Vertex2d position( initPoint.x * (1 - perc) + finalPoint.x * perc, initPoint.y * (1 - perc) + finalPoint.y * perc ); Vertex2d fallPointFruit( position.x, (float) (rand() % (int)(floor->height / 2)) ); GLfloat size = rand() % 3 + 2; GLfloat sizeFruit = 8; RGBColor centerColor(0.96, 0.76, 0.1, 1); RGBColor petalColor(0.9, 0.1, 0.6, 1); RGBColor fruitColor(1 + ((rand()%10 - 5.0f) / 100.0f), 0.6f + ((rand()%10 - 5.0f) / 100.0f), 0, 1); int age = rand() % 256; fractal->flowers.push_back(Flower(position, size, centerColor, petalColor)); fractal->fruits.push_back(Fruit(position, fallPointFruit, sizeFruit, fruitColor, age)); } // Se non ci sono rami "figli" ho finito if (depth == 0) { return fractal; } // Scegli le direzioni per i figli e creali int angles[] = {0, 45, 315}; std::random_shuffle(angles, angles+3); int children = (depth > 2) ? 3 : rand() % 2 + 1; for (int i=0; i<children; i++) { GLfloat new_angle = (angles[i] + rand() % 20 - 10) / 180.0 * M_PI; fractal->child[i] = branchFractal(new_angle, cur_angle + prev_angle, finalPoint, height * 0.7, depth - 1, floor, behindLog); } return fractal; }