C++ (openFrameworks) 画像をランダム位置に表示

Random Images

bin/data ディレクトリに sample.jpg を格納しておいて実行します。
キーボードの S を押すと画像が表示されます。

C++: main.cpp

#include "testApp.h"
#include "ofAppGlutWindow.h"

//--------------------------------------------------------------
int main(){
	ofAppGlutWindow window; // create a window
	// set width, height, mode (OF_WINDOW or OF_FULLSCREEN)
	ofSetupOpenGL(&window, 1024, 768, OF_WINDOW);
	ofRunApp(new testApp()); // start the app
}

C++: testApp.h

#pragma once

#include "ofMain.h"

class testApp : public ofBaseApp{
	public:
		void setup();
		void update();
		void draw();
		
		void keyPressed(int key);
		void keyReleased(int key);
		void mouseMoved(int x, int y);
		void mouseDragged(int x, int y, int button);
		void mousePressed(int x, int y, int button);
		void mouseReleased(int x, int y, int button);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);
    
        
};

C++: testApp.cpp

#include "testApp.h"
ofImage image;

vector <ofPoint *> points;

//--------------------------------------------------------------
void testApp::setup(){
	ofBackground(0,0,0);
	ofEnableSmoothing();
    image.loadImage("sample.jpg");
}

//--------------------------------------------------------------
void testApp::update(){
}

//--------------------------------------------------------------
void testApp::draw(){
    for (int i = 0; i < points.size(); i++) {
        image.draw(points[i]->x,points[i]->y,100,100);
    }
}

//--------------------------------------------------------------
void testApp::keyPressed(int key){
    if (key == 's' || key == 'S') {
        int x = rand() % 1024;
        int y = rand() % 768;
        ofLog(OF_LOG_NOTICE, ofToString(x) + "," + ofToString(y));
        points.push_back(new ofPoint(x,y));
    }
}

//--------------------------------------------------------------
void testApp::keyReleased(int key){

}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y){

}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){ 

}