void testApp::draw() { ofBackground(0); ofSetColor(255); ofCircle(curPoint * ofxVec2f(ofGetWidth(), ofGetHeight()), 32); ofCircle(ofxVec2f(curPoint.x, .9) * ofxVec2f(ofGetWidth(), ofGetHeight()), 32); }
//-------------------------------------------------------------- void testApp::mouseReleased(){ //when we release - we set recording to be false and we set our playhead to 0.0 again recording = false; playPos = 0.0; storeTime = ofGetElapsedTimef(); //lets smooth those points!! //simple low pass smooth //go through the points list and make each point 70% of the previous point and 30% of itself //you can play with the 0.7 and 0.3 ratio bellow - as long as the total adds up to 1.0 //NOTE: that we start at 1 as point 0 has no previous point :( speedList.push_back(0); leftNormals.push_back( 0 ); rightNormals.push_back(0 ); for(unsigned int i = 1; i < ptsList.size(); i++){ ptsList[i] = 0.3 * ptsList[i] + 0.7 * ptsList[i-1]; ofxVec2f distVec = ptsList[i] - ptsList[i-1]; float speed = distVec.length(); distVec.normalize(); speed = 0.2*speed + speedList[i-1]*0.8; speedList.push_back(speed); leftNormals.push_back( ofxVec2f(-distVec.y, distVec.x) ); rightNormals.push_back( ofxVec2f(distVec.y, -distVec.x) ); } }
bool NawlzBlahParticle :: constrainToImage ( const ofxVec2f& target ) { bool isOutside = false; float px = ( target.x - imageRect.x ) / (float)imageRect.width; float py = ( target.y - imageRect.y ) / (float)imageRect.height; px = ofClamp( px, 0, 1 ); py = ofClamp( py, 0, 1 ); int iw = imageRect.width; int ih = imageRect.height; int ix = px * iw; int iy = py * ih; int p = ( ( iy * iw ) + ix ) * 3; isOutside = imagePixels[ p ] == 255; if( isOutside ) { float cx = imageRect.x + imageRect.width * 0.5; float cy = imageRect.y + imageRect.height * 0.5; float px = target.x - cx; float py = target.y - cy; ofxVec2f vec = ofxVec2f( px, py ); float ang = vec.angle( ofxVec2f( 0, -1 ) ); // return an angle between -180 and 180. wanderTheta = ( ( ang + 180 ) / 360.0 ) * TWO_PI + PI * 0.5; // circle starts at 12 oclock and moves clock wise. wanderTheta *= -1; } return isOutside; }
void polyEditable::keyPressed(ofKeyEventArgs& event) { if( !bEnabled || !bUseKeyPress ) return; if( event.key == ' ') nextMode(); // Note:; may not work cross-platform, tab through points if(event.key == 9 ) { if( mode == POLY_EDIT_MODE_MOVE_PTS ) { selectedPoint++; selectedPoint %= (int)(pts.size()); } } cout << "key " << event.key << " " << OF_KEY_BACKSPACE << endl; if( event.key == OF_KEY_BACKSPACE ) removePoint(); if( event.key == OF_KEY_UP ) { ofxVec2f mup = ofxVec2f(0,-moveBy); mup.rotate(-gRotation); if( mode == POLY_EDIT_MODE_MOVE_ALL ) moveAllPointsBy( ofPoint(mup.x,mup.y) );//ofPoint(0,-1) ); else if( mode == POLY_EDIT_MODE_MOVE_PTS ) movePointBy( selectedPoint, ofPoint(mup.x,mup.y) );//ofPoint(0,-1) ); } else if( event.key == OF_KEY_DOWN) { ofxVec2f mdwn = ofxVec2f(0,moveBy); mdwn.rotate(-gRotation); if( mode == POLY_EDIT_MODE_MOVE_ALL ) moveAllPointsBy( ofPoint(mdwn.x,mdwn.y) ); else if( mode == POLY_EDIT_MODE_MOVE_PTS ) movePointBy( selectedPoint, ofPoint(mdwn.x,mdwn.y) ); } else if( event.key == OF_KEY_LEFT ) { ofxVec2f m = ofxVec2f(-moveBy,0); m.rotate(-gRotation); if( mode == POLY_EDIT_MODE_MOVE_ALL ) moveAllPointsBy( ofPoint(m.x,m.y) ); else if( mode == POLY_EDIT_MODE_MOVE_PTS ) movePointBy( selectedPoint, ofPoint(m.x,m.y) ); else if( mode == POLY_EDIT_MODE_ROTATE ) rotate(-.5); } else if( event.key == OF_KEY_RIGHT ) { ofxVec2f m = ofxVec2f(moveBy,0); m.rotate(-gRotation); if( mode == POLY_EDIT_MODE_MOVE_ALL ) moveAllPointsBy( ofPoint(m.x,m.y) ); else if( mode == POLY_EDIT_MODE_MOVE_PTS ) movePointBy( selectedPoint, ofPoint(m.x,m.y)); else if( mode == POLY_EDIT_MODE_ROTATE ) rotate(.5); } }
ofxVec2f ofxPoint2f::getPerpendicular( const ofxPoint2f& pnt ) const { //float a = -atan2( pnt.y - y, pnt.x - x ); //return ofxVec2f( sin(a), cos(a) ); //the following seems simpler and about 3x faster float vy = -(x - pnt.x); float vx = y - pnt.y; float length = (float)sqrt(vx*vx + vy*vy); if( length > 0 ) return ofxVec2f( vx/length, vy/length ); else return ofxVec2f(x, y); }
void ofxLightning::parse() { // start with one segment segments.clear(); segments.push_back(LSegment(ofxVec2f(fromX, fromY), ofxVec2f(toX, toY), 1.0)); currentDeviation = deviation; // for each iteration for (int i = 0; i < numIterations; i++) { // remove segments from list vector<LSegment> segmentsCopy = segments; segments.clear(); // for each segment int max = segmentsCopy.size(); for (int j = 0; j < max; j++) { // find midpoint between start and end ofxVec2f midPoint = segmentsCopy[j].getMidPoint(); // offset midpoint perpendicularly to segment with a random number with max amplitude float offset = ofRandom(0.0, 1.0) < 0.5 ? -currentDeviation : currentDeviation; midPoint.x += cos(segmentsCopy[j].getRadians() - 0.25 * PI) * offset; midPoint.y += sin(segmentsCopy[j].getRadians() - 0.25 * PI) * offset; // add two new segments to list LSegment a(segmentsCopy[j].start, midPoint, segmentsCopy[j].intensity); LSegment b(midPoint, segmentsCopy[j].end, segmentsCopy[j].intensity); segments.push_back(a); segments.push_back(b); if (ofRandom(0.0, 1.0) < branchingProbability) { // add branch: float branchAngle = a.getRadians() * branchAngleMultiplier; ofxVec2f branchEnd(midPoint.x + cos(branchAngle) * branchScale * a.getLength(), midPoint.y + sin(branchAngle) * branchScale * a.getLength()); LSegment branch(midPoint, branchEnd, branchIntensityFactor * a.intensity); segments.push_back(branch); } } // halve max offset amplitude currentDeviation *= 0.5; } }
//------------------------------------------------------------ void particle::addRepulsionForce(float x, float y, float radius, float scale){ // ----------- (1) make a vector of where this position is: ofxVec2f posOfForce; posOfForce.set(x,y); // ----------- (2) calculate the difference & length ofxVec2f diff = ofxVec2f(pos.x, pos.y) - posOfForce; float length = diff.length(); // ----------- (3) check close enough bool bAmCloseEnough = true; if (radius > 0){ if (length > radius){ bAmCloseEnough = false; } } // ----------- (4) if so, update force if (bAmCloseEnough == true){ float pct = 1 - (length / radius); // stronger on the inside diff.normalize(); frc.x = frc.x + diff.x * scale * pct; frc.y = frc.y + diff.y * scale * pct; } }
//-------------------------------------------------------------- ofxMtActionsObject::ofxMtActionsObject(bool _draggable, bool _scalable, bool _rotatable){ priorityLevel = -1; draggable = _draggable; scalable = _scalable; rotatable = _rotatable; //INIT state = FIXE; stopActionOnRollOut = true; limitToScreen = true; drawTouchCounts = false; accelerationSmoothing = 0.5; decelerationSmoothing = 0.9; rotationalSmoothing = 0.9; minSize = 100; maxSize = 800; scaleSmoothing = 0.9; lastNumberOfTouches = 0; acceleration = ofxVec2f(0,0); rotationalAcceleration = 0.0f; contentWidth = 800; contentHeight = 600; width = 400; height = 300; highestSessionID = -1; }
Spotlight::Spotlight(){ type = OUTPUT; cam = 0; radius = 0; radiusMultiplier = 0; center = ofxVec2f(0.5,0.5); }
void Obstacles::makeObstacles(string _inFile){ ifstream theFile(_inFile.c_str()); vector <string> splitReturn; obPoints newPoints; string line; if(theFile.is_open()){ while(!theFile.eof()){ getline(theFile,line); cout<<line<<endl; splitReturn = ofSplitString(line, ","); vector<string>::iterator iter; newPoints.clear(); for(iter = splitReturn.begin();iter != splitReturn.end();iter++){ //cout<<*iter<<endl; int a = ofToInt(*(iter++)); int b = ofToInt(*(iter)); newPoints.push_back(ofxVec2f(a,b)); } allObstacles.push_back(newPoints); } cout<<allObstacles.size()<<endl; makePoints(); draw(); } else { cout<<"NO FILE!"<<endl; } }
void NawlzBlahParticle :: draw() { float r = sizeRadius; float theta = -vel.angle( ofxVec2f( -1, 0 ) ) - 90; theta += rotation; ofSetColor( 255, 255, 255, 255 * lifeAlpha ); glPushMatrix(); glTranslatef( loc.x, loc.y, 0 ); // glRotatef( theta, 0, 0, 1 ); glRotatef( rotation, 0, 0, 1 ); glScalef( scale, scale, 1.0 ); if( tex ) { tex->draw( -tex->getWidth() * 0.5, -tex->getHeight() * 0.5 ); glPopMatrix(); return; } ofFill(); ofSetColor( 175, 175, 175 ); ofBeginShape(); ofVertex( 0, -r * 2 ); ofVertex( -r, r * 2 ); ofVertex( r, r * 2 ); ofEndShape( true ); glPopMatrix(); }
void starParticle::addAttractionForce(starParticle & p, float radius, float scale) { float x = p.pos.x; float y = p.pos.y; bool bAmCloseEnough = true; if (radius > 0) { if (sqrt((x-pos.x)*(x-pos.x) + (y-pos.y)*(y-pos.y)) > radius) { bAmCloseEnough = false; } } if (bAmCloseEnough == true) { ofxVec2f forceVec = ofxVec2f(0,0); forceVec.x = x-pos.x; forceVec.y = y-pos.y; forceVec.normalize(); forceVec.x *= scale; forceVec.y *= scale; frc.x = frc.x + forceVec.x; frc.y = frc.y + forceVec.y; p.frc.x = p.frc.x - forceVec.x; p.frc.y = p.frc.y - forceVec.y; } }
void SpringScene::update(float timeSinceLastUpdate, float audioLevel){ int percentageToEffect = gui->getValueI(sceneName+"PERCENTAGE_TO_EFFECT_"); float ratioToEffect = percentageToEffect/100.f; int numberToEffect = ratioToEffect*polygons.size(); for(int i=0; i < numberToEffect; i++){ //polygons[i].addAttractionPoint(ofGetWidth()/2.f, ofGetHeight(), audioLevel); no good, too slow // ofxVec2f pt = ofxVec2f(ofRandom(0.f, 1.f), ofRandom(0.f, 1.f)); // ofxVec2f amt = ofxVec2f(audioLevel,audioLevel); // //int randomPolygonIndex = (int)ofRandom(0, polygons.size()); // polygons[randomPolygonIndex].addImpulseForce(pt,amt); //too much slow down ofxVec2f oldVel = polygons[i].getVelocity(); float downness = audioLevel; float rightness = audioLevel; if(ofRandomf() > 0){ downness *= -1; } if(ofRandomf() > 0){ rightness *= -1; //so they don't all tend in the same direction, effectively four options.. } ofxVec2f newVel = oldVel + ofxVec2f(rightness, downness); polygons[i].setVelocity(newVel); } Scene::update(timeSinceLastUpdate, audioLevel); }
void ofxCvBlobTracker::drawWData( float x, float y, float sw, float sh ) { ofEnableAlphaBlending(); glPushMatrix(); glTranslatef( x, y, 0.0 ); glScalef( sw, sh, 1); ofFill(); for( int i=0; i<blobs.size(); i++ ) { // draw with lifespan as alpha float lifeAlpha = MIN(.5*blobs[i].lifeSpan,255); ofxVec2f delta = ofxVec2f(blobs[i].deltaLoc.x,blobs[i].deltaLoc.y); float lenD = delta.lengthSquared(); ofSetColor( 255,0 ,200,lifeAlpha ); ofRect( blobs[i].boundingRect.x, blobs[i].boundingRect.y, blobs[i].boundingRect.width, blobs[i].boundingRect.height ); } ofDisableAlphaBlending(); // contours ofSetColor(0xffffff); for( int i=0; i<blobs.size(); i++ ) { glBegin(GL_LINE_LOOP); for( int j=0; j<blobs[i].pts.size(); j++ ) { glVertex2f( blobs[i].pts[j].x, blobs[i].pts[j].y ); } glEnd(); } // labels ofSetColor( 0xffffff ); for( int i=0; i<blobs.size(); i++ ) { ostringstream docstring; //docstring << blobs[i].id << endl; docstring << findOrder(blobs[i].id) << endl; ofDrawBitmapString( docstring.str(), blobs[i].centroid.x, blobs[i].centroid.y ); } // directions for( int i=0; i<blobs.size(); i++ ) { ofLine(blobs[i].centroid.x,blobs[i].centroid.y,blobs[i].predictedPos.x,blobs[i].predictedPos.y); } glPopMatrix(); }
void Obstacles::makePoints(){ vector<obPoints>::iterator iter; vector<ofxVec2f>::iterator vecIter; int i; for(iter = allObstacles.begin(); iter != allObstacles.end(); iter++){ cout << "starting iter..." << endl; obPoints obs = *iter; for(vecIter = obs.begin(); vecIter != obs.end() - 1; vecIter++){ ofxVec2f a = *(vecIter); ofxVec2f b = *(vecIter + 1); cout << "A = " << a.x << "," << a.y << endl; cout << "B = " << b.x << "," << b.y << endl; int c = getCommon(a,b); if(c == 0){ if(a.y < b.y){ for(i = a.y; i < b.y; i += edge){ cout << "Adding point " << a.x << "," << i << endl; allPoints.push_back(ofxVec2f(a.x,i)); } } else { for(i = a.y; i > b.y; i -= edge){ cout << "Adding point " << a.x << "," << i << endl; allPoints.push_back(ofxVec2f(a.x,i)); } } } else { if(a.x < b.x){ for(i = a.x; i < b.x; i += edge){ cout << "Adding point " << i << "," << a.y << endl; allPoints.push_back(ofxVec2f(i,a.y)); } } else { for(i = a.x; i > b.x; i -= edge){ cout << "Adding point " << i << "," << a.y << endl; allPoints.push_back(ofxVec2f(i,a.y)); } } } } } for(vecIter = allPoints.begin();vecIter != allPoints.end(); vecIter++){ ofxVec2f tt = *(vecIter); cout << tt.x << "," << tt.y << endl; } }
//------------------------------------------------- ofxVec2f vectorField::readFromField(float x, float y){ if(x >= 1.0 || x < 0 || y >= 1.0 || y < 0){ return ofxVec2f(); } int rasterX = (int)(x * NUM_BINS_X); int rasterY = (int)(y * NUM_BINS_Y); ofxVec2f vec = field[rasterX][rasterY]; return vec; }
ofPoint testApp :: getNoiseAtPoint( const ofPoint& point ) { float p = getNoiseAtPoint( point.x, point.y ); ofxVec2f v = ofxVec2f( 0, 1 ); v.rotate( p * 720 ); return ofPoint( v.x, v.y ); }
bool NawlzBlahParticle :: constrainToBorders ( const ofxVec2f& target ) { bool isOutside = false; bool l = target.x < bounds.x; bool t = target.y < bounds.y; bool r = target.x > bounds.x + bounds.width; bool b = target.y > bounds.y + bounds.height; isOutside = l || t || r || b; //--- target back to center of bounds. if( isOutside ) { float cx = bounds.x + bounds.width * 0.5; float cy = bounds.y + bounds.height * 0.5; float px = target.x - cx; float py = target.y - cy; ofxVec2f vec = ofxVec2f( px, py ); float ang = vec.angle( ofxVec2f( 0, -1 ) ); // return an angle between -180 and 180. wanderTheta = ( ( ang + 180 ) / 360.0 ) * TWO_PI + PI * 0.5; // circle starts at 12 oclock and moves clock wise. wanderTheta *= -1; } return isOutside; //--- avoid off wall. this approach did not work. if( l ) wanderTheta = TWO_PI * 0; if( t ) wanderTheta = TWO_PI * 0.25; if( r ) wanderTheta = TWO_PI * 0.5; if( b ) wanderTheta = TWO_PI * 0.75; if( t && r ) wanderTheta = TWO_PI * 0.125; if( r && b ) wanderTheta = TWO_PI * 0.375; if( b && l ) wanderTheta = TWO_PI * 0.625; if( l && t ) wanderTheta = TWO_PI * 0.875; return isOutside; }
void testApp::extractData() { for (int i =0; i< svgPaths.shapes.size(); i++){ vector <ofxVec2f> shapePoints; for (int j=0; j< svgPaths.shapes[i].pt.size(); j++){ shapePoints.push_back(ofxVec2f(svgPaths.shapes[i].pt[j].p.x, svgPaths.shapes[i].pt[j].p.y)); } extractedShapes.push_back(shapePoints); } }
void VirusBase::update() { // remove_if sorts to the end via a boolean value, // http://en.wikipedia.org/wiki/Erase-remove_idiom //barbs.erase( remove_if(barbs.begin(), barbs.end(), bRemoveBarb), barbs.end() ); for (int i = 0; i < barbs.size(); i++) { //barbs[i].spring(bodyPts[i].x, bodyPts[i].y, 0.f, .02f, 500.f); if (barbs[i].status == STATUS_SEEKING) { //barbs[i].updateTarget(mouseX, mouseY); //barbs[i].seek(mouseX, mouseY); barbs[i].updateBaseLoc(bodyPts[barbs[i].bodyPtIndex].loc.x + loc.x, bodyPts[barbs[i].bodyPtIndex].loc.y + loc.y); barbs[i].steer(ofxVec2f(mouseX, mouseY), false, 1.9); } if (barbs[i].status != STATUS_REMOVE) { barbs[i].update(); } } for (int i = 0; i < bodyPts.size(); i++) { bodyPts[i].fixedSpring(0.f, 0.f, 0.3f, bodyPts[i].originPt.length(), acc); } for (int i = 0; i < bodyPts.size(); i++) { //elasticEdges( bodyPts[i], 1.75, -WALL_PADDING, .08f); bounceOffEdges( bodyPts[i], .7f, WALL_PADDING, .08f ); bodyPts[i].update( ); } addDamping(.0009); bounceOffEdges( .04f, WALL_PADDING ); acc *= oneOverMass; vel += acc; vel.limit( MAX_SPEED ); loc += vel; torque += -angVel * ANGULAR_DAMPING; angVel += ( torque * oneOverMomentOfInertia ); orientation += angVel; for (int i = 0; i < bodyPts.size(); i++) { bodyPts[i].loc.set(bodyPts[i].loc.length(), 0); bodyPts[i].loc.rotateRad( orientation + bodyPts[i].orientation ); // these barbs are drawn in world coords, because once fired it is easier to keep track // if (barbs[i].status == STATUS_ALIVE) { barbs[i].loc.set(bodyPts[barbs[i].bodyPtIndex].loc.x + loc.x, bodyPts[barbs[i].bodyPtIndex].loc.y + loc.y); barbs[i].setDirection( bodyPts[barbs[i].bodyPtIndex].loc ); } } acc.set(0, 0); torque = 0.f; }
void particleManager::handleMouseDrag(float x, float y) { float pctx = (float)x / (float)ofGetWidth(); float pcty = (float)y / (float)ofGetHeight(); ofxVec2f curPos = ofxVec2f(pctx, pcty); ofxVec2f diff = curPos - prevPos; if (diff.length() < 4) { ofxVec2f angle = diff / 1.0f; VF.addIntoField(pctx, pcty, angle, 0.093); } prevPos = curPos; }
void polyFixWidth::setPerpendiculars(float len ) { if( pts.size() >= 2 ) { // create vector for each end point ofxVec2f ptA = ofxVec2f(pts[0].x,pts[0].y); ofxVec2f ptB = ofxVec2f(pts[1].x,pts[1].y); // calculate perpendicular ofxVec2f diffVec = ptA-ptB; diffVec = diffVec.getNormalized(); ofxVec2f pp = diffVec.getPerpendicular(); ofPoint c = getCentroid(); ppA.set( c.x + len * pp.x, c.y + len * pp.y); ppB.set( c.x - len * pp.x, c.y - len * pp.y); } }
//------------------------------------------------- void vectorField::randomize(float mag, float pct){ pct = MIN(1.0, pct); pct = MAX(0.0, pct); for(int yy = 0; yy < NUM_BINS_Y; yy++){ for(int xx = 0; xx < NUM_BINS_X; xx++){ field[xx][yy] *= 1.0 - pct; field[xx][yy] += ofxVec2f( ofRandom(-1.0, 1.0), ofRandom(-1.0, 1.0)) * mag * pct; } } }
void MiniObject::drawTriangle(const Particle pp1, const Particle pp2, const Particle pp3, int isFront, float blockX, float blockY){ ofxVec2f t1; ofxVec2f t2; ofxVec2f t3; int x=0; int y=0; if (isFront==0) { t1 = ofxVec2f((x+1) * blockX, y * blockY); t2 = ofxVec2f(x * blockX, y * blockY); t3 = ofxVec2f(x * blockX, (y+1) * blockY); }else { t1 = ofxVec2f((x+1) * blockX, (y+1) * blockY); t2 = ofxVec2f((x+1) * blockX, y * blockY); t3 = ofxVec2f(x * blockX, (y+1) * blockY); } //glTexCoord2fv(t1.v); glNormal3fv(pp1.getNormal().getXLocation()); glVertex3fv(pp1.getPosition().getXLocation()); //glTexCoord2fv(t2.v); glNormal3fv(pp2.getNormal().getXLocation()); glVertex3fv(pp2.getPosition().getXLocation()); //glTexCoord2fv(t3.v); glNormal3fv(pp3.getNormal().getXLocation()); glVertex3fv(pp3.getPosition().getXLocation()); }
void polyFixWidth::makeRectangle() { if( pts.size() == 2 ) { float hW = width * .5f; // get perpendicular ofxVec2f ptA = ofxVec2f(pts[0].x,pts[0].y); ofxVec2f ptB = ofxVec2f(pts[1].x,pts[1].y); ofxVec2f ptDiff = ptA-ptB; center.set((ptA.x+ptB.x)*.5,(ptA.y+ptB.y)*.5); if( bSquare ) { // hW = length*.5; ofxVec2f ptNormal = ptDiff; ptNormal = ptNormal.normalize(); pts[0].set(center.x - hW * ptNormal.x,center.y - hW * ptNormal.y); pts[1].set(center.x + hW * ptNormal.x,center.y + hW * ptNormal.y); ptA.set(pts[0].x,pts[0].y); ptB.set(pts[1].x,pts[1].y); } length = ptDiff.length(); ofxVec2f pp = ptDiff.perpendicular(); rectPts.clear(); rectPts.push_back( ofPoint(ptA.x + hW * pp.x, ptA.y + hW * pp.y) ); rectPts.push_back( ofPoint(ptB.x + hW * pp.x, ptB.y + hW * pp.y) ); rectPts.push_back( ofPoint(ptB.x - hW * pp.x, ptB.y - hW * pp.y) ); rectPts.push_back( ofPoint(ptA.x - hW * pp.x, ptA.y - hW * pp.y) ); }else{ //cout << "t pts " << pts.size() << endl; } }
void NawlzBlahParticle :: wander() { wanderTheta += ofRandom( -wanderChange, wanderChange ); // Randomly change wander theta circle = vel; // Start with velocity circle.normalize(); // Normalize to get heading circle *= wanderDistance; // Multiply by distance circle += loc; // Make it relative to boid's location circleOffSet = ofxVec2f( wanderRadius * cos( wanderTheta ), wanderRadius * sin( wanderTheta ) ); circleTarget = circle + circleOffSet; acc += steer( circleTarget ); }
//******************************************************************************************************* void CDaisyScene::DrawCircleRecursive(float dist, float size, float f, ofxVec2f pos, float alpha) { glTranslatef(pos.x, pos.y, 0); int num = (int)dist; static int num_per_recurse = 25; if(num > num_per_recurse) { dist *= 0.5f; float angle = GetWorldTime() * 2.0f; float inc_num = num_per_recurse / 4; float angle_inc = TWO_PI / (float)inc_num; for(int i=0; i<inc_num; i++) { angle += angle_inc; ofxVec2f final_pos = ofxVec2f(sin(angle), -cos(angle)); final_pos *= 3.0f * dist; glPushMatrix(); DrawCircleRecursive(dist, size*0.7f, f, final_pos, alpha); glPopMatrix(); } } else { //dist -= 1.0f; ofSetColor(255, 255*f, 0.0f, alpha); //ofCircle(pos.x, pos.y, GetApp().GetScreenRelativeSize(0.05f)); ofCircle(0, 0, GetApp().GetScreenRelativeSize(0.05f*size)); //float angle = GetWorldTime() * 2.0f; //float angle_inc = TWO_PI / dist; //size /= (dist/10.0f); //RMath::Limit(0.0f, size, 0.1f); //dist -= 1.0f; //ofSetColor(255, 255*f, 0.0f, dist*dist); //for(int i=0; i<num; ++i) //{ // angle += angle_inc; // ofxVec2f final_pos = pos + ofxVec2f(sin(angle), -cos(angle)) * dist * 2.0f; // ofCircle(final_pos.x, final_pos.y, GetApp().GetScreenRelativeSize(0.1f*size*size_mul)); //} } }
void testApp::setup() { ofSetWindowTitle(appName); ofSetVerticalSync(true); ofSetLogLevel(OF_LOG_VERBOSE); ofSeedRandom(0); PhotoManager::setup("~/Desktop/3rdiStream/resized/"); setupOsc(); ofxVec2f size = getMaxSize(); surface.setup(size, ofxVec2f(60, 100)); wall.setup(surface); }
void testApp::mouseMoved(int x, int y) { if(master) { ofxOscMessage message; message.setAddress("mouse"); ofxVec2f cur(x, y); cur /= ofxVec2f(ofGetWidth(), ofGetHeight()); message.addFloatArg(cur.x); message.addFloatArg(cur.y); oscSender.sendMessage(message); } }
//******************************************************************************************************* void CDaisyScene::Draw() { float h = GetAppHeight(); float w = GetAppWidth(); // clear depth buffer (but not color buffer) glClear(GL_DEPTH_BUFFER_BIT); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glPushMatrix(); ofxVec2f centre = ofxVec2f(w/2.0f, h/2.0f); float time = GetWorldTime(); //centre += ofxVec2f(GetSoundEngine().GetMovement(0.2f)*w*0.05, GetSoundEngine().GetMovement(0.6f)*h*0.05f); float f = 0.0f; for(TParticleList::iterator it = m_Particles.begin(); it != m_Particles.end(); ++it) { CBasicParticle* p_particle = *it; ofxVec2f pos = centre + p_particle->GetPos() * w * 0.5f; float size = GetSoundEngine().GetAverage(f); RMath::LimitUpper(size, 0.5f); size *= (1.0f + GetSoundEngine().GetMovement(f)); //size *= 0.1f; float dist = p_particle->GetPos().length() * 100.0f; RMath::Limit(1.0f, dist, 100.0f); float size_mul = 1.0f; glPushMatrix(); float alpha = dist * 2.0f; DrawCircleRecursive(dist, size, f, pos, alpha); glPopMatrix(); f += one_on_num; } glDisable(GL_BLEND); glPopMatrix(); }