More Related Content Similar to openFrameworks – 関数・クラス、オブジェクト指向プログラミング導入 - 多摩美メディアアートII Similar to openFrameworks – 関数・クラス、オブジェクト指向プログラミング導入 - 多摩美メディアアートII (20) More from Atsushi Tadokoro More from Atsushi Tadokoro (20) openFrameworks – 関数・クラス、オブジェクト指向プログラミング導入 - 多摩美メディアアートII7. ‣
:: ( 1, 2, 3...){
}
‣
int testApp::poweroftwo(int a){
! return a * a;
}
‣
9. ‣
#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);
};
10. ‣
#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;
}
12. ‣
#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();
};
13. ‣
#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);
}
14. ‣
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());
}
17. ‣
#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();
};
18. ‣
#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);
}
19. ‣
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());
}
24. ‣
‣
‣
‣
‣
‣
‣
‣
‣
‣
‣
‣
‣
27. ‣
000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. HELLOWORLD.
000300 DATE-WRITTEN. 02/05/96 21:04.
000400*AUTHOR BRIAN COLLINS
000500 ENVIRONMENT DIVISION.
000600 CONFIGURATION SECTION.
000700 SOURCE-COMPUTER. RM-COBOL.
000800 OBJECT-COMPUTER. RM-COBOL.
000900
001000 DATA DIVISION.
001100 FILE SECTION.
001200
100000 PROCEDURE DIVISION.
100100
100200 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.
37. 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
44. ‣
‣
‣
‣
‣
‣
‣
‣
‣
‣
‣
54. ‣
#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;
};
55. ‣
#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();
}