Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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

This comment has been minimized.

Copy link

@microcosm microcosm commented Jul 23, 2014

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