//-------------------------------------------------------------- void testApp::keyPressed(int key) { if(key == '1') mode = 1; if(key == '2') mode = 2; if(key == '3') mode = 3; // clear all the points if(key == 'c') { points.clear(); speeds.clear(); } // add crazy amount if(key == 'z') { for (int i=0; i<400000; i++) { addPoint(ofRandomWidth(), ofRandomHeight()); } } }
//-------------------------------------------------------------- void testApp::update(){ for (int i = 0; i < cars.size(); i++) { // APPLY A STEERING FORCE cars[i].seek(dest[i]); float area = 200; // REPULSION cars[i].addRepulsionForce(cars[i+1].pos, area, 0.1); // UPDATE PHYSICS cars[i].update(); if (cars[i].pos.distance(dest[i]) < 5) { dest[i] = ofPoint(ofRandomWidth(), ofRandomHeight()); } } }
//------------------------------------------------------------------ void demoParticle::reset(){ //the unique val allows us to set properties slightly differently for each particle uniqueVal = ofRandom(-10000, 10000); pos.x = ofRandomWidth(); pos.y = ofRandomHeight(); vel.x = ofRandom(-3.9, 3.9); vel.y = ofRandom(-3.9, 3.9); frc = ofPoint(0,0,0); scale = ofRandom(0.5, 1.0); if( mode == PARTICLE_MODE_NOISE ){ drag = ofRandom(0.97, 0.99); vel.y = fabs(vel.y) * 3.0; //make the particles all be going down }else{ drag = ofRandom(0.95, 0.998); } }
void Particle::setup(){ setPicture=int(ofRandom(4)); flySize=ofRandom(30,50); pos.x=ofRandomWidth(); pos.y=ofRandomHeight(); vel.x=ofRandom(0.0, 1.0); vel.y=ofRandom(0.0, 1.0); angleX=ofRandom(360); angleY=ofRandom(360); angleZ=ofRandom(360); for (int i=0; i<5; i++) { string result = ""; stringstream currentCombo; currentCombo << i; result = currentCombo.str(); butterflyList.push_back(ofImage()); butterflyList[i].loadImage(ofToDataPath(result + ".png")); } }
//-------------------------------------------------------------- void testApp::draw(){ ofBackgroundGradient(255, 0); ofNoFill(); for(int i=0; i<NUM_CIRCLES; i++){ ofCircle(pos[i].x, pos[i].y, circleradius[i]); ofCircle(pos[i].x, pos[i].y, circleradius[i]/2); ofCircle(pos[i].x, pos[i].y, circleradius[i]/4); ofCircle(pos[i].x, pos[i].y, circleradius[i]/6); ofCircle(pos[i].x, pos[i].y, circleradius[i]/8); ofCircle(pos[i].x, pos[i].y, circleradius[i]/16); ofCircle(pos[i].x, pos[i].y, circleradius[i]/32); ofCircle(pos[i].x, pos[i].y, circleradius[i]/64); circlex[i] = ofRandomWidth(); circley[i] = ofRandomHeight(); } }
//-------------------------------------------------------------- void testApp::setup() { ofBackground(0); ofSetVerticalSync(true); // billboard particles for (int i=0; i<NUM_BILLBOARDS; i++) { pos[i].x = ofRandomWidth(); pos[i].y = ofRandomHeight(); vel[i].x = ofRandomf(); vel[i].y = ofRandomf(); home[i] = pos[i]; pointSizes[i] = ofNextPow2(ofRandom(2, 40)); rotations[i] = ofRandom(0, 360); } // set the vertex data vbo.setVertexData(pos, NUM_BILLBOARDS, GL_DYNAMIC_DRAW); shader.load("Billboard"); ofDisableArbTex(); texture.loadImage("snow.png"); }
//-------------------------------------------------------------- void testApp::setup(){ ofBackground(0, 0, 0); ofSetLogLevel(OF_LOG_VERBOSE); ofSetVerticalSync(false); opencl.setupFromOpenGL(); // create vbo glGenBuffersARB(1, &vbo); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo); glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(float2) * NUM_PARTICLES, 0, GL_DYNAMIC_COPY_ARB); glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); // init host and CL buffers particles.initBuffer(NUM_PARTICLES); particlePos.initFromGLObject(vbo, NUM_PARTICLES); // init data for(int i=0; i<NUM_PARTICLES; i++) { Particle &p = particles[i]; p.vel.set(0, 0); p.mass = ofRandom(0.5, 1); particlePos[i].set(ofRandomWidth(), ofRandomHeight()); } particles.writeToDevice(); particlePos.writeToDevice(); opencl.loadProgramFromFile("MSAOpenCL/Particle.cl"); opencl.loadKernel("updateParticle"); opencl.kernel("updateParticle")->setArg(0, particles.getCLMem()); opencl.kernel("updateParticle")->setArg(1, particlePos.getCLMem()); opencl.kernel("updateParticle")->setArg(2, mousePos); opencl.kernel("updateParticle")->setArg(3, dimensions); glPointSize(1); }
//-------------------------------------------------------------- void testApp::setup(){ ofEnableAlphaBlending(); ofBackground(0); bg.loadImage("bg3.png"); //artwork tim reynolds bg.resize(ofGetWindowWidth(), ofGetWindowHeight()); ofSetVerticalSync(true); timer = ofGetElapsedTimef(); for (int i=0; i<30; i++) { Food bitesOfFood; bitesOfFood.setup(); bites.push_back(bitesOfFood); } for(int i = 0; i< 10; i++) { Prey prey; prey.setup(); preys.push_back(prey); } for(int i = 0; i< 3; i++) { Predator predator; predator.setup(); predators.push_back(predator); } myVectorField.setup(ofGetWindowWidth(), ofGetWindowHeight(), 20); for(int i = 0; i < 50000; i++){ Particle tmp; particleList.push_back( tmp ); particleList[i].setParams(ofRandomWidth(), ofRandomHeight(), ofRandom(-1,1), ofRandom(-1,1)); } }
//-------------------------------------------------------------- void ofApp::setup() { ofBackground(0); ofSetVerticalSync(true); // billboard particles for (int i=0; i<NUM_BILLBOARDS; i++) { pos[i].x = ofRandomWidth(); pos[i].y = ofRandomHeight(); vel[i].x = ofRandomf(); vel[i].y = ofRandomf(); home[i] = pos[i]; pointSizes[i] = ofRandom(2, 40); rotations[i] = ofRandom(0, 360); } // set the vertex data vbo.setVertexData(pos, NUM_BILLBOARDS, GL_DYNAMIC_DRAW); if(ofIsGLProgrammableRenderer()){ shader.load("shaderGL3/Billboard"); }else{ shader.load("shaderGL2/Billboard"); } ofDisableArbTex(); texture.load("snow.png"); // we are getting the location of the point size attribute // we then set the pointSizes to the vertex attritbute // we then bind and then enable shader.begin(); int pointAttLoc = shader.getAttributeLocation("pointSize"); vbo.setAttributeData(pointAttLoc, pointSizes, 1, NUM_BILLBOARDS, GL_DYNAMIC_DRAW); // rotate the snow based on the velocity int angleLoc = shader.getAttributeLocation("angle"); vbo.setAttributeData(angleLoc, rotations, 1, NUM_BILLBOARDS, GL_DYNAMIC_DRAW); shader.end(); }
//-------------------------------------------------------------- void CmbSceneGL2D::addDrop() { m_fbos[m_prevIdx].begin(); { ofDisableAlphaBlending(); ofPushMatrix(); { ofScale(1.0, -1.0, 1.0); ofTranslate(0.0, m_dimensions.y * -1.0, 0.0); ofPushStyle(); { ofSetColor(m_dropColor); ofNoFill(); ofDrawCircle(ofRandomWidth(), ofRandomHeight(), m_radius); } ofPopStyle(); } ofPopMatrix(); } m_fbos[m_prevIdx].end(); }
//-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ points.push_back(ofPoint(ofRandomWidth(), ofRandomHeight())); }
//-------------------------------------------------------------- void testApp::setup(){ ofSetFrameRate(60); ofSetBackgroundAuto(false);//false to allow redraw of shapes ofBackground(255, 255, 255); colorStart = 10.0; manualTarget = ofPoint(ofGetWidth()/2, ofGetHeight()/2); for (int i=0; i<NUM_ELEMENTS; i++) { points.push_back(ofPoint(ofRandomWidth(), ofRandomHeight())); angles.push_back(0); speeds.push_back(0); //R sizes.push_back( 0 );//intitialize circle sizes colors.push_back(colorStart); } //R displaceToTop = 250; wMiddle = ofGetWidth()/2; hMiddle = ofGetHeight()/2-displaceToTop; amount = 0.2; // Load the font string filename = "Verdana.ttf"; int fontSize = 50; bool bAntiAliased = true; bool bFullCharacterSet = true; bool makeContours = true; float simplifyAmt = 0.3; // uses ofPolyline::simplify font1.loadFont(filename, fontSize, bAntiAliased, bFullCharacterSet, makeContours, simplifyAmt); //R - SVG rX = ofRandomWidth(); rY = ofRandomHeight(); for(int i=0; i<NUM_FILES; i++) { string fileNum = ofToString(i); mySvgFiles.push_back(ofxSVG()); mySvgFiles.back().load("svg/form_"+fileNum+".svg"); mySvgPoints.push_back( ofPoint(wMiddle,hMiddle) ); mySvgRotation.push_back( 0 ); mySvgScale.push_back( 1.0 ); } //R POEM text = "The \nImaginary \nMan"; ofBuffer file = ofBufferFromFile("poem1.txt"); poemAsString = file; //R SAVE IMG snapCounter = 0; bSnapshot = false; memset(snapString, 0, 255); // clear the string by setting all chars to 0 }
void stars::init(){ pos.x = ofRandomWidth();//ofRandom(0, ofGetWidth()) pos.y = ofRandomHeight();//ofRandom(0, ofGetWidth()) }
void testApp::addParticle() { Particle p; p.pos = ofVec2f( ofRandomWidth(), ofRandomHeight() ); p.vel = ofVec2f( ofRandom(-5, 5), ofRandom( -5, 5) ); particleList.push_back( p ); }
void Particle::setup() { pos.x = ofRandomWidth(); pos.y = ofRandomHeight(); }
//-------------------------------------------------------------- void soundizeMeApp::setup(){ // Smooth edges ofEnableSmoothing(); // Fixed framerate ofSetFrameRate(30); m_audio.loadSound("1_opening.mp3"); m_audio.setLoop(true); m_audio.play(); // the fft needs to be smoothed out, so we create an array of floats // for that purpose: m_nBandsToGet = 1024; int * arr = new int[m_nBandsToGet*4]; for (int i = 0; i < m_nBandsToGet*4; i++){ arr[i] = i % m_nBandsToGet; } random_shuffle(&arr[m_nBandsToGet * 0 ], &arr[m_nBandsToGet * 1]); random_shuffle(&arr[m_nBandsToGet * 1 ], &arr[m_nBandsToGet * 2]); random_shuffle(&arr[m_nBandsToGet * 2 ], &arr[m_nBandsToGet * 3]); random_shuffle(&arr[m_nBandsToGet * 3 ], &arr[m_nBandsToGet * 4]); m_fftSmoothed = new float[m_nBandsToGet]; for (int i = 0; i < m_nBandsToGet; i++){ m_fftSmoothed[i] = 0; } /* 1 sichqare X [-2,2] 2 sichqare Y [-2,2] 3 radiusi [5,30] 4 rgb setHex */ for (int i = 0; i < m_nBandsToGet/8 ; i++) { float theta = ofRandom(0,360); ofVec2f location = ofVec2f(ofRandomWidth(),ofRandomHeight()); ofVec2f velocity = ofVec2f(sin(theta),cos(theta)); ofColor color = ofColor(ofRandom(255), ofRandom(255), ofRandom(255)); velocity *= ofRandom(0.5,2); std::vector<int> FFTids; FFTids.push_back(arr[m_nBandsToGet * 0 + i]); FFTids.push_back(arr[m_nBandsToGet * 1 + i]); FFTids.push_back(arr[m_nBandsToGet * 2 + i]); FFTids.push_back(arr[m_nBandsToGet * 3 + i]); // for (int i = 0; i < 4; i++) // FFTids.push_back(int(ofRandom(m_nBandsToGet))); m_balls.push_back(Ball(location,velocity,color,20,FFTids)); } // slider1.setup("slider1", 50, 0, 100); // slider2.setup("slider2", 50, 0, 100); // slider3.setup("slider3", 50, 0, 100); // slider4.setup("slider4", 50, 0, 100); // m_gui.setup("params", 10, 10); // m_gui.add(&slider1); // m_gui.add(&slider2); // m_gui.add(&slider3); // m_gui.add(&slider4); // ofSetBackgroundAuto(false); // ofBackground(0); }
//-------------------------------------------------------------- void testApp::windowResized(int w, int h){ for (int i=0; i<NUM_BILLBOARDS; i++) { home[i].x = ofRandomWidth(); home[i].y = ofRandomHeight(); } }
//-------------------------------------------------------------- void testApp::setup() { Tweenzor::init( ) ; ofSetLogLevel(OF_LOG_WARNING); bDrawOpenNI = false; //#ifndef USE_ONI_MOVIE openNIDevice.setup(); openNIDevice.addImageGenerator(); openNIDevice.addDepthGenerator(); openNIDevice.setRegister(true); openNIDevice.setMirror(false); openNIDevice.addUserGenerator(); openNIDevice.setMaxNumUsers(4); openNIDevice.start(); // set properties for all user masks and point clouds //openNIDevice.setUseMaskPixelsAllUsers(true); // if you just want pixels, use this set to true openNIDevice.setUseMaskTextureAllUsers(true); // this turns on mask pixels internally AND creates mask textures efficiently openNIDevice.setUsePointCloudsAllUsers(false); // openNIDevice.setPointCloudDrawSizeAllUsers(2); // size of each 'point' in the point cloud // openNIDevice.setPointCloudResolutionAllUsers(2); // resolution of the mesh created for the point cloud eg., this will use every second depth pixel // you can alternatively create a 'base' user class // ofxOpenNIUser user; // user.setUseMaskTexture(true); // user.setUsePointCloud(true); // user.setPointCloudDrawSize(2); // user.setPointCloudResolution(2); // openNIDevice.setBaseUserClass(user); //#endif /* openNIPlayer.setup(); openNIPlayer.addImageGenerator(); openNIPlayer.addDepthGenerator(); openNIPlayer.setRegister(true); openNIPlayer.setMirror(false); openNIPlayer.addUserGenerator(); openNIPlayer.setMaxNumUsers(2); openNIPlayer.start(); openNIPlayer.setUseMaskTextureAllUsers(true); // this turns on mask pixels internally AND creates mask textures efficiently openNIPlayer.setUsePointCloudsAllUsers(false);*/ // openNIPlayer.setPointCloudDrawSizeAllUsers(2); // size of each 'point' in the point cloud // openNIPlayer.setPointCloudResolutionAllUsers(2); // resolution of the mesh created for the point cloud eg., this will use every second depth pixel colorPool.push_back( ofColor( 242, 56 , 90 ) ) ; colorPool.push_back( ofColor( 245, 165 , 3 ) ) ; colorPool.push_back( ofColor( 233, 241 , 223 ) ) ; colorPool.push_back( ofColor( 74, 217 , 217 ) ) ; colorPool.push_back( ofColor( 54, 177 , 191 ) ) ; verdana.loadFont(ofToDataPath("verdana.ttf"), 24); roiArea = ofRectangle( ofRandomWidth() , ofRandomHeight() , ofRandomWidth() , ofRandomHeight() ) ; bUseRoi = false ; bFullscreen = false ; bCalibrateSpace = true ; loadRoiCalibration() ; init_ofxUI ( ) ; for ( int i = 0 ; i < 15 ; i++ ) { JointRoute jr ; jointRoutes.push_back( jr ) ; skeleton.push_back ( ofPoint() ) ; } jointRoutes[0].addIndex(1) ; jointRoutes[0].addIndex(9) ; jointRoutes[0].addIndex(12) ; jointRoutes[1].addIndex(3) ; jointRoutes[1].addIndex(6) ; jointRoutes[1].addIndex(2) ; jointRoutes[2].addIndex(-1) ; jointRoutes[3].addIndex(4) ; jointRoutes[3].addIndex(4) ; jointRoutes[4].addIndex(5) ; jointRoutes[4].addIndex(5) ; jointRoutes[5].addIndex(-1) ; jointRoutes[6].addIndex(7) ; jointRoutes[6].addIndex(7) ; jointRoutes[7].addIndex(8) ; jointRoutes[7].addIndex(8) ; jointRoutes[8].addIndex(-1) ; jointRoutes[9].addIndex(10) ; jointRoutes[10].addIndex(11) ; jointRoutes[11].addIndex(-1) ; jointRoutes[12].addIndex(13) ; jointRoutes[13].addIndex(14) ; jointRoutes[14].addIndex(-1) ; lastSpawn = 0 ; spawnDelay = 1.5f ; bDepthRegistration = false ; fbo.allocate( ofGetWidth() , ofGetHeight() , GL_RGBA ) ; fbo.begin() ; ofClear( 1 , 1 , 1, 0 ) ; fbo.end() ; bSkeletonActive = false ; }
//-------------------------------------------------------------- void ofApp::setup() { svg.load("shape.svg"); ofSetFrameRate(60); ofBackgroundHex(0x00000); ofSetLogLevel(OF_LOG_NOTICE); box2d.init(); box2d.setGravity(0, gravity); box2d.setFPS(30.0); box2d.registerGrabbing(); int extend = 100; box2d.createBounds(0,-extend*0.5,ofGetWidth(),ofGetHeight()+extend*5); particles.setParticleFlag(b2_tensileParticle); particles.loadImage("particle32.png"); // particles.setup(box2d.getWorld()); particles.setup(box2d.getWorld(), 20000, 60.0, 6.0, 42.0, ofColor::white); for (int i = 0; i < 8000; i++) { ofVec2f position = ofVec2f(ofRandomWidth(), ofRandomHeight()*0.2); ofVec2f velocity = ofVec2f(0, 0); particles.createParticle(position, velocity); } drawParticle = false; int density = 10; //start shape for (int i = 0; i < svg.getNumPath(); i++){ ofPtr <ofxBox2dEdge> edge = ofPtr<ofxBox2dEdge>(new ofxBox2dEdge); ofPath p = svg.getPathAt(i); // svg defaults to non zero winding which doesn't look so good as contours p.setPolyWindingMode(OF_POLY_WINDING_ODD); vector<ofPolyline> lines = p.getOutline(); for(int j=0;j<(int)lines.size();j++){ vector<ofVec3f>points = lines[j].getVertices(); for(int k = 0 ; k < points.size() ; k++ ) { edge.get()->addVertex(points[k]); } } edge.get()->setFriction(0); edge.get()->setBounce(0); edge.get()->setDamping(0); edge.get()->create(box2d.getWorld()); edges.push_back(edge); } metaball2D.setup(ofGetWidth(), ofGetHeight()); // for(int j = 0 ; j < 500 ; j++){ // circles.push_back(ofPtr<ofxBox2dCircle>(new ofxBox2dCircle)); // circles.back().get()->setPhysics(0, 0.0, 0); // circles.back().get()->setup(box2d.getWorld(), ofRandomWidth(),ofRandomHeight()*0.2 , 10); // // } }