Skip to content

Instantly share code, notes, and snippets.

@tado
Last active December 23, 2015 23:39
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/6711076 to your computer and use it in GitHub Desktop.
Save tado/6711076 to your computer and use it in GitHub Desktop.
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
// 画面基本設定
ofSetFrameRate(60);
ofBackground(63);
}
//--------------------------------------------------------------
void testApp::update(){
for(int i = 0; i < NUM; i++){
particle[i].resetForce();
particle[i].addForce(ofVec2f(0, 0.25));
particle[i].updateForce();
particle[i].updatePos();
particle[i].checkBounds(0, -1000, ofGetWidth(), ofGetHeight());
}
}
//--------------------------------------------------------------
void testApp::draw(){
// 設定した場所に円を描く
for(int i = 0; i < NUM; i++){
particle[i].draw();
}
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
// fキーでフルスクリーンに
if (key == 'f') {
ofToggleFullscreen();
}
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
for(int i = 0; i < NUM; i++){
ofVec2f pos = ofVec2f(x, y);
float length = ofRandom(60);
float angle = ofRandom(PI * 2);
ofVec2f vel = ofVec2f(cos(angle) * length, sin(angle) * length);
particle[i].setup(pos, vel);
particle[i].radius = 4;
particle[i].friction = 0.01;
}
}
#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);
static const int NUM = 1000;
Particle particle[NUM];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment