Skip to content

Instantly share code, notes, and snippets.

@tado
Last active December 24, 2015 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tado/6714705 to your computer and use it in GitHub Desktop.
Save tado/6714705 to your computer and use it in GitHub Desktop.
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
// 画面基本設定
ofSetFrameRate(60);
ofBackground(63);
ofEnableBlendMode(OF_BLENDMODE_ADD);
// パーティクル画像読込み
particleImage.loadImage("particle32.png");
}
//--------------------------------------------------------------
void testApp::update(){
for(int i = 0; i < particle.size(); i++){
particle[i].resetForce();
particle[i].updateForce();
particle[i].updatePos();
}
}
//--------------------------------------------------------------
void testApp::draw(){
// 設定した場所に円を描く
ofSetHexColor(0xffffff);
for(int i = 0; i < particle.size(); i++){
//particle[i].draw();
ofPoint pos = ofPoint(particle[i].position.x, particle[i].position.y);
particleImage.draw(pos.x-16, pos.y-16, 32, 32);
}
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 < NUM; 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;
ofImage particleImage;
static const int NUM = 5;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment