Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save phoenixperry/a633e13cb784860f55b9fd43641eff4e to your computer and use it in GitHub Desktop.
Save phoenixperry/a633e13cb784860f55b9fd43641eff4e to your computer and use it in GitHub Desktop.
#include "ofApp.h"
ofPoint center_p;
ofPoint p;
ofPolyline hexLine;
//ofMesh hexMesh;
vector<ofPoint> points;
ofColor hexColor = *new ofColor(0,200,0);
//--------------------------------------------------------------
void ofApp::setup(){
ofBackground(0);
center_p.x = 200;
center_p.y = 200;
ofPolyline hexline = *new ofPolyline();
for (int i = 0; i < 6; i++)
{
p= hexCorner(center_p, 50, i);
points.push_back(p);
// cout<<points.size() <<endl;
}
//hexMesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
}
ofPoint ofApp::hexCorner(ofPoint center, int size, int i){
float startPointInDegrees =30;
float angle_deg = 60*i+startPointInDegrees;
float angle_rad = PI/180 * angle_deg;
float x = center.x + size * cos(angle_rad);
float y = center.y + size * sin(angle_rad);
ofPoint location = *new ofPoint(x,y);
return location;
}
void ofApp::drawHexagon (vector<ofPoint> *points){
for(int i=0; i<5; i++)
{
ofPoint p = points->at(i);
ofPoint p1 = points->at(i+1);
ofSetLineWidth(4.0); // Line widths apply to polylines
ofSetColor(hexColor);
hexLine.addVertex(p);
hexLine.addVertex(p1);
ofFill();
// cout << p.x << "+" << p.y << endl;
if(i==4)hexLine.addVertex(points->at(5));
}
hexLine.close();
hexLine.draw();
}
void ofApp::drawHexMesh(vector<ofPoint> *points, ofMesh* mesh){
// for (int i=0; i<6; i++) {
// mesh->addVertex(points->at(i));
// }
// ofSetColor(hexColor);
// ofFill();
// mesh->draw();
}
//--------------------------------------------------------------
void ofApp::update(){
if(hexLine.inside(mouseX, mouseY))
{
hexColor.r = 100;
hexColor.b = 100;
hexColor.g = 0;
cout<< "inside " << endl;
}else
{
hexColor.r = 0;
hexColor.b = 100;
hexColor.g = 100;
cout<< "outside " << endl;
}
cout << mouseX << " mouse x " << endl;
cout << mouseY << " mouse y " <<endl;
}
//--------------------------------------------------------------
void ofApp::draw(){
drawHexagon(&points);
//drawHexMesh(&points, &hexMesh);
}
//--------------------------------------------------------------
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){
}
//--------------------------------------------------------------
int num = 0;
void ofApp::mousePressed(int x, int y, int button){
//this was me just using the radius check, same as a circle
float num = ofDist(200, 200, x, y);
if(num < 50){
// cout << "over hex"<< num << endl;
}
// if(hexLine.inside(x,y)) cout<< "mouse in ";
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
if(hexLine.inside(x,y)) cout<< "mouse in " << num << endl;
num++;
}
//--------------------------------------------------------------
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){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment