[ Video ]
[ About ]
Day 6 Web.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#pragma once #include "ofMain.h" #include "Web.h" class ofApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed(int key) {}; void keyReleased(int key) {}; void mouseMoved(int x, int y) {}; void mouseDragged(int x, int y, int button) {}; void mousePressed(int x, int y, int button) {}; void mouseReleased(int x, int y, int button) {}; void mouseEntered(int x, int y) {}; void mouseExited(int x, int y) {}; void windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; vector<Web> webs; }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(39); ofNoFill(); for (int i = 0; i < 8; i++) { this->webs.push_back(Web()); } } //-------------------------------------------------------------- void ofApp::update() { for (Web& web : this->webs) { web.update(); } } //-------------------------------------------------------------- void ofApp::draw() { for (Web& web : this->webs) { web.draw(); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#pragma once #include "ofMain.h" class Web { public: Web(); ~Web(); void update(); void draw(); private: ofPoint location; int radius_max; int radius_start; float progress; int life; vector<float> line_param; }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
#include "Web.h" //-------------------------------------------------------------- Web::Web() { this->location = ofPoint(ofRandom(ofGetWidth()), ofRandom(ofGetHeight())); this->radius_start = 10; this->radius_max = floor(ofRandom(5, 10)) * 10; this->progress = ofRandom(1); this->life = 60; for (int deg = 0; deg < 360; deg += 30) { this->line_param.push_back(ofRandom(1, 2)); } } //-------------------------------------------------------------- Web::~Web() { } //-------------------------------------------------------------- void Web::update() { if (this->progress > 1) { if (this->life-- < 0) { this->location = ofPoint(ofRandom(ofGetWidth()), ofRandom(ofGetHeight())); this->radius_start = 10; this->radius_max = floor(ofRandom(5, 10)) * 10; this->progress = 0; this->life = 60; } } else { this->progress += 0.01; } } //-------------------------------------------------------------- void Web::draw() { ofPushMatrix(); ofTranslate(this->location); ofSetColor(239, ofMap(this->life, 60, 0, 255, 0)); int radius; for (radius = this->radius_start; radius < this->radius_max * this->progress; radius += 10) { ofBeginShape(); for (int deg = 0; deg < 360; deg += 30) { ofVertex(ofPoint(radius * cos(deg * DEG_TO_RAD), radius * sin(deg * DEG_TO_RAD))); } ofEndShape(true); } int i = 0; for (int deg = 0; deg < 360; deg += 30) { ofDrawLine(ofPoint(), ofPoint(this->radius_max * this->line_param[i] * cos(deg * DEG_TO_RAD), this->radius_max * this->line_param[i] * sin(deg * DEG_TO_RAD))); i++; } ofPopMatrix(); } |