Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ofApp.h"
- //--------------------------------------------------------------
- void ofApp::setup(){
- ofBackground(238);
- ofSetBackgroundAuto(false);
- fieldIntensity = 500; //ofRandom(2,10);
- noiseScale = 1000; //ofRandom(200,400);
- agentCount = 5000;
- stepSize = 5;
- edge = 50;
- for (int i=0; i<agentCount; i++) {
- Particle partTemp;
- partTemp.pos = ofPoint(ofRandom(ofGetWidth()+edge),ofRandom(ofGetHeight()+edge));
- partTemp.prevPos = ofPoint(0,0);
- locations.push_back(partTemp);
- }
- }
- //--------------------------------------------------------------
- void ofApp::update(){
- for (auto &loc: locations) {
- float angle = ofNoise(loc.pos.x/noiseScale, loc.pos.y/noiseScale)*fieldIntensity;
- loc.prevPos.x = loc.pos.x;
- loc.prevPos.y = loc.pos.y;
- loc.pos.x += cos(angle)*stepSize;
- loc.pos.y += sin(angle)*stepSize;
- if (loc.pos.x < -edge || loc.pos.x > ofGetWidth()+edge || loc.pos.y < -edge || loc.pos.y > ofGetHeight()+edge) {
- loc.pos = ofPoint(ofRandom(ofGetWidth()),ofRandom(ofGetHeight()));
- loc.prevPos = loc.pos;
- }
- }
- }
- //--------------------------------------------------------------
- void ofApp::draw(){
- for (auto loc: locations) {
- ofSetColor(34,25);
- ofDrawLine(loc.prevPos.x, loc.prevPos.y, loc.pos.x, loc.pos.y);
- }
- }
- //--------------------------------------------------------------
- void ofApp::keyPressed(int key){
- if (key == 'n') {
- locations.clear();
- setup();
- }
- if (key == 'c') {
- setup();
- }
- if(key == 's'){
- img.grabScreen(0, 0 , ofGetWidth(), ofGetHeight());
- stringstream fileName;
- fileName << "screenshot" << ofRandom(1000) << ".png";
- img.save(fileName.str());
- }
- }
- //--------------------------------------------------------------
- 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){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement