[ Video ]
[ About ]
Particleをsin波で移動させています。
Particle is moved by sin wave.
[ 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 26  | 
						#pragma once #include "ofMain.h" #include "Particle.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) {}; 	ofEasyCam cam; 	vector<shared_ptr<Particle>> particles; };  | 
					
| 
					 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  | 
						#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofBackground(255); 	ofSetWindowTitle("Insta"); 	ofEnableDepthTest(); 	//ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); 	for (int i = 0; i < 128; i++) { 		this->particles.push_back(shared_ptr<Particle>(new Particle())); 	} } //-------------------------------------------------------------- void ofApp::update() { 	for(int i = 0; i < this->particles.size(); i++){ 		this->particles[i]->update(); 	} } //-------------------------------------------------------------- void ofApp::draw() { 	this->cam.begin(); 	for (int i = 0; i < this->particles.size(); i++) { 		this->particles[i]->draw(this->particles); 	} 	this->cam.end(); } //-------------------------------------------------------------- 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  | 
						#pragma once #include "ofMain.h" class Particle { public: 	Particle(); 	~Particle() {}; 	void update(); 	void draw(vector<shared_ptr<Particle>> particles); 	ofVec2f get_location(); private: 	ofVec2f location; 	ofVec2f velocity; 	ofColor body_color; };  | 
					
| 
					 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  | 
						#include "Particle.h" Particle::Particle(){ 	this->location = ofVec2f(ofRandom(-ofGetWidth() / 2, ofGetWidth() / 2)); 	this->velocity = ofVec2f(ofRandom(1.5, 3.0), 0); 	//this->body_color.setHsb(ofRandom(255), 255, 255); 	this->body_color = ofColor(0); } void Particle::update() { 	float x = this->location.x + this->velocity.x; 	float y = sin(x * this->velocity.x * 0.0025) * ofGetHeight() * 0.5; 	this->location = ofVec2f(x, y); 	if (this->location.x > ofGetWidth() / 2 + 3) { 		this->location.x = -ofGetWidth() / 2 - 3; 	} } void Particle::draw(vector<shared_ptr<Particle>> particles) { 	ofSetColor(this->body_color); 	ofDrawCircle(this->location, 3); 	float distance; 	for (int i = 0; i < particles.size(); i++) { 		distance = this->location.distance(particles[i]->get_location()); 		if (distance > 0 && distance < 64) { 			ofSetColor(this->body_color, 255 - distance); 			ofDrawLine(this->location, particles[i]->get_location()); 		} 	} } ofVec2f Particle::get_location() { 	return this->location; }  |