More Related Content Similar to Sbaw090623 (20) More from Atsushi Tadokoro More from Atsushi Tadokoro (20) Sbaw0906235. 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.
13. 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
18. Spot sp; //
void setup() {
size(400, 400);
smooth();
noStroke();
sp = new Spot(); // ( )
sp.x = 150; // x 150
sp.y = 200; // y 200
sp.diameter = 30; // diameter 30
}
void draw() {
background(0);
ellipse(sp.x, sp.y, sp.diameter, sp.diameter);
}
19. Spot sp; //
void setup() {
size(400, 400);
smooth();
noStroke();
sp = new Spot(); // ( )
sp.x = 150; // x 150
sp.y = 200; // y 200
sp.diameter = 30; // diameter 30
}
void draw() {
background(0);
ellipse(sp.x, sp.y, sp.diameter, sp.diameter);
}
class Spot {
float x, y; // x y
float diameter; //
}
26. #pragma once
#include "ofMain.h"
#include "ofxAccelerometer.h"
#include "ofxMultiTouch.h"
#include "Spot.h"
class testApp : public ofSimpleApp, public ofxMultiTouchListener {
public:
void setup();
void update();
void draw();
void exit();
...( )...
private:
Spot sp;
};
27. #include "testApp.h"
#include "Spot.h"
void testApp::setup(){
sp.pos.x = ofGetWidth()/2;
sp.pos.y = ofGetHeight()/2;
sp.diameter = 100;
}
void testApp::update(){
}
void testApp::draw(){
ofEnableSmoothing();
ofSetColor(0, 127, 255);
ofCircle(sp.pos.x, sp.pos.y, sp.diameter);
}
...( )...
33. #include "testApp.h"
#include "Spot.h"
void testApp::setup(){
sp.pos.x = ofGetWidth()/2;
sp.pos.y = ofGetHeight()/2;
sp.diameter = 100;
}
void testApp::update(){
}
void testApp::draw(){
sp.display();
}
...( )...
37. Spot
+ pos : ofPoint
+ loc : float
+ Spot(pos:ofPoint, loc:float)
+ display() : void
38. #pragma once
#include "ofMain.h"
#include "ofxAccelerometer.h"
#include "ofxMultiTouch.h"
#include "Spot.h"
class testApp : public ofSimpleApp, public ofxMultiTouchListener {
public:
void setup();
void update();
void draw();
void exit();
...( )...
private:
Spot *sp; //Spot sp (*)
};
39. #include "testApp.h"
#include "Spot.h"
void testApp::setup(){
ofPoint _pos;
_pos.x = ofGetWidth()/2;
_pos.y = ofGetHeight()/2;
sp = new Spot(_pos, 100.0); //
}
void testApp::update(){
}
void testApp::draw(){
sp->display(); // "->"
}
...( )...
44. #pragma once
#include "ofMain.h"
#include "ofxAccelerometer.h"
#include "ofxMultiTouch.h"
#include "Spot.h"
class testApp : public ofSimpleApp, public ofxMultiTouchListener {
public:
void setup();
void update();
void draw();
void exit();
...( )...
private:
Spot** sp; //Spot sp (**)
int numSpot; // Spot
};
45. #include "testApp.h"
#include "Spot.h"
void testApp::setup(){
numSpot = 100;
sp = new Spot*[numSpot]; //
for(int i = 0; i < numSpot; i++){
ofPoint _pos;
_pos.x = ofRandom(0, ofGetWidth());
_pos.y = ofRandom(0, ofGetHeight());
float _diameter = ofRandom(1, 20);
sp[i] = new Spot(_pos, _diameter); //
}
}
void testApp::update(){
}
void testApp::draw(){
for(int i = 0; i < numSpot; i++){
sp[i]->display();
}
}
...( )...
50. Spot
+ pos : ofPoint
+ loc : float
+Spot(pos:ofPoint, velocity:ofPoint, loc:float)
+update() : void
+ display() : void
51. #pragma once
#include "ofMain.h"
#include "ofxAccelerometer.h"
#include "ofxMultiTouch.h"
#include "Spot.h"
class testApp : public ofSimpleApp, public ofxMultiTouchListener {
public:
void setup();
void update();
void draw();
void exit();
...( )...
private:
Spot** sp; //Spot sp (**)
int numSpot; // Spot
};
52. #include "testApp.h"
#include "Spot.h"
void testApp::setup(){
ofSetFrameRate(60);
ofEnableAlphaBlending();
ofSetBackgroundAuto(false);
numSpot = 100;
sp = new Spot*[numSpot]; //
for(int i = 0; i < numSpot; i++){
ofPoint _pos, _velocity;
_pos.x = ofRandom(0, ofGetWidth());
_pos.y = ofRandom(0, ofGetHeight());
_velocity.x = ofRandom(-10, 10);
_velocity.y = ofRandom(-30, -10);
float _diameter = ofRandom(1, 20);
sp[i] = new Spot(_pos, _velocity, _diameter); //
sp[i]->gravity = 0.5; //
sp[i]->friction = 0.999; //
}
}
53. void testApp::update(){
ofSetColor(0, 0, 0, 31);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
for(int i = 0; i < numSpot; i++){
sp[i]->update();
}
}
void testApp::draw(){
for(int i = 0; i < numSpot; i++){
sp[i]->display();
}
}
...( )...
54. #ifndef _OF_SPOT
#define _OF_SPOT
#include "ofMain.h"
class Spot {
public:
Spot(ofPoint pos, ofPoint velocity, float diameter);
void update();
void display();
ofPoint pos;
ofPoint velocity;
float diameter;
float gravity;
float friction;
};
55. #include "Spot.h"
Spot::Spot(ofPoint _pos, ofPoint _velocity, float _diameter)
{
pos = _pos;
velocity = _velocity;
diameter = _diameter;
}
void Spot::update()
{
velocity *= friction;
velocity.y += gravity;
pos.x += velocity.x;
pos.y += velocity.y;
if(pos.x < diameter || pos.x > ofGetWidth() - diameter){
velocity.x *= -1;
}
56. if(pos.y > ofGetHeight()-diameter){
velocity.y *= -1;
pos.y = ofGetHeight()-diameter;
}
}
void Spot::display()
{
ofSetColor(0, 127, 255, 200);
ofCircle(pos.x, pos.y, diameter);
}