I did manage to get my object and instance to work but I had to create the instance in ofAPP.cpp in the draw function. This code below works and I create a particle with xNoise and yNoise instances
void ofApp::draw(){
//phase = ofGetFrameNum();
NoiseLoop xNoise(1,0,ofGetWidth());
NoiseLoop yNoise(1,0,ofGetHeight());
cout << xNoise.diameter << " " << xNoise.cx << " " << yNoise.cy << " " << xNoise.value(a)<< " " << yNoise.value(a) <<"\n";
// float a = phase;
float x = xNoise.value(a);
float y = yNoise.value(a);
cout<<a<<endl;
ofDrawCircle(x, y, 100);
a+=0.01;
}
//.cpp
NoiseLoop::NoiseLoop (float diameter, float min, float max) {
this->diameter = diameter;
this->min = min;
this->max = max;
cx = ofRandom(1000);
cy = ofRandom(1000);
}
float NoiseLoop::value(float a){
float xoff = ofMap(cos(a), -1, 1, 0, diameter);
float yoff = ofMap(sin(a), -1, 1, 0, diameter);
float r = ofNoise(xoff, yoff);
return ofMap(r, 0, 1, min, max);
}
Following on the issue of the instance created in the draw function is that when I add float cx and float cy are being constantly updated.
//ofAPP.cpp
void ofApp::draw(){
//phase = ofGetFrameNum();
NoiseLoop xNoise(1,0,ofGetWidth());
NoiseLoop yNoise(1,0,ofGetHeight());
cout << xNoise.diameter << " " << xNoise.cx << " " << yNoise.cy << " " << xNoise.value(a)<< " " << yNoise.value(a) <<"\n";
float x = xNoise.value(a);
float y = yNoise.value(a);
cout<<a<<endl;
ofDrawCircle(x, y, 100);
a+=0.01;
//.cpp
float NoiseLoop::value(float a){
float xoff = ofMap(cos(a), -1, 1, cx, cx+ diameter);
float yoff = ofMap(sin(a), -1, 1, cy, cy+ diameter);
float r = ofNoise(xoff, yoff);
return ofMap(r, 0, 1, min, max);
}
In processing the instances xNoise and yNoise are global and the parameters(incu cx/cy) would be declared once by calling the class in setup.
If I create the instances in the .h I get an error “Expected ')” '“Expected parameter declarator”
#pragma once
#include "ofMain.h"
#include "NoiseLoop.h"
#include "Ball.h"
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);
void render(float percent);
Boolean randomValue;
float noiseMax;
float phase;
float a;
NoiseLoop xNoise(1,0,600);
NoiseLoop yNoise(1,0,600);
and for reference here is the object.cpp
NoiseLoop::NoiseLoop (float diameter, float min, float max) {
this->diameter = diameter;
this->min = min;
this->max = max;
cx = ofRandom(1000);
cy = ofRandom(1000);
}
float NoiseLoop::value(float a){
float xoff = ofMap(cos(a), -1, 1, cx, cx+ diameter);
float yoff = ofMap(sin(a), -1, 1, cy, cy+ diameter);
float r = ofNoise(xoff, yoff);
return ofMap(r, 0, 1, min, max);
}
I think the reason my particle is so erratic is due to the cx/cy call every frame instead of once in set up.
cx = ofRandom(1000);
cy = ofRandom(1000);
So to conclude XD
I want to call my instances in setup run the constructor Noiseloop but in the draw function pass a into float NoiseLoop::value(float a)
into the draw loop.
float x = xNoise.value(a);
float y = yNoise.value(a);
cout<<a<<endl;
ofDrawCircle(x, y, 100);
a+=0.01;
Thanks again