#include "ofApp.h"
void ofApp::setup(){
ofBackground(255,255,255);
ofSetFrameRate(60);
nCurveVertices = 7;
curveVertices[0].x = 326;
curveVertices[0].y = 209;
curveVertices[1].x = 306;
curveVertices[1].y = 279;
curveVertices[2].x = 265;
curveVertices[2].y = 331;
curveVertices[3].x = 304;
curveVertices[3].y = 383;
curveVertices[4].x = 374;
curveVertices[4].y = 383;
curveVertices[5].x = 418;
curveVertices[5].y = 309;
curveVertices[6].x = 345;
curveVertices[6].y = 279;
for (int i = 0; i < nCurveVertices; i++){
curveVertices[i].bOver = false;
curveVertices[i].bBeingDragged = false;
curveVertices[i].radius = 4;
}
}
void ofApp::update(){
}
void ofApp::draw(){
ofFill();
ofSetHexColor(0xe0be21);
ofSetPolyMode(OF_POLY_WINDING_ODD);
ofBeginShape();
ofVertex(200,135);
ofVertex(15,135);
ofVertex(165,25);
ofVertex(105,200);
ofVertex(50,25);
ofEndShape();
ofSetHexColor(0xb5de10);
ofSetPolyMode(OF_POLY_WINDING_NONZERO);
ofBeginShape();
ofVertex(400,135);
ofVertex(215,135);
ofVertex(365,25);
ofVertex(305,200);
ofVertex(250,25);
ofEndShape();
float xPct = (float)(mouseX) / (float)(ofGetWidth());
float yPct = (float)(mouseY) / (float)(ofGetHeight());
int nTips = 5 + xPct * 60;
int nStarPts = nTips * 2;
float angleChangePerPt = TWO_PI / (float)nStarPts;
float innerRadius = 0 + yPct*80;
float outerRadius = 80;
float origx = 525;
float origy = 100;
float angle = 0;
ofSetHexColor(0xa16bca);
ofBeginShape();
for (int i = 0; i < nStarPts; i++){
if (i % 2 == 0) {
float x = origx + innerRadius * cos(angle);
float y = origy + innerRadius * sin(angle);
ofVertex(x,y);
} else {
float x = origx + outerRadius * cos(angle);
float y = origy + outerRadius * sin(angle);
ofVertex(x,y);
}
angle += angleChangePerPt;
}
ofEndShape();
ofSetHexColor(0x0cb0b6);
ofSetPolyMode(OF_POLY_WINDING_ODD);
ofBeginShape();
for (int i = 0; i < 10; i++){
ofVertex(ofRandom(650,850), ofRandom(20,200));
}
ofEndShape();
ofPushMatrix();
ofTranslate(100,300,0);
ofSetHexColor(0xff2220);
ofFill();
ofSetPolyMode(OF_POLY_WINDING_ODD);
ofBeginShape();
float angleStep = TWO_PI/(100.0f + sin(ofGetElapsedTimef()/5.0f) * 60);
float radiusAdder = 0.5f;
float radius = 0;
for (int i = 0; i < 200; i++){
float anglef = (i) * angleStep;
float x = radius * cos(anglef);
float y = radius * sin(anglef);
ofVertex(x,y);
radius += radiusAdder;
}
ofEndShape(OF_CLOSE);
ofPopMatrix();
ofSetHexColor(0x2bdbe6);
ofBeginShape();
for (int i = 0; i < nCurveVertices; i++){
if (i == 0){
ofCurveVertex(curveVertices[0].x, curveVertices[0].y);
ofCurveVertex(curveVertices[0].x, curveVertices[0].y);
} else if (i == nCurveVertices-1){
ofCurveVertex(curveVertices[i].x, curveVertices[i].y);
ofCurveVertex(curveVertices[0].x, curveVertices[0].y);
ofCurveVertex(curveVertices[0].x, curveVertices[0].y);
} else {
ofCurveVertex(curveVertices[i].x, curveVertices[i].y);
}
}
ofEndShape();
ofEnableAlphaBlending();
ofNoFill();
ofSetColor(0,0,0,40);
ofBeginShape();
for (int i = 0; i < nCurveVertices; i++){
ofVertex(curveVertices[i].x, curveVertices[i].y);
}
ofEndShape(true);
ofSetColor(0,0,0,80);
for (int i = 0; i < nCurveVertices; i++){
if (curveVertices[i].bOver == true) ofFill();
else ofNoFill();
ofDrawCircle(curveVertices[i].x, curveVertices[i].y,4);
}
ofDisableAlphaBlending();
float x0 = 500;
float y0 = 300;
float x1 = 550+50*cos(ofGetElapsedTimef()*1.0f);
float y1 = 300+100*sin(ofGetElapsedTimef()/3.5f);
float x2 = 600+30*cos(ofGetElapsedTimef()*2.0f);
float y2 = 300+100*sin(ofGetElapsedTimef());
float x3 = 650;
float y3 = 300;
ofFill();
ofSetHexColor(0xFF9933);
ofBeginShape();
ofVertex(x0,y0);
ofBezierVertex(x1,y1,x2,y2,x3,y3);
ofEndShape();
ofEnableAlphaBlending();
ofFill();
ofSetColor(0,0,0,40);
ofDrawCircle(x0,y0,4);
ofDrawCircle(x1,y1,4);
ofDrawCircle(x2,y2,4);
ofDrawCircle(x3,y3,4);
ofDisableAlphaBlending();
ofFill();
ofSetHexColor(0xd3ffd3);
ofDrawRectangle(80,480,140,70);
ofSetHexColor(0xff00ff);
ofBeginShape();
ofVertex(100,500);
ofVertex(180,550);
ofVertex(100,600);
ofNextContour(true);
ofVertex(120,520);
ofVertex(160,550);
ofVertex(120,580);
ofEndShape(true);
ofNoFill();
ofPushMatrix();
ofSetPolyMode(OF_POLY_WINDING_ODD);
ofBeginShape();
ofVertex(300,500);
ofVertex(380,550);
ofVertex(300,600);
ofNextContour(true);
for (int i = 0; i < 20; i++){
float anglef = ((float)i / 19.0f) * TWO_PI;
float x = 340 + 30 * cos(anglef);
float y = 550 + 30 * sin(anglef);
ofVertex(x,y);
radius += radiusAdder;
}
ofEndShape(true);
ofTranslate(100,0,0);
ofSetPolyMode(OF_POLY_WINDING_NONZERO);
ofBeginShape();
ofVertex(300,500);
ofVertex(380,550);
ofVertex(300,600);
ofNextContour(true);
for (int i = 0; i < 20; i++){
float anglef = ((float)i / 19.0f) * TWO_PI;
float x = 340 + 30 * cos(anglef);
float y = 550 + 30 * sin(anglef);
ofVertex(x,y);
radius += radiusAdder;
}
ofEndShape(true);
ofTranslate(100,0,0);
ofSetPolyMode(OF_POLY_WINDING_ABS_GEQ_TWO);
ofBeginShape();
ofVertex(300,500);
ofVertex(380,550);
ofVertex(300,600);
ofNextContour(true);
for (int i = 0; i < 20; i++){
float anglef = ((float)i / 19.0f) * TWO_PI;
float x = 340 + 30 * cos(anglef);
float y = 550 + 30 * sin(anglef);
ofVertex(x,y);
radius += radiusAdder;
}
ofEndShape(true);
ofPopMatrix();
ofSetHexColor(0x000000);
ofDrawBitmapString("(a) star\nwinding rule odd", 20,210);
ofSetHexColor(0x000000);
ofDrawBitmapString("(b) star\nwinding rule nonzero", 220,210);
ofSetHexColor(0x000000);
ofDrawBitmapString("(c) dynamically\ncreated shape", 420,210);
ofSetHexColor(0x000000);
ofDrawBitmapString("(d) random points\npoly", 670,210);
ofSetHexColor(0x000000);
ofDrawBitmapString("(e) fun with sin/cos", 20,410);
ofSetHexColor(0x000000);
ofDrawBitmapString("(f) ofCurveVertex\nuses catmull rom\nto make curved shapes", 220,410);
ofSetHexColor(0x000000);
ofDrawBitmapString("(g) ofBezierVertex\nuses bezier to draw curves", 460,410);
ofSetHexColor(0x000000);
ofDrawBitmapString("(h) ofNextContour\nallows for holes", 20,610);
ofSetHexColor(0x000000);
ofDrawBitmapString("(i) ofNextContour\ncan even be used for CSG operations\nsuch as union and intersection", 260,620);
}
void ofApp::keyPressed(int key){
}
void ofApp::keyReleased(int key){
}
void ofApp::mouseMoved(int x, int y ){
for (int i = 0; i < nCurveVertices; i++){
float diffx = x - curveVertices[i].x;
float diffy = y - curveVertices[i].y;
float dist = sqrt(diffx*diffx + diffy*diffy);
if (dist < curveVertices[i].radius){
curveVertices[i].bOver = true;
} else {
curveVertices[i].bOver = false;
}
}
}
void ofApp::mouseDragged(int x, int y, int button){
for (int i = 0; i < nCurveVertices; i++){
if (curveVertices[i].bBeingDragged == true){
curveVertices[i].x = x;
curveVertices[i].y = y;
}
}
}
void ofApp::mousePressed(int x, int y, int button){
for (int i = 0; i < nCurveVertices; i++){
float diffx = x - curveVertices[i].x;
float diffy = y - curveVertices[i].y;
float dist = sqrt(diffx*diffx + diffy*diffy);
if (dist < curveVertices[i].radius){
curveVertices[i].bBeingDragged = true;
} else {
curveVertices[i].bBeingDragged = false;
}
}
}
void ofApp::mouseReleased(int x, int y, int button){
for (int i = 0; i < nCurveVertices; i++){
curveVertices[i].bBeingDragged = false;
}
}
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