void drawTree(uint16_t x, uint16_t y, binTree_t* pTree) { char buf[10]; uint16_t width; uint16_t lWidth; uint16_t rWidth; uint16_t rx; uint16_t ry; if (pTree == NULL) { return; } memset(buf, 0, sizeof(buf)); itoa(pTree->value, buf, 10); terminal_draw_char(x, y, buf); rWidth = getWidth(pTree->right, RIGHT); lWidth = getWidth(pTree->left, LEFT); width = rWidth > lWidth ? rWidth : lWidth; if (pTree->left) { drawBranch(x - 1, y + 1, &rx, &ry, width, LEFT); drawTree(rx, ry, pTree->left); // termial_draw_char(x - 1, y + 1, "/"); // drawTree(x - 2, y + 2, pTree->left); } if (pTree->right) { drawBranch(x + 1, y + 1, &rx, &ry, width, RIGHT); drawTree(rx, ry, pTree->right); // termial_draw_char(x + 1, y + 1, "\\"); // drawTree(x + 2, y + 2, pTree->right); } }
//-------------------------------------------------------------- void ofApp::draw(){ ofSetColor(255, 0, 0); ofFill(); ofTranslate(ofGetWidth()/2, ofGetHeight()); drawBranch(500, cos(ofGetElapsedTimef())*100); drawBranch(200, 30); }
void Particle::drawBranch(float length, float theta){ float x2=150+length; float y2=(length/2)-theta; float x3=theta; float y3=100-length; //big rotating circles ofNoFill(); ofSetColor(sin(ofGetElapsedTimef()/5)*250,abs(cos(ofGetElapsedTimef()/5)*350),(sin(ofGetElapsedTimef()/3)*250),50); ofDrawCircle(x3,200,x2,y2); //small rotating circles ofNoFill(); ofSetColor(abs(tan(ofGetElapsedTimef()/5)*250),abs(tan(ofGetElapsedTimef()/5)*350),(sin(ofGetElapsedTimef()/2)*350)); ofDrawCircle(x3,length,theta*5,theta*2); //triangle // ofNoFill(); // ofSetColor(sin(ofGetElapsedTimef())*250,abs(cos(ofGetElapsedTimef()/5)*350),(sin(ofGetElapsedTimef()/3)*250),50); // ofDrawTriangle(0, 0, 10, 30, 20, 10); // //---------- ofTranslate(0, theta); ofTranslate(0, theta); length= length*0.5; theta= theta*0.8; if(length>2){ ofPushMatrix(); // ofRotate(theta/2); ofRotate(abs(cos(ofGetElapsedTimef()/4)*250)); drawBranch(length, theta); ofPopMatrix(); ofPushMatrix(); ofRotate(abs(cos(ofGetElapsedTimef()/4)*253)); drawBranch(length, theta); ofPopMatrix(); } }
//-------------------------------------------------------------- void ofApp::drawLeaf(int depth, float angle) { int leafLength = lineLength*depth, leafSize = 20; //appInfo += ofToString(leafLength)+"\n"; ofTranslate(0,-leafLength); ofSetLineWidth(depth); ofSetColor(100,100,100); ofLine(0,leafLength,0,0); if(depth == 0) { ofEnableAlphaBlending(); ofSetColor(255,0,255,15); if (ofRandom(100) > 0) { ofFill(); ofEllipse(0,0,leafSize,leafSize); } ofSetColor(100,100,100); } if(depth>0){ drawBranch(depth-1, angle); } }
void KisNodeDelegate::paint(QPainter *p, const QStyleOptionViewItem &o, const QModelIndex &index) const { p->save(); { QStyleOptionViewItem option = getOptions(o, index); QStyle *style = option.widget ? option.widget->style() : QApplication::style(); style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, p, option.widget); bool shouldGrayOut = index.data(KisNodeModel::ShouldGrayOutRole).toBool(); if (shouldGrayOut) { option.state &= ~QStyle::State_Enabled; } p->setFont(option.font); drawColorLabel(p, option, index); drawFrame(p, option, index); drawThumbnail(p, option, index); drawText(p, option, index); drawIcons(p, option, index); drawVisibilityIconHijack(p, option, index); drawDecoration(p, option, index); drawExpandButton(p, option, index); drawBranch(p, option, index); drawProgressBar(p, option, index); } p->restore(); }
void ofApp::drawBranch(float length, float theta){ ofDrawLine(0, 0, 0, -length); ofTranslate(0, -length); length = length * 0.7; if(length > 2){ ofPushMatrix(); ofRotate(theta); drawBranch(length, theta); ofPopMatrix(); ofPushMatrix(); ofRotate(-theta); drawBranch(length, theta); ofPopMatrix(); } }
// Center of tree void centerBranch(int depth) { int terminatingBranch = 0; if (depth == 0) { translateBy(0, 5 * (1.0 / scaleFactor), 0); terminatingLeaf(); return; } // if if (depth == 1) { terminatingBranch = TERM; } // if translateBy(0, 6 * (depth * 1.0 / scaleFactor), 0); drawBranch(CENTER, depth); // Left branch pushMatrix(); turnLeft(); translateBy(0, 6 * (depth * 1.0 / scaleFactor), 0); drawBranch(LEFT | terminatingBranch, depth); leftBranch(depth - 1); popMatrix(); // 3D left branch pushMatrix(); rotateBy(90, 0, 1, 0); rotateBy(15, 0, 0, 1); translateBy(1, 0, 0); turnLeft(); translateBy(0, 6 * (depth * 1.0 / scaleFactor), 0); drawBranch(LEFT | terminatingBranch, depth); leftBranch(depth - 1); popMatrix(); translateBy(0, 6 * (depth * 1.0 / scaleFactor), 0); drawBranch(CENTER, depth); // Right branch pushMatrix(); turnRight(); translateBy(0, 6 * (depth * 1.0 / scaleFactor), 0); drawBranch(RIGHT | terminatingBranch, depth); rightBranch(depth - 1); popMatrix(); // 3D right branch pushMatrix(); rotateBy(90, 0, 1, 0); rotateBy(-15, 0, 0, 1); translateBy(-1, 0, 0); turnRight(); translateBy(0, 6 * (depth * 1.0 / scaleFactor), 0); drawBranch(RIGHT | terminatingBranch, depth); rightBranch(depth - 1); popMatrix(); translateBy(0, 6 * (depth * 1.0 / scaleFactor), 0); drawBranch(CENTER | TERM, depth); centerBranch(depth - 1); } // centerBranch
void Snowy::draw(){ drawBranch(xPos, yPos, 1/tan(ofGetElapsedTimef())*diam); }
void draw(){ ofBackground(ofColor::white); ofTranslate(ofGetWidth() / 2 , ofGetHeight() /2 ); drawBranch(0, 0, startRadius, recursionLevel); ofFill(); ofSetColor(0, 0, 255); };
//-------------------------------------------------------------- void ofApp::drawTrunk(int depth, float angle) { ofTranslate(startingPointX, startingPointY); ofSetLineWidth(depth*4); ofSetColor(0); for (int i=0; i<=ofGetHeight(); ++i) { ofSetColor(100,100,100); ofLine(0,i,0,0); } drawBranch(depth, angle); }
void drawBranch(float x, float y, float radius, int level) { path.clear(); path.setStrokeColor(ofColor::blueSteel); path.setStrokeWidth(level*2); path.arc(x,y, radius,radius, -180, 0); path.draw(); ofFill(); ofSetColor(56); ofCircle(x, y, level*3); if (level > 0 ){ drawBranch(x-radius, y+radius/2, radius/2, level-1); drawBranch(x+radius, y+radius/2, radius/2, level-1); } // return drawBranch(x, y, radius, level); }
void ofApp::Snowflake::drawBranch(float length, float theta){ ofLine(0, 0, 0, -length); ofTranslate(0, -length); length = length*0.4; if(length>5){ ofPushMatrix(); ofRotate(theta); drawBranch(length, theta); ofPopMatrix(); ofPushMatrix(); ofRotate(-theta); drawBranch(length, theta); ofPopMatrix(); } }
//-------------------------------------------------------------- void ofApp::draw(){ ofBackground(0); // ofSetColor(255,0,0); // ofFill(); // float length = 200; ofTranslate(ofGetWidth()/2, ofGetHeight()); // ofDrawLine(0, 0, 0, -length); // ofTranslate(0, -length); // ofRotate(30); // ofDrawLine(0,0,0,-length); drawBranch(230,cos(ofGetElapsedTimef()) * 80); }
void Snowy::drawBranch(float x, float y, float diam){ ofEllipse(xPos, yPos, diam, diam); ofSetColor(255,0,0,600); // ofEllipse(400, 200, diam, diam); // ofSetColor(0,255,0,900); // ofSetColor(0,255,0); // // // ofEllipse(400, 400, diam, diam); // ofSetColor(0,0,255,900); // ofNoFill(); diam = diam * 0.9; // length = length * 0.8; if(diam>1 || diam< -1){ drawBranch(xPos, yPos, diam); } }
void KTreeItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) { drawBranch(painter); }