Skip to content

Instantly share code, notes, and snippets.

@tado
Last active December 23, 2015 23:49
Show Gist options
  • Save tado/6712412 to your computer and use it in GitHub Desktop.
Save tado/6712412 to your computer and use it in GitHub Desktop.
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
// 画面基本設定
ofSetFrameRate(60);
ofBackground(63);
// 色の混合を加算合成に
ofEnableBlendMode(OF_BLENDMODE_ADD);
// 円の解像度
ofSetCircleResolution(6);
}
//--------------------------------------------------------------
void testApp::update(){
for(int i = 0; i < particle.size(); i++){
particle[i].resetForce();
particle[i].updateForce();
particle[i].updatePos();
}
}
//--------------------------------------------------------------
void testApp::draw(){
// 設定した場所に円を描く
for(int i = 0; i < particle.size(); i++){
particle[i].draw();
}
ofSetHexColor(0xffffff);
ofDrawBitmapString("particle num = " + ofToString(particle.size()), 10, 15);
ofDrawBitmapString("fps = " + ofToString(ofGetFrameRate()), 10, 30);
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
if (key == 'f') {
ofToggleFullscreen();
}
if (key == 'c') {
particle.clear();
}
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
for(int i = 0; i < 10; i++){
ofVec2f pos = ofVec2f(x, y);
float length = ofRandom(1);
float angle = ofRandom(PI * 2);
ofVec2f vel = ofVec2f(cos(angle) * length, sin(angle) * length);
Particle p;
p.setup(pos, vel);
p.radius = 2;
p.friction = 0.002;
particle.push_back(p);
}
}
#pragma once
#include "ofMain.h"
#include "Particle.h"
class testApp : 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 windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
vector<Particle> particle;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment