Upcoming SlideShare
Loading in...5
×

Like this presentation? Why not share!

# openFrameworks – 関数・クラス、オブジェクト指向プログラミング導入 - 多摩美メディアアートII

## on Sep 28, 2011

• 4,074 views

### Views

Total Views
4,074
Views on SlideShare
2,551
Embed Views
1,523

Likes
2
Downloads
91
Comments
0

### 1 Embed1,523

 http://yoppa.org 1523

### Upload Details

Uploaded via as Adobe PDF

### Report content

• Comment goes here.
Are you sure you want to
Your message goes here
Edit your comment

## openFrameworks – 関数・クラス、オブジェクト指向プログラミング導入 - 多摩美メディアアートIIPresentation Transcript

• ‣‣‣
• ‣ ‣ ‣ ‣ ‣‣
• ‣‣‣ ‣ ‣ ‣
• ‣‣‣
• ‣ :: ( 1, 2, 3...){}‣int testApp::poweroftwo(int a){! return a * a;}‣
• ‣‣‣‣‣‣ofPoint interpolateByPct(float pct);
• ‣#pragma once#include "ofMain.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);!! float pct;! ofPoint currentPos, startPos, endPos;! ofPoint interpolateByPct(float pct);};
• ‣#include "testApp.h"void testApp::setup(){! ofBackground(0, 0, 0);! ofSetFrameRate(60);! ofSetRectMode(OF_RECTMODE_CENTER);! startPos.set(10, 400);! endPos.set(1000, 300);! pct = 0;}void testApp::update(){! pct += 0.01f;! if (pct > 1) {! ! pct = 0;! }!! currentPos = interpolateByPct(pct);}void testApp::draw(){! ofSetColor(31, 127, 255);! ofRect(currentPos.x, currentPos.y, 20, 20);}ofPoint testApp::interpolateByPct(float pct){! ofPoint pos;! pos.x = (1-pct) * startPos.x + (pct) * endPos.x;! pos.y = (1-pct) * startPos.y + (pct) * endPos.y;! return pos;}
• ‣‣‣ ‣ ‣
• ‣#pragma once#include "ofMain.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);!! float pct;! ofPoint currentPos, startPos, endPos;! ofPoint interpolateByPct(float pct);! void fadeToBlack();};
• ‣#include "testApp.h"void testApp::setup(){! ofSetBackgroundAuto(false);! ofSetVerticalSync(true);! ofEnableAlphaBlending();! ofSetFrameRate(60);! ofBackground(0, 0, 0);! startPos.set(10, 400);! endPos.set(1000, 300);! pct = 0;}void testApp::update(){! pct += 0.01f;! if (pct > 1) {! ! pct = 0;! }!! currentPos = interpolateByPct(pct);}void testApp::draw(){! fadeToBlack();! ofSetRectMode(OF_RECTMODE_CENTER);! ofSetColor(31, 127, 255);! ofRect(currentPos.x, currentPos.y, 20, 20);}
• ‣ofPoint testApp::interpolateByPct(float _pct){! float pct = _pct;! ofPoint pos;! pos.x = (1-pct) * startPos.x + (pct) * endPos.x;! pos.y = (1-pct) * startPos.y + (pct) * endPos.y;! return pos;}void testApp::fadeToBlack() {! ofSetRectMode(OF_RECTMODE_CORNER);! ofSetColor(0, 0, 0, 10);! ofRect(0, 0, ofGetWidth(), ofGetHeight());}
• ‣‣‣‣‣‣‣
• ‣#pragma once#include "ofMain.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);!! float pct;! float shaper;! ofPoint currentPos, startPos, endPos;! ofPoint interpolateByPct(float pct, float shaper);! void fadeToBlack();};
• ‣#include "testApp.h"void testApp::setup(){! ofSetBackgroundAuto(false);! ofSetVerticalSync(true);! ofEnableAlphaBlending();! ofSetFrameRate(60);! ofBackground(0, 0, 0);! startPos.set(10, 400);! endPos.set(1000, 300);! pct = 0.0;! shaper = 4.0;}void testApp::update(){! pct += 0.01f;! if (pct > 1) {! ! pct = 0;! }!! currentPos = interpolateByPct(pct, shaper);}
• ‣void testApp::draw(){! fadeToBlack();! ofSetRectMode(OF_RECTMODE_CENTER);! ofSetColor(31, 127, 255);! ofRect(currentPos.x, currentPos.y, 20, 20);}ofPoint testApp::interpolateByPct(float _pct, float _shaper){! float pct = powf(_pct, _shaper);! ofPoint pos;! pos.x = (1-pct) * startPos.x + (pct) * endPos.x;! pos.y = (1-pct) * startPos.y + (pct) * endPos.y;! return pos;}void testApp::fadeToBlack() {! ofSetRectMode(OF_RECTMODE_CORNER);! ofSetColor(0, 0, 0, 10);! ofRect(0, 0, ofGetWidth(), ofGetHeight());}
• ‣‣ ‣ ‣‣ ‣ ‣
• ‣‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣‣‣
• ‣‣ ‣ ‣ ‣ ‣ ‣
• ‣000100 IDENTIFICATION DIVISION.000200 PROGRAM-ID. HELLOWORLD.000300 DATE-WRITTEN. 02/05/96 21:04.000400*AUTHOR BRIAN COLLINS000500 ENVIRONMENT DIVISION.000600 CONFIGURATION SECTION.000700 SOURCE-COMPUTER. RM-COBOL.000800 OBJECT-COMPUTER. RM-COBOL.000900001000 DATA DIVISION.001100 FILE SECTION.001200100000 PROCEDURE DIVISION.100100100200 MAIN-LOGIC SECTION.100300 BEGIN.100400 DISPLAY " " LINE 1 POSITION 1 ERASE EOS.100500 DISPLAY "HELLO, WORLD." LINE 15 POSITION 10.100600 STOP RUN.100700 MAIN-LOGIC-EXIT.100800 EXIT.
• ‣‣ ‣ ‣ ‣
• ‣ ‣ ‣ ‣ ‣
• ‣‣‣‣‣‣
• ‣ ‣ ‣ ‣ ‣ ‣
• ‣‣‣
• ‣‣
• To invent programs, you need to be able to capture abstractions and ex design. It’s the job of a programming language to help you do this. The process of invention and design by letting you encode abstractions tha It should let you make your ideas concrete in the code you write. Surf the architecture of your program.‣‣ All programming languages provide devices that help express abstrac are ways of grouping implementation details, hiding them, and giving‣ a common interface—much as a mechanical object separates its interfa illustrated in “Interface and Implementation” .‣ Figure 2-1 Inte rfa ce a nd Im ple m e nta tion interface implementation 11 10 9 8 7 6
• ‣‣‣
• ‣‣‣‣ getName() getName()
• ‣ ‣ ‣
• ‣‣‣
• ‣‣
• ‣‣‣ ‣ ‣ ‣ ‣ ‣‣ ‣ ‣
• ‣‣‣ ‣‣ ‣‣ ‣
• ‣ ‣ ‣‣‣
• ‣‣
• ‣‣
• ‣#pragma once#include "ofMain.h"#include "Rectangle.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);!! Rectangle myRectangle;};
• ‣#include "testApp.h"void testApp::setup(){! ofSetBackgroundAuto(false);! ofSetVerticalSync(true);! ofEnableAlphaBlending();! ofSetFrameRate(60);! ofBackground(0, 0, 0);!! myRectangle.pos.x = ofGetWidth()/2;! myRectangle.pos.y = ofGetHeight()/2;}void testApp::update(){}void testApp::draw(){! myRectangle.draw();}
• ‣#pragma once#include "ofMain.h"class Rectangle {public:! void draw();! ofPoint pos;};
• ‣#include "rectangle.h"void Rectangle::draw() {! ofFill();! ofSetRectMode(OF_RECTMODE_CENTER);! ofSetColor(31,127,255);! ofRect(pos.x, pos.y, 20,20);}
• ‣‣ ‣‣ ‣ ‣ ‣ ‣ ‣