openFrameworksで背景をグラデーションにする
openFrameworksの背景を簡単にグラデーションにするofBackgroundGradientという関数があるので試してみた.
OF_GRADIENT_CIRCULAR
OF_GRADIENT_LINEAR
OF_GRADIENT_BAR
本当は,modeの設定をラジオボタンにしたかったが,ofxGuiでのやり方がわからず断念.そもそもofxGuiにラジオボタンがあるのかな?
ofMain.h
#pragma once
#include "ofMain.h"
#include "ofxGui.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);
ofxPanel gui;
ofParameter startColor, endColor;
ofParameter mode_id;
};
ofMain.cpp
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
gui.setup();
gui.add(mode_id.set("mode", 0, 0, 2));
gui.add(startColor.set("start color", ofColor(54, 230, 140), ofColor(0, 0), ofColor(255, 255)));
gui.add(endColor.set("end color", ofColor(255, 140, 0), ofColor(0, 0), ofColor(255, 255)));
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
ofGradientMode mode;
switch(mode_id){
case 0:
mode = OF_GRADIENT_CIRCULAR;
break;
case 1:
mode = OF_GRADIENT_LINEAR;
break;
case 2:
mode = OF_GRADIENT_BAR;
break;
}
ofBackgroundGradient(startColor, endColor, mode);
gui.draw();
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){
}
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}
openFrameworks/backgroundGradient at master · aa-debdeb/openFrameworks