Skip to content

Instantly share code, notes, and snippets.

@darrenmothersele
Created December 9, 2013 17:03
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/7875928 to your computer and use it in GitHub Desktop.
Save darrenmothersele/7875928 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(){
}
float monteCarlo() {
while (true) {
float r1 = ofRandom(1);
float probability = r1;
float r2 = ofRandom(1);
if (r2 < probability) {
return r1;
}
}
}
void testApp::draw(){
float num = monteCarlo();
float sd = 120;
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