[ Video ]
[ About ]
無作為な文字列ジェネレータ
Random word generator.
[ Source ]
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #pragma once #include "ofMain.h" class ofApp : 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 mouseEntered(int x, int y) {}; 	void mouseExited(int x, int y) {}; 	void windowResized(int w, int h) {}; 	void dragEvent(ofDragInfo dragInfo) {}; 	void gotMessage(ofMessage msg) {}; 	int font_size; 	ofTrueTypeFont font; 	int number_of_words; 	vector<int> number_of_chara; 	vector<int> counts; 	vector<vector<float>> noise_seeds; }; | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #include "ofApp.h"	 //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofSetWindowTitle("openFrameworks"); 	ofBackground(239); 	this->font_size = 80; 	this->font.loadFont("fonts/Kazesawa-Bold.ttf", this->font_size, true, true, true); 	this->number_of_words = 5; 	for (int i = 0; i < this->number_of_words; i++) { 		this->number_of_chara.push_back(0); 		this->counts.push_back(0); 		vector<float> noise_seed; 		this->noise_seeds.push_back(noise_seed); 	} } //-------------------------------------------------------------- void ofApp::update() { 	for (int i = 0; i < this->number_of_words; i++) { 		if (this->counts[i] >= this->number_of_chara[i] * 30) { 			this->number_of_chara[i] = ofRandom(3, 7); 			this->noise_seeds[i].clear(); 			for (int k = 0; k < this->number_of_chara[i]; k++) { 				this->noise_seeds[i].push_back(ofRandom(1000)); 			} 			this->counts[i] = 0; 		} 	} } //-------------------------------------------------------------- void ofApp::draw() { 	ofTranslate(ofGetWidth() * 0.15, ofGetHeight() * 0.15); 	vector<char> charas{ 		'A', 'B', 'C', 'D', 'E', 		'F', 'G', 'H', 'I', 'J', 		'K', 'L', 'M', 'N', 'O', 		'P', 'Q', 'R', 'S', 'T', 		'U', 'V', 'W', 'X', 'Y', 'Z', 		'a', 'b', 'c', 'd', 'e', 		'f', 'g', 'h', 'i', 'j', 		'k', 'l', 'm', 'n', 'o', 		'p', 'q', 'r', 's', 't', 		'u', 'v', 'w', 'x', 'y', 'z' }; 	for (int i = 0; i < this->number_of_words; i++) { 		for (int k = 0; k < this->number_of_chara[i]; k++) { 			ofSetColor(39); 			if (this->counts[i] < k * 30) { 				this->noise_seeds[i][k] += 0.05; 				ofSetColor(150); 			} 			int noise_value = ofMap(ofNoise(this->noise_seeds[i][k]), 0, 1, 0, charas.size()); 			this->font.drawString({ charas[noise_value] }, k * (this->font_size * 1.2) - this->font_size * 0.5, this->font_size * 0.5 + (this->font_size * 1.5) * i); 		} 		this->counts[i]++; 	} } //-------------------------------------------------------------- int main() { 	ofSetupOpenGL(720, 720, OF_WINDOW); 	ofRunApp(new ofApp()); } |