Hi, I’m trying to make many pendulums which have the same fulcrum.
I’ve made the project with a pendulum class and called it in ofApp.h.
But only one pendulum has appeared.
Here the code, any help is really appreciated.
thanks in advance
#pragma once
#include "ofMain.h"
#include "pendulum.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 windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
static const int PEN_NUM = 10;
pendulum Pendulum[PEN_NUM];
};
and here’s the ofApp.cpp
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
for (int i = 0; i < PEN_NUM; i++){
//Set screen frame rate
ofSetFrameRate( 60 );
//Set initial values
ofVec2f pos0;
pos0= ofPoint( 512, 300 );
ofVec2f pos;
pos= ofPoint( ofRandom(600), ofRandom(200) );
ofVec2f velocity;
velocity= ofPoint( ofRandom(100), 0 );
Pendulum[i].setup(pos0, pos, velocity);
}
}
//--------------------------------------------------------------
void ofApp::update(){
for (int i = 0; i < PEN_NUM; i++){
Pendulum[i].update();
}
}
//--------------------------------------------------------------
void ofApp::draw(){
for (int i = 0; i < PEN_NUM; i++){
Pendulum[i].draw();
}
}
Hello!
If it’s ok with you, can you show us pendulum class?
And if I were you, I’d write pendulums’ basic information in constructor of pendulum class.
Hello.
I am surprised now! And I watched your code.
Please try to conceal ofBackground(255, 255, 255); of pendulum class’s draw function.
Because of calling ofBackground(255) in for statement of ofMain file’s draw function, this program draw fully white color every pendulum.