Sure, here is a sample, the boxes are drawn from the middle, there is also a circle, what I would like to do, whenever the circle touches a rectangle / square they should perform a certain function (example go red and fade out).
I am stuck at the part how and what i should add to the code to detect that interaction. and how i would get the correct ID from the rectangle / square so i can call the function on it.
The code has some ofxUI in it so i could change the size of the grid and change the radius of the circle.
#include "ofApp.h";
int numX;
int numY;
int xSize;
int ySize;
int circleDiameter;
int circleStroke;
//--------------------------------------------------------------
void ofApp::setup(){
gui = new ofxUICanvas(); //Creates a canvas at (0,0) using the default width
gui->addIntSlider("NUMBER BOXES X", 1, ofGetWidth() / 20, &numX);
gui->addIntSlider("NUMBER BOXES Y", 1, ofGetWidth() / 20, &numY);
gui->addIntSlider("Circle Diameter", 1, ofGetWidth() / 1.7, &circleDiameter);
gui->addIntSlider("Circle Stroke", 1, 100, &circleStroke);
gui->addToggle("FULLSCREEN", false);
gui->autoSizeToFitWidgets();
ofAddListener(gui->newGUIEvent, this, &ofApp::guiEvent);
gui->loadSettings("settings.xml");
}
//--------------------------------------------------------------
void ofApp::update(){
ofBackground(0, 0, 0);
xSize = (ofGetWidth() / numX) * 1;
ySize = (ofGetHeight() / numY) * 1;
}
//--------------------------------------------------------------
void ofApp::draw(){
ofPushMatrix();
ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2, 0);
ofSetCircleResolution(50);
ofCircle(0, 0, circleDiameter);
for (int i = 0; i < numX; i++) {
for (int j = 0; j < numY; j++) {
ofNoFill();
ofRect(xSize * i, ySize * j, xSize * 1, ySize * 1);
ofRect(-xSize * i, ySize * j, -xSize * 1, ySize * 1);
ofRect(xSize * i, -ySize * j, xSize * 1, -ySize * 1);
ofRect(-xSize * i, -ySize * j, -xSize * 1, -ySize * 1);
}
}
ofPopMatrix();
}
//--------------------------------------------------------------
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::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}
void ofApp::exit()
{
gui->saveSettings("settings.xml");
delete gui;
}
void ofApp::guiEvent(ofxUIEventArgs &e)
{
if (e.getName() == "FULLSCREEN")
{
ofxUIToggle *toggle = e.getToggle();
ofSetFullscreen(toggle->getValue());
}
}