Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
logiciels:openframeworks:atelier:accueil [2015/03/11 21:44] resonance [Atelier OpenFrameworks] |
logiciels:openframeworks:atelier:accueil [2016/02/01 00:11] resonance |
||
---|---|---|---|
Ligne 3: | Ligne 3: | ||
<WRAP round download 55%> | <WRAP round download 55%> | ||
- | Télécharger tous les fichiers (25 Mo): {{: | + | **Tous |
</ | </ | ||
Ligne 9: | Ligne 9: | ||
Pour commencer, il faut trois fichiers : main.cpp, ofApp.h et ofApp.cpp. Ces fichiers sont générés par le // | Pour commencer, il faut trois fichiers : main.cpp, ofApp.h et ofApp.cpp. Ces fichiers sont générés par le // | ||
- | |||
++++ main.cpp | | ++++ main.cpp | | ||
Ligne 646: | Ligne 645: | ||
ofPopMatrix(); | ofPopMatrix(); | ||
easyCam.end(); | easyCam.end(); | ||
+ | } | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ===== Cours 7 : vidéo ASCII ===== | ||
+ | * Fichier police à mettre dans " | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ++++ ofApp.h | | ||
+ | <code cpp> | ||
+ | #pragma once | ||
+ | #include " | ||
+ | |||
+ | class ofApp : public ofBaseApp{ | ||
+ | |||
+ | public: | ||
+ | void setup(); | ||
+ | void update(); | ||
+ | void draw(); | ||
+ | void keyPressed(int key); | ||
+ | |||
+ | ofVideoGrabber vidGrabber; | ||
+ | int camWidth; | ||
+ | int camHeight; | ||
+ | string asciiCharacters; | ||
+ | ofTrueTypeFont | ||
+ | }; | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++ ofApp.cpp | | ||
+ | <code cpp> | ||
+ | #include " | ||
+ | |||
+ | void ofApp:: | ||
+ | ofBackground(0, | ||
+ | ofSetFrameRate(60); | ||
+ | ofEnableAlphaBlending(); | ||
+ | camWidth = 640; // try to grab at this size. | ||
+ | camHeight = 480; | ||
+ | vidGrabber.setVerbose(true); | ||
+ | vidGrabber.initGrabber(camWidth, | ||
+ | font.loadFont(" | ||
+ | |||
+ | //this set of characters comes from processing: | ||
+ | // | ||
+ | //changed order slightly to work better for mapping | ||
+ | asciiCharacters = string(" | ||
+ | } | ||
+ | |||
+ | void ofApp:: | ||
+ | vidGrabber.update(); | ||
+ | } | ||
+ | |||
+ | void ofApp:: | ||
+ | // change background video alpha value based on the mouse position | ||
+ | // float videoAlphaValue = ofMap(mouseX, | ||
+ | // ofSetColor(255, | ||
+ | // vidGrabber.draw(0, | ||
+ | |||
+ | ofPixelsRef pixelsRef = vidGrabber.getPixelsRef(); | ||
+ | ofSetHexColor(0xffffff); | ||
+ | |||
+ | for (int i = 0; i < camWidth; i+= 7){ | ||
+ | for (int j = 0; j < camHeight; j+= 9){ | ||
+ | // get the pixel and its lightness (lightness is the average of its RGB values) | ||
+ | float lightness = pixelsRef.getColor(i, | ||
+ | // calculate the index of the character from our asciiCharacters array | ||
+ | int character = powf( ofMap(lightness, | ||
+ | // draw the character at the correct location | ||
+ | font.drawString(ofToString(asciiCharacters[character]), | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void ofApp:: | ||
+ | // in fullscreen mode, on a pc at least, the | ||
+ | // first time video settings the come up | ||
+ | // they come up *under* the fullscreen window | ||
+ | // use alt-tab to navigate to the settings | ||
+ | // window. we are working on a fix for this... | ||
+ | if (key == ' | ||
+ | vidGrabber.videoSettings(); | ||
+ | } | ||
} | } | ||
</ | </ | ||
++++ | ++++ |