Home

OpenFrameworks looking good

Saturday, September 04th, 2010 | Author:

OpenFrameworks is a C++ toolkit designed for creative coding. The Code::Blocks IDE works in a familiar way and the two combine well.

Did a quick port of an old Yugo Flash4 example to AS3 and then to OpenFrameworks C++ to try it out. Very impressed with the toolkit and IDE - if you know some AS3 and some programming you will certainly have a head start. Definitely going to experiment some more with it.

The swf movie is here and the port is below:

C++:
  1. #include "testApp.h"
  2.  
  3. //--------------------------------------------------------------
  4. void testApp::setup(){
  5.  
  6. ofSetFrameRate(50);
  7.     i =0;
  8.     a = 5;
  9.     b = 1.66;
  10.     k = 20;
  11.  
  12.     for(i=0; i<NBALLS; i++) {
  13.         ball = &ballArray[i];
  14.         ball->x = 200+(i*k);
  15.         ball->y = 400;
  16.     }
  17.  
  18.     for(i=0; i<NBALLS; i++) {
  19.         ball = &ballArray[i];
  20.         ball->x_value = ball->x;
  21.         ball->y_value = ball->y;
  22.         ball->vx = 0;
  23.         ball->vy = 0;
  24.     }
  25.  
  26. }
  27.  
  28. //--------------------------------------------------------------
  29. void testApp::update(){
  30.  
  31.     for(i=1; i<NBALLS; i++) {
  32.         ball = &ballArray[i];
  33.         prevBall = &ballArray[(i-1)];
  34.         ball->vx  = (ball->vx  + ( prevBall->x_value + k - ball->x_value) /a) /b;
  35.         ball->vy  = (ball->vy  + ( prevBall->y_value - ball->y_value) /a) /b;
  36.         ball->x_value += ball->vx;
  37.         ball->y_value += ball->vy;
  38.     }
  39.  
  40.     ballArray[0].x_value = ballArray[0].x = mouseX;
  41.     ballArray[0].y_value =  ballArray[0].y = mouseY;
  42.  
  43.     for(i=0; i<NBALLS; i++) {
  44.         ball = &ballArray[i];
  45.         ball->x = ball->x_value;
  46.         ball->y = ball->y_value;
  47.     }
  48.  
  49. }
  50.  
  51. //--------------------------------------------------------------
  52. void testApp::draw(){
  53.  
  54.     for(int i=0; i<NBALLS; i++) {
  55.         ball = &ballArray[i];
  56.         ball->draw();
  57.     }
  58.  
  59. }

Tags »

 | Comments Feed: RSS 2.0
Category: Code Examples, Flash, OpenFrameworks

Comments and pings are currently closed.