Skip to content

Instantly share code, notes, and snippets.

@darrenmothersele
Created December 9, 2013 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenmothersele/7875908 to your computer and use it in GitHub Desktop.
Save darrenmothersele/7875908 to your computer and use it in GitHub Desktop.
#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);
}
#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);
}
@microcosm
Copy link

What does this line do?
while (s >= 1 || s == 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment