Created
April 16, 2016 09:35
-
-
Save tado/013f4291925b963f268988144d327a4a to your computer and use it in GitHub Desktop.
Creative Visualization Workshop - assignment 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
//-------------------------------------------------------------- | |
void ofApp::setup(){ | |
// 画面基本設定 | |
ofSetFrameRate(60); //秒間60コマで描画 | |
ofBackground(0); //背景を黒に | |
//位置と速度を初期化 | |
location = ofVec2f(ofGetWidth()/2, ofGetHeight()/2); //画面の中心に | |
velocity = ofVec2f(ofRandom(-10, 10), ofRandom(-10, 10)); //ランダムな速度で | |
} | |
//-------------------------------------------------------------- | |
void ofApp::update(){ | |
location += velocity; //速度から位置を更新 | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
//計算した位置に円を描画 | |
ofSetColor(31, 127, 255); //円の色 | |
ofDrawCircle(location, 40); //半径40の円を描画 | |
//画面の端でバウンドするように | |
if (location.x < 0 || location.x > ofGetWidth()) { //画面の左右ではみ出したら | |
velocity.x *= -1; //横向きの速度を反転(バウンド) | |
} | |
if (location.y < 0 || location.y > ofGetHeight()) { //画面の左右ではみ出したら | |
velocity.y *= -1; //横向きの速度を反転(バウンド) | |
} | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyPressed(int key){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyReleased(int key){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseMoved(int x, int y ){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseDragged(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mousePressed(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseReleased(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseEntered(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseExited(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::windowResized(int w, int h){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::gotMessage(ofMessage msg){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::dragEvent(ofDragInfo dragInfo){ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.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); | |
ofVec2f location; // 位置 | |
ofVec2f velocity; // 速度 | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment