#include "ofApp.h"
void ofApp::setup(){
ofSetFrameRate(60);
ofBackground(50);
angle=0;
cosine=0;
sine=0;
tangent=0;
rotationSpeed=0.01;
radius = 180;
center = {ofGetWidth()*0.3f, ofGetHeight()*0.6f, 0 };
ofSetCircleResolution(40);
angleArc.setCircleResolution(360);
angleArc.setFilled(true);
angleArc.setColor(ofColor(240, 130, 10));
}
void ofApp::update(){
if (!ofGetMousePressed()) {
angle+=rotationSpeed;
}
angle = ofWrap(angle, 0, TWO_PI);
cosine=cos(angle);
sine=sin(angle);
tangent=tan(angle);
point = { cosine * radius, sine * radius, 0 };
angleArc.clear();
angleArc.arc( 0, 0, radius * 0.5f, radius * 0.5f, 0, ofRadToDeg(angle));
angleArc.lineTo(0,0);
angleArc.close();
}
void ofApp::draw(){
ofTranslate(center);
ofSetColor(240, 230, 10);
ofDrawCircle(0,0, radius);
ofSetColor(0, 140, 255);
ofDrawCircle(point, 10);
angleArc.draw();
ofSetColor(20);
ofSetLineWidth(1);
ofDrawLine(-radius * 1.3f, 0, radius * 2, 0);
ofDrawLine(0, -radius * 2, 0, radius * 1.3f);
ofSetColor(180);
ofDrawLine(0, -radius , radius * 2, -radius);
ofDrawLine(0, radius , radius * 2, radius);
ofDrawLine(-radius, 0 ,-radius, -radius * 2);
ofDrawLine( radius, 0 , radius, -radius * 2);
ofSetColor(255, 0, 127);
ofDrawRectangle(0, -radius * 2, cosine * radius, 20);
ofDrawRectangle(radius * 2, 0, -20, sine * radius);
ofSetLineWidth(3);
ofSetColor(255, 0, 50);
ofDrawLine(point.x, point.y, cosine * radius, -radius * 2);
ofDrawLine(point.x, point.y, radius * 2, sine * radius);
ofSetColor(0, 127, 255);
ofDrawLine(0, 0, point.x, point.y);
ofSetColor(40);
ofDrawLine(0, sine * radius, cosine * radius, sine * radius);
ofDrawLine(cosine * radius, 0, cosine * radius, sine * radius);
ofSetColor(10);
ofDrawBitmapString("Angle (RAD): " + ofToString(angle), 3,-3);
ofSetColor(30);
ofDrawBitmapString("Angle (DEG): " + ofToString(ofRadToDeg(angle)), 3,20);
ofDrawBitmapString("Radius: " + ofToString(radius), -radius +20, -3);
ofSetColor(220);
ofDrawBitmapString("Angle Sine: " + ofToString(sine), radius *2 +3, 0);
ofDrawBitmapString("sine x radius: " + ofToString(sine * radius), radius *2 +3, 15 );
ofDrawBitmapString("Angle cosine: " + ofToString(cosine), 0, -radius *2 -20);
ofDrawBitmapString("cosine x radius: " + ofToString(cosine * radius), 0, -radius *2 -5 );
}
void ofApp::keyPressed(int key){
}
void ofApp::keyReleased(int key){
}
void ofApp::mouseMoved(int x, int y ){
}
void ofApp::checkMouse(float x, float y){
glm::vec2 mousePos(x-center.x, y-center.y);
if (glm::length(mousePos) < radius ) {
angle = atan2( mousePos.y , mousePos.x);
angle = ofWrap(angle, 0, TWO_PI);
}
}
void ofApp::mouseDragged(int x, int y, int button){
checkMouse(x,y);
}
void ofApp::mousePressed(int x, int y, int button){
checkMouse(x,y);
}
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){
}
Comments