Skip to content

Instantly share code, notes, and snippets.

@gatana
Created March 27, 2016 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gatana/339a15b324cb59849c29 to your computer and use it in GitHub Desktop.
Save gatana/339a15b324cb59849c29 to your computer and use it in GitHub Desktop.
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofSetBackgroundColor(208,120,13,90);
ofSetFrameRate(60);
ofSetCircleResolution(120);
counter = 0;
// me.circumference =8;
//
// me.xpos= ofDegToRad(5);
// me.ypos= ofDegToRad(80);
}
//--------------------------------------------------------------
void ofApp::update(){
ofTranslate(ofGetHeight()/3, ofGetWidth()/3);
// me.form1(me.circumference, ofDegToRad(270),0 ,0);
//counter along with sin will make the radius of the ball keep changing
counter = counter + 0.033f;
//recursive function begins (drawCircle calls upon itself to draw circles outside the last circle's radius)
}
void drawCircleRecursive(ofVec2f center, float radius)
{
//why does ofCircle always seem to be deprecated?
ofCircle(center.x, center.y, radius);
//radius size of initial circle
if(radius > 8)
{
//making this number bigger compacts the circles to be drawn closer
radius *= 0.95f;
drawCircleRecursive(center, radius);
}
}
//--------------------------------------------------------------
void ofApp::draw(){
//here i try to trigger the circles to move
float radius = 50 + 100 * sin(counter);
//ofSetColor(255, 255, 255);
//color changes over time
ofSetColor(abs(sin(ofGetElapsedTimef()/2))*255, abs(cos(ofGetElapsedTimef()/2))*255, abs(cos(ofGetElapsedTimef()/4))*255, 255);
ofNoFill();
//casting ints as floats
drawCircleRecursive(ofVec2f{static_cast<float>(ofGetWidth()/2), static_cast<float>(ofGetHeight()/2)}, ofGetHeight());
int w = gmg.getWidth();
int h = gmg.getHeight();
float diameter = 10;
ofSetColor(2, 210, 200);
for(int y = 1; y < h; y++) {
for(int x = 2; x < w; x++) {
ofColor cur = gmg.getColor(x, y);
float size = 1 - (cur.getBrightness() / 1005);
ofDrawCircle(x * diameter, 50 + y * diameter, 1 + size * diameter / 2);
}
}
}
//--------------------------------------------------------------
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){
}
#pragma once
#include "ofMain.h"
#include "Generative.hpp"
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);
ofImage gmg;
float counter;
// Generative me;
};
#include "ofMain.h"
#include "ofApp.h"
//code snip in ofApp.cpp from
//https://github.com/GuidoSchmidt/ofNaturOfCode/tree/master/8.01-RecursiveCircles/src
//========================================================================
int main( ){
ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new ofApp());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment