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(){
}
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