Advertisement
xeromino

noise

Jun 14th, 2016
179
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "ofApp.h"
  2.  
  3. //--------------------------------------------------------------
  4. void ofApp::setup(){
  5.     ofBackground(238);
  6.     ofSetBackgroundAuto(false);
  7.     fieldIntensity = 500; //ofRandom(2,10);
  8.     noiseScale = 1000; //ofRandom(200,400);
  9.     agentCount = 5000;
  10.     stepSize = 5;
  11.     edge = 50;
  12.     for (int i=0; i<agentCount; i++) {
  13.         Particle partTemp;
  14.         partTemp.pos = ofPoint(ofRandom(ofGetWidth()+edge),ofRandom(ofGetHeight()+edge));
  15.         partTemp.prevPos = ofPoint(0,0);
  16.         locations.push_back(partTemp);
  17.     }
  18. }
  19.  
  20. //--------------------------------------------------------------
  21. void ofApp::update(){
  22.     for (auto &loc: locations) {
  23.         float angle = ofNoise(loc.pos.x/noiseScale, loc.pos.y/noiseScale)*fieldIntensity;
  24.         loc.prevPos.x = loc.pos.x;
  25.         loc.prevPos.y = loc.pos.y;
  26.         loc.pos.x += cos(angle)*stepSize;
  27.         loc.pos.y += sin(angle)*stepSize;
  28.         if (loc.pos.x < -edge || loc.pos.x > ofGetWidth()+edge || loc.pos.y < -edge || loc.pos.y > ofGetHeight()+edge) {
  29.             loc.pos = ofPoint(ofRandom(ofGetWidth()),ofRandom(ofGetHeight()));
  30.             loc.prevPos = loc.pos;
  31.         }
  32.     }
  33. }
  34.  
  35. //--------------------------------------------------------------
  36. void ofApp::draw(){
  37.     for (auto loc: locations) {
  38.         ofSetColor(34,25);
  39.         ofDrawLine(loc.prevPos.x, loc.prevPos.y, loc.pos.x, loc.pos.y);
  40.     }
  41. }
  42.  
  43. //--------------------------------------------------------------
  44. void ofApp::keyPressed(int key){
  45.     if (key == 'n') {
  46.         locations.clear();
  47.         setup();
  48.     }
  49.     if (key == 'c') {
  50.         setup();
  51.     }
  52.     if(key == 's'){
  53.         img.grabScreen(0, 0 , ofGetWidth(), ofGetHeight());
  54.         stringstream fileName;
  55.         fileName << "screenshot" << ofRandom(1000) << ".png";
  56.         img.save(fileName.str());
  57.     }
  58. }
  59.  
  60. //--------------------------------------------------------------
  61. void ofApp::keyReleased(int key){
  62. }
  63.  
  64. //--------------------------------------------------------------
  65. void ofApp::mouseMoved(int x, int y ){
  66.  
  67. }
  68.  
  69. //--------------------------------------------------------------
  70. void ofApp::mouseDragged(int x, int y, int button){
  71.  
  72. }
  73.  
  74. //--------------------------------------------------------------
  75. void ofApp::mousePressed(int x, int y, int button){
  76.  
  77. }
  78.  
  79. //--------------------------------------------------------------
  80. void ofApp::mouseReleased(int x, int y, int button){
  81.  
  82. }
  83.  
  84. //--------------------------------------------------------------
  85. void ofApp::mouseEntered(int x, int y){
  86.  
  87. }
  88.  
  89. //--------------------------------------------------------------
  90. void ofApp::mouseExited(int x, int y){
  91.  
  92. }
  93.  
  94. //--------------------------------------------------------------
  95. void ofApp::windowResized(int w, int h){
  96.  
  97. }
  98.  
  99. //--------------------------------------------------------------
  100. void ofApp::gotMessage(ofMessage msg){
  101.  
  102. }
  103.  
  104. //--------------------------------------------------------------
  105. void ofApp::dragEvent(ofDragInfo dragInfo){
  106.  
  107. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement