Mais conteúdo relacionado
Mais de Atsushi Tadokoro (20)
openFrameworks 外部ファイルを利用する - 画像、動画 - 多摩美メディアアートII
- 9. ‣
R G B A R G B A R
R G B R G B R G B
K K K K K K K K K
- 13. ‣
#include "testApp.h"
void testApp::setup(){
! ofBackground(0, 0, 0);
!
! //
! myImage.loadImage("t_hero.png");
!
}
void testApp::update(){
}
void testApp::draw(){
! //
! int left = (ofGetWidth() - myImage.width) / 2;
! int top = (ofGetHeight() - myImage.height) / 2;
!
! //
! myImage.draw(left, top);
}
- 17. ‣
#include "testApp.h"
void testApp::setup(){
! ofBackground(0, 0, 0);
!
! //
! myImage.loadImage("t_hero.png");
}
void testApp::update(){
}
void testApp::draw(){
! //
! int left = (ofGetWidth() - myImage.width) / 2;
! int top = (ofGetHeight() - myImage.height) / 2;
! ofTranslate(left, top);
!
! //
! unsigned char * pixels = myImage.getPixels();
- 18. ‣
! //20 Rect
! int skip = 20;
! for (int i = 0; i < myImage.width; i = i + skip){
! ! for (int j = 0; j < myImage.height; j = j + skip){
! ! ! int brightness = pixels[j*myImage.width + i];
! ! ! ofSetColor(brightness, brightness, brightness);
! ! ! ofRect(i, j, skip, skip);!
! ! }
! }
}
- 21. ‣
void testApp::draw(){
! //
! int left = (ofGetWidth() - myImage.width) / 2;
! int top = (ofGetHeight() - myImage.height) / 2;
! ofTranslate(left, top);
!
! //
! unsigned char * pixels = myImage.getPixels();
! //10 Rect
! int skip = 12;
! ofSetColor(0, 0, 0);
! for (int i = 0; i < myImage.width; i = i + skip){
! ! for (int j = 0; j < myImage.height; j = j + skip){
! ! ! int brightness = pixels[j*myImage.width + i];
! ! ! // (%)
! ! ! float pct = 1.0 - brightness / 255.0f;
! ! ! //
! ! ! ofCircle(i, j, pct * skip * 0.5);
! ! }
! }
}
- 24. ‣
void testApp::draw(){
! int left = (ofGetWidth() - myImage.width) / 2;
! int top = (ofGetHeight() - myImage.height) / 2;
! ofTranslate(left, top);
! unsigned char * pixels = myImage.getPixels();
! int skip = 8;
! ofSetColor(255, 255, 255);
! ofSetLineWidth(3);
! for (int i = 0; i < myImage.width; i = i + skip){
! ! for (int j = 0; j < myImage.height; j = j + skip){
! ! ! int brightness = pixels[j*myImage.width + i];
! ! ! float pct = 1.0 - brightness / 255.0f;
! ! ! //
! ! ! ofPushMatrix();
! ! ! ofTranslate(i, j);
! ! ! ofRotateZ(pct * 90);
! ! ! ofLine(-skip, 0, skip, 0);
! ! ! ofPopMatrix();
! ! }
! }
}
- 28. ‣
#include "testApp.h"
void testApp::setup(){
! ofBackground(255, 255, 255);
! //
! myImage.loadImage("t_hero.png");
!
! //8
! pixelString = " .-+*a&@";
!
}
void testApp::update(){!
}
void testApp::draw(){
! int left = (ofGetWidth() - myImage.width) / 2;
! int top = (ofGetHeight() - myImage.height) / 2;
! ofTranslate(left, top);
! unsigned char * pixels = myImage.getPixels();
! int skip = 6;
! ofSetColor(0, 0, 0);
- 29. ‣
!
! for (int i = 0; i < myImage.width; i = i + skip){
! ! for (int j = 0; j < myImage.height; j = j + skip){
! ! ! int brightness = pixels[j*myImage.width + i];
! ! ! float pct = 1.0 - brightness / 255.0f;
! ! ! //
! ! ! string str = pixelString.substr(int(pct * 8),1);
! ! ! //
! ! ! ofDrawBitmapString(str, i, j);
! ! }
! }
}
- 31. ‣
‣
R G B R G B R G B
‣
‣
‣
‣
- 32. ‣
void testApp::draw(){
! //
! int left = (ofGetWidth() - myImage.width) / 2;
! int top = (ofGetHeight() - myImage.height) / 2;
! ofTranslate(left, top);
!
! //
! unsigned char * pixels = myImage.getPixels();
! //10 Rect
! int skip = 10;
! for (int i = 0; i < myImage.width; i = i + skip){
! ! for (int j = 0; j < myImage.height; j = j + skip){
! ! ! //RGB
! ! ! int r = pixels[j * myImage.width * 3 + i * 3];
! ! ! int g = pixels[j * myImage.width * 3 + i * 3 + 1];
! ! ! int b = pixels[j * myImage.width * 3 + i * 3 + 2];
! ! ! //
! ! ! ofSetColor(r, g, b);
! ! ! ofRect(i, j, skip, skip);!
! ! }
! }
}
- 35. ‣
void testApp::draw(){
! int left = (ofGetWidth() - myImage.width) / 2;
! int top = (ofGetHeight() - myImage.height) / 2;
! ofTranslate(left, top);
! unsigned char * pixels = myImage.getPixels();
! int skip = 8;
! for (int i = 0; i < myImage.width; i = i + skip){
! ! for (int j = 0; j < myImage.height; j = j + skip){
! ! ! int r = pixels[j * myImage.width * 3 + i * 3];
! ! ! int g = pixels[j * myImage.width * 3 + i * 3 + 1];
! ! ! int b = pixels[j * myImage.width * 3 + i * 3 + 2];
! ! ! int brightness = (r + g + b) / 3.0f * 255.0f;
! ! ! float pct = 1.0 - (r + g + b) / 3.0f / 255.0f;
! ! ! //
! ! ! ofSetColor(r, g, b);
! ! ! ofPushMatrix();
! ! ! ofTranslate(i, j);
! ! ! ofRotateZ(pct * 360);
! ! ! ofLine(-pct*skip*4, 0, pct*skip*4, 0);
! ! ! ofPopMatrix();
! ! }
! }
}
- 41. ‣
#include "testApp.h"
void testApp::setup(){
! ofSetFrameRate(60);
! ofBackground(0, 0, 0);
! //640x480 pixel
myVideo.initGrabber(640, 480, true);
}
void testApp::update(){
! //
myVideo.update();
}
void testApp::draw(){
! //
! int left = (ofGetWidth() - myVideo.width) / 2;
! int top = (ofGetHeight() - myVideo.height) / 2;
! ofTranslate(left, top);
!
! //
! myVideo.draw(0, 0);
}
- 43. ‣
#include "testApp.h"
void testApp::setup(){
! ofSetFrameRate(60);
! ofBackground(0, 0, 0);
! ofSetRectMode(OF_RECTMODE_CENTER);
!
! //640x480 pixel
myVideo.initGrabber(800, 600, true);
}
void testApp::update(){
! //
myVideo.update();
}
void testApp::draw(){
! //
! int left = (ofGetWidth() - myVideo.width) / 2;
! int top = (ofGetHeight() - myVideo.height) / 2;
! ofTranslate(left, top);
!
! //
! unsigned char * pixels = myVideo.getPixels();
- 44. ‣
! int skip = 12;
! for (int i = 0; i < myVideo.width; i = i + skip){
! ! for (int j = 0; j < myVideo.height; j = j + skip){
//RGB
int r = pixels[j * myVideo.width * 3 + i * 3];
! ! ! int g = pixels[j * myVideo.width * 3 + i * 3 + 1];
! ! ! int b = pixels[j * myVideo.width * 3 + i * 3 + 2];
! ! ! //
! ! ! int brightness = (r + g + b) / 3.0f * 255.0f;
! ! ! float pct = (r + g + b) / 3.0f / 255.0f;
! ! ! //
! ! ! ofSetColor(255,255,255);
! ! ! ofPushMatrix();
! ! ! ofTranslate(i, j);
! ! ! ofRotateZ(pct * 180);
! ! ! ofRect(0, 0, skip * pct, skip * pct);
! ! ! ofPopMatrix();
! ! }
! }
}
- 47. ‣
#include "testApp.h"
void testApp::setup(){
! ofSetFrameRate(60);
! ofBackground(255, 255, 255);
! ofSetRectMode(OF_RECTMODE_CENTER);
! //8
! pixelString = " .-+*a&@";
! //640x480 pixel
myVideo.initGrabber(800, 600, true);
}
void testApp::update(){
! //
myVideo.update();
}
void testApp::draw(){
! //
! int left = (ofGetWidth() - myVideo.width) / 2;
! int top = (ofGetHeight() - myVideo.height) / 2;
! //
! unsigned char * pixels = myVideo.getPixels();
- 48. ‣
! int skip = 8;
! ofTranslate(left, top+skip);
! ofSetColor(0, 0, 0);
! for (int i = 0; i < myVideo.width; i = i + skip){
! ! for (int j = 0; j < myVideo.height; j = j + skip){
! ! ! //RGB
! ! ! int r = pixels[j * myVideo.width * 3 + i * 3];
! ! ! int g = pixels[j * myVideo.width * 3 + i * 3 + 1];
! ! ! int b = pixels[j * myVideo.width * 3 + i * 3 + 2];
! ! ! //
! ! ! float pct = 1.0 - (r + g + b) / 3.0f / 255.0f;
! ! ! //
! ! ! string str = pixelString.substr(int(pct * 8),1);
! ! ! //
! ! ! ofDrawBitmapString(str, i, j);
! ! }
! }
}
- 53. ‣
#pragma once
#include "ofMain.h"
class testApp : public ofBaseApp {
!
public:
! void setup();
! void update();
! void draw();
! void keyPressed(int key);
! void mousePressed(int x, int y, int button);
!
! void reset();
! ofImage img;
! ofImageQualityType quality;
};
- 54. ‣
#include "testApp.h"
void testApp::setup() {
! ofSetFrameRate(60);
! ofSetBackgroundAuto(false);
! //Jpeg
! quality = OF_IMAGE_QUALITY_WORST;
! //
! reset();
}
void testApp::reset() {
! //
! img.loadImage("input.jpg");
}
void testApp::update() {
! //Jpeg
! string compressedFilename = "compressed.jpg";
! //Jpeg
! img.saveImage(compressedFilename, quality);
! ofBuffer file = ofBufferFromFile(compressedFilename);
! int fileSize = file.size();
- 55. ‣
! //Jepg
! char * buffer = file.getBinaryBuffer();
! //
! int whichByte = (int) ofRandom(fileSize);
! //ON bit
! int whichBit = ofRandom(8);
! // ( ?)
! char bitMask = 1 << whichBit;
! buffer[whichByte] |= bitMask;
! //glitch
! ofBufferToFile(compressedFilename, file);
! //
! img.loadImage(compressedFilename);
}
void testApp::draw() {
! //glitch
! ofSetColor(255,255,255);
! img.draw(0, 0, ofGetWidth(), ofGetHeight());
}
- 56. ‣
void testApp::keyPressed (int key){
! //
! reset();
}
void testApp::mousePressed(int x, int y, int button){
! //
! reset();
}
- 59. ‣
#pragma once
#include "ofMain.h"
class testApp : public ofBaseApp {
!
public:
! void setup();
! void update();
! void draw();
! void keyPressed(int key);
! void mousePressed(int x, int y, int button);
!
! void reset();!
! ofImage img;
! ofImageQualityType quality;
! ofVideoGrabber myVideo;
};
- 60. ‣
#include "testApp.h"
void testApp::setup() {
! ofSetFrameRate(60);
! quality = OF_IMAGE_QUALITY_WORST;
! //
! myVideo.initGrabber(320, 240, true);
! // ofImage
! img.grabScreen(0, 0, ofGetWidth(), ofGetHeight());
}
void testApp::reset() {
! //
! myVideo.update();
! // 1
! myVideo.draw(0, 0, ofGetWidth(), ofGetHeight());
! // ofImage
! img.grabScreen(0, 0, ofGetWidth(), ofGetHeight());
}
- 61. ‣
void testApp::update() {
! //Jpeg
! string compressedFilename = "compressed.jpg";
! //Jpeg
! img.saveImage(compressedFilename, quality);
! ofBuffer file = ofBufferFromFile(compressedFilename);
! int fileSize = file.size();
! //Jepg
! char * buffer = file.getBinaryBuffer();
! //
! int whichByte = (int) ofRandom(fileSize);
! //ON bit
! int whichBit = ofRandom(8);
! // ( ?)
! char bitMask = 1 << whichBit;
! buffer[whichByte] |= bitMask;
! //glitch
! ofBufferToFile(compressedFilename, file);
! //
! img.loadImage(compressedFilename);
- 62. ‣
! //
! float coin = ofRandom(100);
! if (coin > 95) {
! ! reset();
! }
}
void testApp::draw() {
! //glitch
! ofSetColor(255);
! img.draw(0, 0, ofGetWidth(), ofGetHeight());
}
void testApp::keyPressed (int key){
! reset();
}
void testApp::mousePressed(int x, int y, int button){
! reset();
}