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:07] resonance |
logiciels:openframeworks:atelier:accueil [2016/02/01 00:11] (Version actuelle) resonance |
||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== Atelier OpenFrameworks ====== | ====== Atelier OpenFrameworks ====== | ||
| - | Pour commencer, il faut trois fichiers | + | Atelier donné au Fablab LFO pour les [[http:// |
| + | |||
| + | <WRAP round download 55%> | ||
| + | **Tous les fichiers | ||
| + | </ | ||
| ===== Fichiers ===== | ===== Fichiers ===== | ||
| + | |||
| + | 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 438: | Ligne 444: | ||
| ===== Cours 5 : fichier ===== | ===== Cours 5 : fichier ===== | ||
| + | * Fichiers police et textes : {{: | ||
| {{: | {{: | ||
| Ligne 525: | Ligne 532: | ||
| ===== Cours 6 : Mesh ===== | ===== Cours 6 : Mesh ===== | ||
| - | * Fichier image :[[: | + | * Fichier image : {{: |
| {{: | {{: | ||
| Ligne 638: | 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(); | ||
| + | } | ||
| } | } | ||
| </ | </ | ||
| ++++ | ++++ | ||