3. oF versus Processing

Just as an example, below you will find a sample Processing sketch and its openFrameworks equivalent.

Processing

//--------------------------------------------------------------

float bAlpha, cAlpha, radius1, radius2, counter; color cColor = 255;void setup() {   size(1024, 768);   frameRate(30);}void draw() {// opacity of background reduces as mouse moving down    bAlpha = map(mouseY, 0, height, 20, 120);   background(bAlpha);// growing center circle, whose color is randomly assigned as key pressed   counter = counter + 0.033f;   noStroke();   fill(cColor, 80);   radius1 = 400*sin(counter);   ellipse(width/2, height/2, radius1, radius1);/* surround circles, whose color is consistent with the center one    and opacity reduces as mouse moving to the right */   cAlpha = map(mouseX, 0, width, 0, 100);   noFill();   stroke(cColor, cAlpha);   for(int i = 0; i < 5; i++){     radius2 = random(400, height);     ellipse(width/2, height/2, radius2, radius2);   }   }void keyPressed() {   cColor = color(random(255), random(255), random(255));}

openFrameworks

ofApp.cpp

//--------------------------------------------------------------

#include "ofApp.h"//--------------------------------------------------------------void ofApp::setup(){          ofSetCircleResolution(100);     ofSetFrameRate(30);     counter = 0;}//--------------------------------------------------------------void ofApp::update(){      //    counter = counter + 0.033f;}//--------------------------------------------------------------void ofApp::draw(){// opacity of background reduces as mouse moving down     float bAlpha = ofMap(mouseY, 0, ofGetHeight(), 20, 120);     ofBackground((int) bAlpha);      counter = counter + 0.033f;// growing center circle, whose color is randomly assigned as key pressed     ofSetColor(cColor, 80);     ofFill();     float radius1 = 400 * sin(counter)/2;     ofDrawCircle(ofGetWidth()/2, ofGetHeight()/2, radius1);      /* surround circles, whose color is consistent with the center one   and opacity reduces as mouse moving to the right */     float cAlpha = ofMap(mouseX, 0, ofGetWidth(), 0, 100);     ofNoFill();     ofSetColor(cColor, cAlpha);     for(int i = 0; i < 5; i++){         float radius2 = (int)ofRandom(400, ofGetHeight())/2;         ofDrawCircle(ofGetWidth()/2, ofGetHeight()/2, radius2);     }     }

//--------------------------------------------------------------void ofApp::keyPressed(int key){          cColor = ofColor((int)ofRandom(0,255),(int)ofRandom(0,255),(int)ofRandom(0,255));}

//--------------------------------------------------------------

ofApp.h

//--------------------------------------------------------------

#pragma once#include "ofMain.h"class ofApp : public ofBaseApp{ public: void setup(); void update(); void draw();  void keyPressed(int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void mouseEntered(int x, int y); void mouseExited(int x, int y); void windowResized(int w, int h); void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg);              float counter;         ofColor cColor; };