Sbaw090623

1,578 views

Published on

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,578
On SlideShare
0
From Embeds
0
Number of Embeds
451
Actions
Shares
0
Downloads
11
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Sbaw090623

  1. 1. 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.
  2. 2. getName() getName()
  3. 3. 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
  4. 4. Spot + pos : ofPoint + loc : float
  5. 5. 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); }
  6. 6. 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; // }
  7. 7. #ifndef _OF_SPOT #define _OF_SPOT #include "ofMain.h" class Spot { public: ofPoint pos; float diameter; }; #endif
  8. 8. #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; };
  9. 9. #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); } ...( )...
  10. 10. Spot + pos : ofPoint + loc : float + display( )
  11. 11. #ifndef _OF_SPOT #define _OF_SPOT #include "ofMain.h" class Spot { public: void display(); ofPoint pos; float diameter; }; #endif
  12. 12. #include "Spot.h" void Spot::display() { ofSetColor(0, 127, 255); ofCircle(pos.x, pos.y, diameter); }
  13. 13. #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(); } ...( )...
  14. 14. Spot + pos : ofPoint + loc : float + Spot(pos:ofPoint, loc:float) + display() : void
  15. 15. #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 (*) };
  16. 16. #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(); // "->" } ...( )...
  17. 17. #ifndef _OF_SPOT #define _OF_SPOT #include "ofMain.h" class Spot { public: Spot(ofPoint pos, float diameter); void display(); ofPoint pos; float diameter; }; #endif
  18. 18. #include "Spot.h" Spot::Spot(ofPoint _pos, float _diameter) { pos = _pos; diameter = _diameter; } void Spot::display() { ofSetColor(0, 127, 255); ofCircle(pos.x, pos.y, diameter); }
  19. 19. #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 };
  20. 20. #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(); } } ...( )...
  21. 21. #ifndef _OF_SPOT #define _OF_SPOT #include "ofMain.h" class Spot { public: Spot(ofPoint pos, float diameter); void display(); ofPoint pos; float diameter; }; #endif
  22. 22. #include "Spot.h" Spot::Spot(ofPoint _pos, float _diameter) { pos = _pos; diameter = _diameter; } void Spot::display() { ofSetColor(0, 127, 255); ofCircle(pos.x, pos.y, diameter); }
  23. 23. Spot + pos : ofPoint + loc : float +Spot(pos:ofPoint, velocity:ofPoint, loc:float) +update() : void + display() : void
  24. 24. #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 };
  25. 25. #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; // } }
  26. 26. 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(); } } ...( )...
  27. 27. #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; };
  28. 28. #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; }
  29. 29. 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); }

×