@Ha99 wrote:
Hello, I am new to OpenFrameworks coming from Processing. I keep receiving Thread 1: EXC_BAD_ACESS (code=1, address= 0x0).
The program animates an attractor of mouse position.This is my program
pragma once
include "ofMain.h"
include
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); int num; vector <int> vx; vector <int> vy; vector <int> x; vector <int> y; vector <int> ax; vector <int> ay; int magnetism; int radius; float size; int decerleration; int speed; int xPos; int yPos; int distance; int touchX; int touchY; int r; int g; int b;
};
include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){ofBackground(0); num = 1000; magnetism = 10.0; radius = 1; decerleration = 0.95; ofNoFill(); ofEnableBlendMode(OF_BLENDMODE_ADD); //x.resize(num); for(int i = 0; i< num; i++){ x[i]= ofRandom(ofGetWidth()); y[i] = ofRandom(ofGetHeight()); vx[i] = 0; vy[i] = 0; ax[i] = 0; ay[i] = 0;
// x.push_back(x);
// x[i].set(x);
}}
//--------------------------------------------------------------
void ofApp::update(){}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(0, 0, 0);
ofDrawRectangle(0, 0, ofGetHeight(), ofGetWidth());for(int i= 0; i< num; i++){ distance = ofDist(touchX, touchY, x[i], y[i]); if(distance > 3){ ax[i] = magnetism * (touchX - x[i]) / (distance * distance); ay[i] = magnetism * (touchY - y[i]) / (distance * distance); } vx[i] += ax[i]; vy[i] += ay[i]; vx[i] = vx[i] *decerleration; vy[i] = vy[i] *decerleration; x[i] += vx[i]; y[i] += vy[i]; speed = ofDist(0, 0, vx[i], vy[i]); r = ofMap(speed, 0, 5, 0, 255); g = ofMap(speed, 0, 5, 64, 255); b = ofMap(speed, 0, 5, 128, 255); ofSetColor(r, g, b, 32); ofDrawEllipse(x[i], y[i], radius, radius); }
}
Posts: 10
Participants: 2