Created
December 9, 2013 17:02
-
-
Save darrenmothersele/7875908 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "testApp.h" | |
#include <ofGraphics.h> | |
void testApp::setup(){ | |
ofSetFrameRate(60); | |
ofSetBackgroundAuto(false); | |
ofEnableAlphaBlending(); | |
ofEnableSmoothing(); | |
ofBackground(255); | |
ofSetColor(0); | |
} | |
void testApp::update(){ | |
} | |
void testApp::draw(){ | |
float num = ofRandomf(); | |
float sd = 60; | |
float mean = ofGetWidth() / 2; | |
float x = (sd * num) + mean; | |
ofSetColor(255, 10); | |
ofRect(0, 0, ofGetWidth(), ofGetHeight()); | |
ofSetColor(0); | |
ofEllipse(x, ofGetHeight() / 2, 16, 16); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "testApp.h" | |
#include <ofGraphics.h> | |
bool haveNextNextGaussian = false; | |
float nextNextGaussian; | |
float ofxGaussian() { | |
if (haveNextNextGaussian){ | |
haveNextNextGaussian = false; | |
return nextNextGaussian; | |
} | |
else { | |
float v1, v2, s; | |
do { | |
v1 = 2 * ofRandomf() - 1; | |
v2 = 2 * ofRandomf() - 1; | |
s = v1 * v1 + v2 * v2; | |
} | |
while (s >= 1 || s == 0); | |
float multiplier = sqrt(-2 * log(s)/s); | |
nextNextGaussian = v2 * multiplier; | |
haveNextNextGaussian = true; | |
return v1 * multiplier; | |
} | |
} | |
void testApp::setup(){ | |
ofSetFrameRate(60); | |
ofSetBackgroundAuto(false); | |
ofEnableAlphaBlending(); | |
ofEnableSmoothing(); | |
ofBackground(255); | |
ofSetColor(0); | |
} | |
void testApp::update(){ | |
} | |
void testApp::draw(){ | |
float num = ofxGaussian(); | |
float sd = 60; | |
float mean = ofGetWidth() / 2; | |
float x = (sd * num) + mean; | |
ofSetColor(255, 10); | |
ofRect(0, 0, ofGetWidth(), ofGetHeight()); | |
ofSetColor(0); | |
ofEllipse(x, ofGetHeight() / 2, 16, 16); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What does this line do?
while (s >= 1 || s == 0);