Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@satoruhiga
Created November 14, 2013 12:23
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 satoruhiga/7465939 to your computer and use it in GitHub Desktop.
Save satoruhiga/7465939 to your computer and use it in GitHub Desktop.
#pragma once
#include "ofMain.h"
class NoiseCircle
{
public:
float noise_amt;
float noise_speed;
float noise_scale;
void setup(float size, float noise_amt, float noise_scale, float noise_speed, int num_control_point)
{
this->noise_amt = noise_amt;
this->noise_speed = noise_speed;
this->noise_scale = noise_scale;
seed = ofRandom(100000);
control_points.clear();
control_points_orig.clear();
for (int i = 0; i < num_control_point; i++)
{
float d = ofMap(i, 0, num_control_point, 0, 1);
float xx = sin(d * TWO_PI) * size;
float yy = cos(d * TWO_PI) * size;
control_points_orig.push_back(ofVec3f(xx, yy));
}
control_points = control_points_orig;
}
void update()
{
float t = ofGetElapsedTimef() * noise_speed;
for (int i = 0; i < control_points_orig.size(); i++)
{
const ofVec3f& v0 = control_points_orig[i];
ofVec3f& v1 = control_points[i];
float idx = (i + 1) * noise_scale;
v1.x = v0.x + ofSignedNoise(idx, 0, 0, t + seed) * noise_amt;
v1.y = v0.y + ofSignedNoise(0, idx, 0, t + seed) * noise_amt;
v1.z = v0.z;
}
path.clear();
for (int i = 0; i < control_points.size(); i++)
{
ofVec3f& v0 = control_points[i];
ofCurveVertex(v0);
path.curveTo(v0);
}
path.curveTo(control_points[0]);
path.curveTo(control_points[1]);
path.curveTo(control_points[2]);
path.close();
}
void draw()
{
path.draw();
}
protected:
vector<ofVec3f> control_points;
vector<ofVec3f> control_points_orig;
ofPath path;
float seed;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment