//-------------------------------------------------------------- void testApp::setup(){ ofSetLogLevel(OF_LOG_VERBOSE); ofBackground(50, 50, 50); ofSetVerticalSync(false); ofEnableAlphaBlending(); shader.setGeometryInputType(GL_LINES); shader.setGeometryOutputType(GL_TRIANGLE_STRIP); shader.setGeometryOutputCount(4); shader.load("shaders/vert.glsl", "shaders/frag.glsl", "shaders/geom.glsl"); printf("Maximum number of output vertices support is: %i\n", shader.getGeometryMaxOutputCount()); // create a bunch of random points float r = ofGetHeight()/2; for(int i=0; i<100; i++) { points.push_back(ofPoint(ofRandomf() * r, ofRandomf() * r, ofRandomf() * r)); } doShader = true; ofEnableDepthTest(); }
//-------------------------------------------------------------- void testApp::draw(){ fbo.begin(); ofSetTextureWrap(GL_REPEAT,GL_REPEAT); fbfbo.draw(0,2); //cam.draw(0,0); fbfbo.getTextureReference().bind(); trik2.draw(); fbfbo.getTextureReference().unbind(); ofSetColor(255,255,255); if(tritimer>tritimerlimit){ float xpt, ypt,xtoff,ytoff; //draw gradient splashes ofMesh trik; for(int b = 0;b<5;b++){ xtoff = ofRandomf()*0.5; ytoff = ofRandomf()*0.5; for(int i=0;i<3;i++){ xpt = ofRandomuf()*2+xtoff; ypt = ofRandomuf()*2+ytoff; trik.addVertex(ofVec3f(xpt*w,ypt*h,0)); trik.addColor(ofFloatColor(float(ofRandomuf()>0.5)*0.6+0.4,float(ofRandomuf()>0.5)*0.5+0.5,float(ofRandomuf()>0.5)*0.7+0.3)); } } trik.draw(); tritimer = 0; tritimerlimit= ofRandom(20,200); } if(tritimer2>45){ //re-generate the feedback triangles float xpt, ypt,xoff,yoff,xtoff,ytoff; trik2.clear(); //ofEnableNormalizedTexCoords(); for(int b = 0;b<5;b++){ xoff = ofRandomf()*0.1; yoff = ofRandomf()*0.1; xtoff = ofRandomf()*0.5; ytoff = ofRandomf()*0.5; for(int i=0;i<3;i++){ xpt = ofRandomuf()+xtoff; ypt = ofRandomuf()+ytoff; trik2.addVertex(ofVec3f((xpt+xoff)*w,(ypt+yoff)*h,0)); trik2.addTexCoord(ofVec2f(xpt*w,ypt*h)); trik2.addColor(ofFloatColor(1,1,1)); } } tritimer2=0; tritimer2limit= ofRandom(20,200); //ofDisableNormalizedTexCoords(); } fbo.end(); fbfbo.begin(); fbo.draw(0,0); fbfbo.end(); fbo.draw(0,0); }
//-------------------------------------------------------------- void testApp::setup() { ofBackground(0, 0, 0); ofSetVerticalSync(true); ofSetLineWidth(3.0); cameraRotation = 0; zoom = -500; zoomTarget = 200; // ------------------------- billboard particles for (int i=0; i<NUM_BILLBOARDS; i++) { billboardVels[i].set(ofRandomf(), -1.0, ofRandomf()); billboardVerts[i].set(ofRandom(-500, 500), ofRandom(-500, 500), ofRandom(-500, 500)); billboardColor[i].set(1, 0, 0, ofRandomuf()); billboardSize[i] = 0; billboardSizeTarget[i] = ofNextPow2(ofRandom(4, 24)); // faster to have a power of 2 } billboardVbo.setVertexData(billboardVerts, NUM_BILLBOARDS, GL_DYNAMIC_DRAW); billboardVbo.setColorData(billboardColor, NUM_BILLBOARDS, GL_DYNAMIC_DRAW); // load the bilboard shader // this is used to change the // size of the particle billboardShader.load("shaders/BillboardExample"); // we need to disable ARB textures // because we are binding ourselfs ofDisableArbTex(); texture.loadImage("images/dot.png"); }
void testApp::setup() { ofSetFrameRate(60); ofBackgroundHex(0x000000); glPointSize(1.0); cameraRotation = 0; zoom = -500; zoomTarget = 200; for (int i=0; i<NUM_PARTICLES; i++) { myVels[i].set(ofRandomf(), -1.0, ofRandomf()); myVerts[i].set(0, 0, 0); myColor[i].set(1, 1, 1, 1); } myVbo.setVertexData(myVerts, NUM_PARTICLES, GL_DYNAMIC_DRAW); myVbo.setColorData(myColor, NUM_PARTICLES, GL_DYNAMIC_DRAW); // デバイスの接続するポートとスピードを設定 ard.connect("/dev/cu.usbserial-A900ceWs", 57600); // Arduinoとの接続が確立するのを監視するリスナー ofAddListener(ard.EInitialized, this, &testApp::setupArduino); // 接続の確立したかどうかのフラグ bSetupArduino = false; }
void Fireworks::setup() { mesh_ = ofMesh::icosphere(10, 2); vector<ofMeshFace> tris = mesh_.getUniqueFaces(); float globalOffset = ofRandomuf(); for (auto it = tris.begin(); it != tris.end(); it++) { ofVec3f v = (it->getVertex(0) + it->getVertex(1) + it->getVertex(2)) / 3.0f; float l = floor((1.0f - pow(ofRandomuf(), 3.0f)) * 3.0f); ofVec3f center = ofVec3f(v).normalize() * (l + 1) * 8; float offset = l / 3.0f + ofRandomuf() * 0.1f + globalOffset; float speed = ofRandomuf(); ofVec3f axis(ofRandomf(), ofRandomf(), ofRandomf()); axis.normalize(); for (int i = 0; i < 3; i++) { it->setVertex(i, it->getVertex(i) - v); center_.push_back(center.x); center_.push_back(center.y); center_.push_back(center.z); offset_.push_back(offset); speed_.push_back(speed); axis_.push_back(axis.x); axis_.push_back(axis.y); axis_.push_back(axis.z); } } mesh_.setUsage(GL_STATIC_DRAW); mesh_.setFromTriangles(tris); shader_.load("shaders/fireworks"); palette_.loadImage("color_palette.jpg"); setScale(ofRandom(2, 5)); start_time_ = 0; moving_ = false; }
void ofApp::draw_vid(){ #ifdef USE_GRABBER ofPushMatrix();{ // ofScale( canvas.height/grbW, canvas.width/grbH ); ofScale( canvas.height/grbH, canvas.width/grbH ); //ofScale( canvas.height/grbW, canvas.width/grbW ); ofSetColor(255,10); grayImg.draw(0, 0); vector<ofVec2f> lines; int size = feat.size(); for( int i=0; i<size-1; i++){ for( int j=i+1; j<size; j++){ //int id1 = ofRandom(0, size); //int id2 = ofRandom(0, size); int id1 = i; int id2 = j; const ofVec2f & v1 = feat[id1]; const ofVec2f & v2 = feat[id2]; float dist = v1.distance(v2); float max = 10; float noise = ofNoise(i*j+ofRandomf()); if( noise>0.8 ) max = 1000.0f; if( 1<dist && dist<max ){ lines.push_back(v1); lines.push_back(v2); } } } ofSetLineWidth(1); ofSetColor(40, 55); ob::drawLines(lines); glPointSize(2); ofSetColor(55,155); ob::drawDots(feat); } ofPopMatrix(); #endif }
Particle::Particle() : // Using initializer list angle(ofRandomf() * PI), // Set to random angle from -PI to PI speed(ofRandom(MIN_SPEED,MAX_SPEED)), // Set to random speed within bounds alpha(ofRandom(MIN_ALPHA,MAX_ALPHA)), // Set to random rotational acceleration flow(ofRandom(MIN_FLOW,MAX_FLOW)), // Set to random translational acceleration radius(ofRandom(MIN_RADIUS,MAX_RADIUS)), // Set to varible radius color(speed/MAX_SPEED * 255,position.x/ofGetWindowWidth() * 255,position.y/ofGetWindowHeight() * 255), // Set color position(ofVec2f(ofRandom(radius,ofGetWindowWidth() - radius),ofRandom(radius,ofGetWindowHeight() - radius))), // Set to random position velocity(ofVec2f(cos(angle) * speed,sin(angle) * speed)), // Set to correct velocity attract(false), // Set to no attraction repel(false), // Set to no repulsion alive(true) // Set true to create bug-like movement { }
void Branch::setup(float _xPos, float _yPos){ float xPos = _xPos; float yPos = _yPos; float speed = 5; ofSetColor(255, 0, 0); ofFill(); float rand = ofRandomf(); cout << rand << endl; if(yPos >= -500){ float newX = xPos + ofRandom(-10,10); float newY = yPos - speed; ofDrawLine(xPos, yPos, newX, newY); setup(newX, newY); } }
void recursiveFun(float _xPos, float _yPos){ float xPos = _xPos; float yPos = _yPos; float speed = 5; ofSetColor(255, 0, 0); ofFill(); float rand = ofRandomf(); cout << rand << endl; if(rand >= 0){ float newX = xPos + ofRandom(-5,5); float newY = yPos - speed; ofDrawLine(xPos, yPos, newX, newY); recursiveFun(newX, newY); } }
void chispa::update() { if (v <= 0) return; x += ofRandom(-2, 2); y -= fabs(s / ofRandom(4,5)); v -= (float)ofRandom(5, 40) / 100; /* int aa = a + ofRandom(-5, 5); if (aa < 85) aa = 85; if (aa > 95) aa = 95; x += sin(ofDegToRad(aa)) * s; y += cos(ofDegToRad(aa)) * s; */ if (v > 0) { int al = 0x1f; ofColor amarillo = ofColor(255, 255, 0, al); ofColor rojo = ofColor(255, 0, 0, al); ofSetLineWidth(1); ofFill(); ofEnableBlendMode(OF_BLENDMODE_ADD);//MULTIPLY); if (v / MAX_VIDA > .90) { ofSetColor(amarillo.lerp(ofColor(255, 255, 255, al / 2), v / MAX_VIDA)); ofEllipse(x, y, 10, 5); } ofSetColor(rojo.lerp(amarillo, (v / MAX_VIDA))); //ofCircle(x, y, 4 * (1 - (v / MAX_VIDA))); float r = (1 - (v / MAX_VIDA)); //float r = (v / MAX_VIDA); ofBeginShape(); for (int fa = 0; fa < 360; fa += (360 / ofRandom(4,8))) { float faa = ofDegToRad(fa), ra = 10 * fabs(ofRandomf() * r); ofVertex(x + (sin(faa) * ra), y + (cos(faa) * ra)); } ofEndShape(true); //ofEllipse(x, y, 4 * r, 8 * r); ofDisableBlendMode(); } }
void electromagnetica::setupParticles(){ int w= W_WIDTH; int h= W_HEIGHT; //Loop through all the rows numParticles = 0; //Loop through all the columns // Distribuir las particulas por la escena ofSeedRandom(); for ( int y = 0 ; y < h ; y+=options_sampling ){ for ( int x = 0 ; x < w ; x+=options_sampling ){ // particles.push_back(Particle(ofVec3f(0,0,0),ofColor(255,255,255) ,x,y)); // float px = ofRandom(-1000,1000); // float py = ofRandom(-1000,1000); // float pz = ofRandom(0,5000); // particles.push_back(Particle(ofVec3f(px,py,pz) ,ofColor(255,255,255) ,x,y)); if(ofRandomf()>0.5) { Particle mparticle=Particle(ofVec3f(x,y,3) ,ofColor(255,255,255) ,x,y); particles.push_back(mparticle); meshParticles.addVertex(mparticle.position ); meshParticles.addColor(mparticle.color); } else{ Particle mparticle=Particle(ofVec3f(x,y,3) ,ofColor(0,0,0) ,x,y); particles.push_back(mparticle); meshParticles.addVertex(mparticle.position ); meshParticles.addColor(mparticle.color); } numParticles++ ; } } cout<< "particulas mesa EM:" <<numParticles <<endl; resetExtraParticles(); }
void Scene2Controller::Update() { model_.dialogue.Update(); UpdateRackets(); model_.world.Step(delta_time * 0.5, box2d_velocity_iterations, box2d_position_iterations); if (model_.score >= max_balls_goal) { scene_manager.NextScene(); return; } model_.score = 0.0; model_.inverse_score = 0.0; for (auto ball : model_.ball_body) { if (ball->GetPosition().x > 0 && ball->GetLinearVelocity().Length() < 5.0) { model_.score += 1.0; } if (ball->GetPosition().x < 0 && ball->GetLinearVelocity().Length() < 5.0) { model_.inverse_score += 1.0; } } if (ofGetElapsedTimef() > scene_begin_time + 8.0 && ofGetFrameNum() % 1 == 0 && model_.ball_body.size() < max_balls) { const ofVec2f position = ball_initial_position.GetValue() + ofVec2f(-ofNoise(-1.7 * ofGetElapsedTimef()), ofSignedNoise(1.3 * ofGetElapsedTimef())); const ofVec2f velocity = ball_initial_velocity.GetValue() .rotated(-15.0 + ofSignedNoise(ofGetElapsedTimef()) * 30.0) * (1.0 + 0.1 * ofSignedNoise(1.3 * ofGetElapsedTimef())); CreateBall(position, velocity, 0.0, angular_velocity * ofRandomf()); if (model_.ball_body.size() > max_balls) { b2Body *const body = model_.ball_body.front(); DestroyBall(body); model_.ball_body.pop_front(); } } if (keys[OF_KEY_BACKSPACE] && !previous_keys[OF_KEY_BACKSPACE]) { if (model_.ball_body.size() > 0) { b2Body *const body = model_.ball_body.front(); DestroyBall(body); model_.ball_body.pop_front(); } } Controller::Update(); }
void Maho::toggleSpark(){ mahoPhase = 0; fadeCount = 0; drawing = true; color = mainPink; if (bLine1) { float anAngle = 360.0f / line1Num; float firstAngle = ofGetElapsedTimef() * 360.0f; for (int i = 0; i < line1Num; i++) { myLine line = myLine(firstAngle + anAngle * i + ofRandomf()); lines.push_back(line); } } if (bBunshi){ //bunshi for (int i = 0; i < bunshiNum; i++) { bunshi b = bunshi(); bunshis.push_back(b); } } if (bLine2) { //line2 float aAm = 360.0f / line2Num; for (int i = 0; i < line2Num; i++) { myLine2 l = myLine2(aAm * i * ofRandom(0.0f, 30.0f)); lines2.push_back(l); } } if (bBlob){ b.toggleStart(blobPointNum); b2.toggleStart(blobPointNum); } if (mahoIndex == 2) { bSera = false; sera.setup(); } printf("goko1発射!!\n"); seraDid = false; }
void Scene2Controller::RacketCollide(ofVec2f racket_position, ofVec2f hit_direction, float hit_mean, int key_left, int key_right) { for (auto ball : model_.ball_body) { const ofVec2f position = ofVec2f(ball->GetPosition().x, ball->GetPosition().y); const float dx = ball->GetLinearVelocity().x; if (ofRandomuf() < 0.1 && abs((position - racket_position).x) < racket_speed + racket_radius && abs((position - racket_position).y) < racket_speed + 2.0 * racket_radius) { float variance = 0.0; float angular_velocity = 0.0; if ((keys[key_left] && dx < 0) || (keys[key_right] && dx > 0)) { variance = -hit_variance * ofRandomuf(); } else if ((keys[key_left] && dx > 0) || (keys[key_right] && dx < 0)) { variance = hit_variance * ofRandomuf(); } else { variance = hit_variance * ofRandomf(); } const ofVec2f velocity = 2.0 * hit_mean * (1.0 + variance) * hit_direction; ball->SetLinearVelocity(b2Vec2(velocity.x, velocity.y)); } } }
//-------------------------------------------------------------- void testApp::setup(){ string fontfiles[8] = { "fonts/Dreamer.ttf", "fonts/FantasticParty.ttf", "fonts/Google-spies PERSONNAL USE ONLY.ttf", "fonts/Kimmun.ttf", "fonts/Opificio-Serif-regular.ttf", "fonts/Royal Delight.ttf", "fonts/soft_lines_7.ttf", "fonts/StoneBird.ttf" }; for(int i=0; i<8; i++) { ofTrueTypeFont font; font.loadFont(fontfiles[i], FONT_SIZE); fonts.push_back(font); } int n = ofRandom(fonts.size()); input.font = fonts[n]; input.word = ""; input.color.setHsb(ofRandom(255), 255, 255); input.shake = ofRandomf() * 5; }
int locCloud::simulateHist(vector<float> nMeans, vector<float> nStdDevs) { float x, tmp; int numGaussians = nMeans.size(); if ( nMeans.size() != nStdDevs.size() ){ return -1; } for (int ii=0; ii < numParticles; ii++){ x = particles[ii].repAngle; tmp = 0; for (int jj=0; jj<numGaussians; jj++){ tmp += eval_norm_pdf(x, nMeans[jj], nStdDevs[jj]); tmp += eval_norm_pdf(x-360, nMeans[jj], nStdDevs[jj]); tmp += eval_norm_pdf(x+360, nMeans[jj], nStdDevs[jj]); } float noiseFac = ofRandomf()+1; //random numer between 0 and 2 noiseFac = 1; doaHist[ii] = noiseFac*tmp; } return 0; }
void Scene3Controller::RacketCollide(ofVec2f racket_position, ofVec2f hit_direction, float hit_mean, int key_left, int key_right, bool opponent) { if (model_.ball_body) { const ofVec2f position = ofVec2f(model_.ball_body->GetPosition().x, model_.ball_body->GetPosition().y); const float dx = model_.ball_body->GetLinearVelocity().x; const float probability = model_.opponent_index == 8 ? 1.0 : 0.1; if (ofRandomuf() < probability && abs((position - racket_position).x) < ball_radius + 2.0 * racket_radius && abs((position - racket_position).y) < ball_radius + 2.0 * racket_radius) { float variance = 0.0; float angular_velocity = 0.0; if ((keys[key_left] && dx < 0) || (keys[key_right] && dx > 0)) { variance = -hit_variance * ofRandomuf(); } else if ((keys[key_left] && dx > 0) || (keys[key_right] && dx < 0)) { variance = hit_variance * ofRandomuf(); } else { variance = hit_variance * ofRandomf(); } const ofVec2f velocity = hit_mean * (1.0 + variance) * hit_direction; model_.ball_body->SetLinearVelocity(b2Vec2(velocity.x, velocity.y)); model_.bounces = 0; if (opponent && model_.opponent_index == 1) { model_.time_slowed = true; } if (!opponent && model_.opponent_index == 1) { model_.time_slowed = false; } if (opponent && model_.opponent_index == 8) { model_.bounces += 1; } if (opponent && model_.opponent_index == 2) { for (int i = 0; i < 4; ++i) { b2BodyDef ball_body_definition; ball_body_definition.type = b2_dynamicBody; ball_body_definition.position.Set(model_.ball_body->GetPosition().x + 0.1 * ofRandomf(), model_.ball_body->GetPosition().y + 0.1 * ofRandomf()); ball_body_definition.linearVelocity.Set(model_.ball_body->GetLinearVelocity().x + 3.0 * ofRandomf(), model_.ball_body->GetLinearVelocity().y + 0.25 * ofRandomf()); ball_body_definition.angle = model_.ball_body->GetAngle(); ball_body_definition.angularVelocity = model_.ball_body->GetAngularVelocity(); ball_body_definition.linearDamping = linear_damping; ball_body_definition.angularDamping = angular_damping; model_.extra_balls.push_back(model_.world.CreateBody(&ball_body_definition)); b2CircleShape ball_shape; ball_shape.m_radius = ball_radius; b2FixtureDef ball_fixture_definition; ball_fixture_definition.shape = &ball_shape; ball_fixture_definition.density = density; ball_fixture_definition.restitution = restitution; ball_fixture_definition.friction = friction; model_.extra_balls.back()->CreateFixture(&ball_fixture_definition); } } if (opponent && model_.opponent_index == 4 && ofGetElapsedTimef() > model_.last_hit + 0.3) { if (model_.glass_hits == 0) { model_.served = true; } if (model_.glass_hits <= 2) { model_.glass = 0.0; } model_.glass_hits += 1; if (model_.glass_hits == 3) { glassbreak.setPan(model_.opponent.x / half_court_length); glassbreak.play(); for (int i = 0; i < 100; ++i) { Scene3Model::Particle particle; particle.position = model_.opponent + ofVec2f(racket_radius * ofRandomf(), 4.0 * racket_radius * ofRandomuf()); particle.velocity = ofVec2f(3.0 / 4.0 * ofRandomf(), ofRandomf() / 4.0); particle.angle = ofRandomf(); particle.angular_velocity = 10.0 * ofRandomf(); particle.life = 1.0; model_.particles.push_back(particle); } } } if (model_.opponent_index == 7) { Scene3Model::Trail trail; trail.position = OpenFrameworksVector(model_.ball_body->GetPosition()); trail.text = "Volley"; model_.ball_trail.push_back(trail); } model_.served = true; hit1.setSpeed(ofRandom(0.8, 1.2)); hit2.setSpeed(ofRandom(0.8, 1.2)); hit1.setPan(racket_position.x / half_court_length); hit2.setPan(racket_position.x / half_court_length); if (ofGetElapsedTimef() > model_.last_hit + 0.3) { ofRandomuf() > 0.5 ? hit1.play() : hit2.play(); } model_.last_hit = ofGetElapsedTimef(); } } }
void Scene3Controller::BeginContact(b2Contact* contact) { const b2Body *body_a = contact->GetFixtureA()->GetBody(); const b2Body *body_b = contact->GetFixtureB()->GetBody(); const b2Body *ball = nullptr, *court = nullptr; if (model_.ball_body == body_a) { ball = body_a; } if (model_.ball_body == body_b) { ball = body_b; } if (model_.court_body == body_a) { court = body_a; } if (model_.court_body == body_b) { court = body_b; } if (contact->GetFixtureA() == model_.eight_body->GetFixtureList()->GetNext() || contact->GetFixtureB() == model_.eight_body->GetFixtureList()->GetNext()) { model_.ball_body->GetFixtureList()->SetRestitution(restitution); } if (ball && court) { if (model_.opponent_index == 3 && model_.bounces == 0) { cardtable.play(); for (int i = 0; i < 13; ++i) { Scene3Model::Particle particle; particle.position = ofVec2f(0.377 * half_court_length, court_thickness + racket_radius); particle.velocity = ofVec2f(3.0 / 4.0 * ofRandomf(), ofRandomf() / 4.0); particle.angle = ofRandomf(); particle.angular_velocity = 10.0 * ofRandomf(); particle.life = 1.0; model_.particles.push_back(particle); } } if (model_.opponent_index == 7) { Scene3Model::Trail trail; trail.position = OpenFrameworksVector(model_.ball_body->GetPosition()); trail.text = "Bounce"; model_.ball_trail.push_back(trail); } if (model_.opponent_index == 8) { if (!model_.eight_on_left_side || ball->GetPosition().x < 0) { model_.opponent_target.x = model_.opponent.x = ball->GetPosition().x; } if (!model_.eight_on_left_side && model_.opponent.x < 0.0) { model_.eight_on_left_side = true; } } if (model_.opponent_index == 8 && (!model_.eight_on_left_side || ball->GetPosition().x < 0)) { for (int i = 0; i < 13; ++i) { Scene3Model::Particle particle; particle.position = ofVec2f(model_.opponent.x, court_thickness + racket_radius); particle.velocity = ofVec2f(ofRandomf(), ofRandomf()); particle.angle = ofRandomf(); particle.angular_velocity = 10.0 * ofRandomf(); particle.life = 1.0; model_.particles.push_back(particle); } } } if (ball && court && ball->GetPosition().x > 0 && model_.served) { model_.bounces += 1; if (model_.opponent_index != 9 && model_.bounces == ((model_.opponent_index == 5) ? 8 : 2)) { model_.angle = 0.0; model_.score += 1; model_.ball_in_play = false; if (model_.opponent_index == 5) { model_.opponent = model_.opponent_target = ofVec2f(half_court_length, racket_radius + court_thickness); } model_.dialogue.Trigger("point"); } else if (model_.opponent_index == 9 && model_.bounces == 2) { if (model_.mirror_score < 2) { model_.mirror_score += 1; model_.ball_in_play = false; model_.dialogue.Trigger("score"); } else { model_.score += 1; model_.ball_in_play = false; model_.dialogue.Trigger("point"); } } } else if (ball && court && ball->GetPosition().x < 0) { model_.bounces = 0; } if (ball) { bounce1.setPan(ball->GetPosition().x / half_court_length); bounce2.setPan(ball->GetPosition().x / half_court_length); bounce3.setPan(ball->GetPosition().x / half_court_length); bounce4.setPan(ball->GetPosition().x / half_court_length); if (ofRandomuf() < 0.5) { if (ofRandomuf() < 0.5) { bounce1.setSpeed(ofRandom(0.8, 1.2)); bounce1.play(); } else { bounce2.setSpeed(ofRandom(0.8, 1.2)); bounce2.play(); } } else { if (ofRandomuf() < 0.5) { bounce3.setSpeed(ofRandom(0.8, 1.2)); bounce3.play(); } else { bounce4.setSpeed(ofRandom(0.8, 1.2)); bounce4.play(); } } } }
//-------------------------------------------------------------- void testApp::setup(){ frameRate = 30; ofSetFrameRate(frameRate); ofSetVerticalSync(true); _attention.x = ofRandomf(); _meditation.x = ofRandomf(); audioLevelsPreview.allocate(320, 240); frame.allocate(640, 480, OF_IMAGE_COLOR); spread = 2.0; bRecording = false; cam.initGrabber(320, 240); // // Set up audio // masterMixer.setInputBusCount(2); reverb = ofxAudioUnit(kAudioUnitType_Effect, kAudioUnitSubType_MatrixReverb); varispeed = varispeed = ofxAudioUnit(kAudioUnitType_FormatConverter, kAudioUnitSubType_Varispeed); lowpass = ofxAudioUnit(kAudioUnitType_Effect, kAudioUnitSubType_LowPassFilter); delay = ofxAudioUnit(kAudioUnitType_Effect, kAudioUnitSubType_Delay); distortion = ofxAudioUnit(kAudioUnitType_Effect, kAudioUnitSubType_Distortion); // -BrainWave01-Both.wav -- do not use // -BrainWave02-Med.wav - this sound can't be loud // -BrainWave03-Attn.wav - to use with delay. conflicts with 07/09 // -BrainWave04-Both.wav - this can be relatively constant // -BrainWave05-Attn.wav - not sure this one works. DNU for now // -BrainWave06-Attn.wav - sort of conflicts with sound 04. BETTER AT LOWER ATT // -BrainWave07-Attn.wav - sort of conflicts with sound 03. delay can be used on this as well BETTER AT HIGHER ATT // -BrainWave08-Med.wav - sort of conflics with 15, 12, 13 // -BrainWave09-Attn.wav - sort of conflicts with 07, 03. // -BrainWave10-Attn.wav - MID ATTN // -BrainWave11-Med.wav - very calm moments // -BrainWave12-Med.wav - sort of conflicts with 15 // -BrainWave13-Med.wav - sort of conflics with 12 // -BrainWave14-Both.wav - sort of conflicts with 9. HIGH MED // -BrainWave15-Med.wav - conflicts with 12, 13, 8 // -BRainWave16-Attn.wav - MID ATTN // BrainWave17-Attn.wav - this sound can't play with many other sounds (blink?) attention_sounds.push_back("5minsilence.wav"); attention_sounds.push_back("sounds2/BrainWave03-Attn.wav"); attention_sounds.push_back("sounds2/BrainWave06-Attn.wav"); // DON'T USE WITH 4 attention_sounds.push_back("5minsilence.wav"); attention_sounds.push_back("sounds2/BRainWave16-Attn.wav"); attention_sounds.push_back("sounds2/BrainWave07-Attn.wav"); attention_sounds.push_back("sounds2/BrainWave10-Attn.wav"); attention_sounds.push_back("5minsilence.wav"); attention_sounds.push_back("sounds2/BrainWave09-Attn.wav"); attention_sounds.push_back("sounds2/BrainWave17-Attn.wav"); attention_sounds.push_back("5minsilence.wav"); meditation_sounds.push_back("sounds2/5minsilence.wav"); meditation_sounds.push_back("sounds2/BrainWave15-Med.wav"); meditation_sounds.push_back("sounds2/BrainWave11-Med.wav"); meditation_sounds.push_back("sounds2/5minsilence.wav"); //BrainWave08-Med.wav"); // lower level meditation_sounds.push_back("sounds2/BrainWave04-Both.wav"); meditation_sounds.push_back("sounds2/BrainWave12-Med.wav"); meditation_sounds.push_back("sounds2/BrainWave14-Both.wav"); meditation_sounds.push_back("sounds2/BrainWave13-Med.wav"); meditation_sounds.push_back("sounds2/5minsilence.wav"); attentionVolume = new float[ attention_sounds.size() ]; attentionLoops = new ofxAudioUnitFilePlayer[ attention_sounds.size() ]; attentionMixer.setInputBusCount(attention_sounds.size()); attentionMixer.connectTo(masterMixer, 0); for(int i=0; i<attention_sounds.size(); i++) { string fname = attention_sounds[i]; attentionLoops[i].setFile(ofFilePath::getAbsolutePath(fname)); attentionLoops[i].connectTo(attentionMixer, i); attentionLoops[i].loop(); attentionMixer.setInputVolume(0, i); } meditationVolume = new float[ meditation_sounds.size() ]; meditationLoops = new ofxAudioUnitFilePlayer[ meditation_sounds.size() ]; meditationMixer.setInputBusCount(meditation_sounds.size()); meditationMixer.connectTo(masterMixer, 1); for(int i=0; i<meditation_sounds.size(); i++) { string fname = meditation_sounds[i]; meditationLoops[i].setFile(ofFilePath::getAbsolutePath(fname)); meditationLoops[i].connectTo(meditationMixer, i); meditationLoops[i].loop(); meditationMixer.setInputVolume(0, i); } reverb.printParameterList(); varispeed.printParameterList(); lowpass.printParameterList(); delay.printParameterList(); distortion.printParameterList(); masterMixer // .connectTo(reverb) // .connectTo(lowpass) // .connectTo(delay) // .connectTo(distortion) // .connectTo(varispeed) .connectTo(output); output.start(); debugMessage << "Press 1 for reverb settings\n" << "Press 2 for varispeed settings\n" << "Press 3 for lowpass settings\n" << "Press 4 for delay settings\n" << "Press 5 for distortion settings\n"; AudioUnitSetParameter(reverb.getUnit(), kReverbParam_DryWetMix, kAudioUnitScope_Global, 0, 0, 0); AudioUnitSetParameter(varispeed.getUnit(), kVarispeedParam_PlaybackRate, kAudioUnitScope_Global, 0, 1, 0); AudioUnitSetParameter(lowpass.getUnit(), kLowPassParam_CutoffFrequency, kAudioUnitScope_Global, 0, 6900, 0); AudioUnitSetParameter(delay.getUnit(), kDelayParam_WetDryMix, kAudioUnitScope_Global, 0, 0, 0); AudioUnitSetParameter(distortion.getUnit(), kDistortionParam_FinalMix, kAudioUnitScope_Global, 0, 0, 0); // // Set up recorder // sampleRate = 44100; channels = 2; vidRecorder.setVideoCodec("mpeg4"); vidRecorder.setVideoBitrate("800k"); vidRecorder.setAudioCodec("mp3"); vidRecorder.setAudioBitrate("192k"); // // SoundStream setup // soundStream.listDevices(); //soundStream.setDeviceID(5); soundStream.setup(this, 0, channels, sampleRate, 256, 4); ofAddListener(httpUtils.newResponseEvent,this,&testApp::newResponse); httpUtils.start(); setupUI(); }
void Pointer::initPatterns() { patterns.clear(); genMotorPattern(); return; bool en_CircleRandom = true; bool en_TriangleRot = true; bool en_LineRot = true; bool en_circleTriangle = false; bool en_grid = false; bool en_grid_45 = true; if (en_grid_45) { beginPattern(); for (int i = 0;i < 20;i++) { if (ofRandomuf() < 0.5) { ofVec2f ax = ofVec2f(ofRandomf(), -1.0); addVertex(ax.x, ax.y, true); addVertex(ax.y, ax.x, false); }else{ ofVec2f ax = ofVec2f(1.0, ofRandomf()); addVertex(ax.x, ax.y, true); addVertex(ax.y, ax.x, false); } } endPattern(); } //grid if (en_grid) { beginPattern(); for (int i = 0;i < 20;i++) { if (ofRandomuf() < 0.5) { float x = ofRandomf(); addVertex(x, -1.0, true); addVertex(x, 1.0, false); }else{ float y = ofRandomf(); addVertex(-1.0, y, true); addVertex( 1.0, y, false); } } endPattern(); } //circleTriangle if (en_circleTriangle) { beginPattern(); for (int i = 0;i < 10;i++) { float deg = ofRandom(-PI * 2); addVertex(-1.0, 0.0, true); addVertex( 1.0, 0.0, true); addVertex(cos(deg), sin(deg), true); addVertex(-1.0, 0.0, true); } endPattern(); } //Circle if (en_CircleRandom){ beginPattern(); float seed = ofRandomf(); for (int i = 0;i <= 100;i++) { float deg = powf(2.0, ofNoise(i * 2.0 * PI + seed * 3941.341)) * 10.0; addVertex(cos(deg), sin(deg), true); } endPattern(); } //TriangleRot if (en_TriangleRot){ beginPattern(); float deg[3], rad[3]; for (int i = 0;i < 3;i++) { deg[i] = ofRandomf() + i * 2; rad[i] = ofRandom(0.5,1.0); } for (int i = 0;i < 15;i++) { for (int j = 0;j < 3;j++) { addVertex(cos(deg[j]) * rad[j], sin(deg[j]) * rad[j], true); } addVertex(cos(deg[0]) * rad[0], sin(deg[0]) * rad[0], false); for (int j = 0;j < 3;j++) deg[j] += 0.05 * (i + 1); } endPattern(); } //LineRot if (en_LineRot){ beginPattern(); float deg[3], rad[3]; for (int i = 0;i < 2;i++) { deg[i] = ofRandomf() + i * 2; rad[i] = ofRandom(0.5,1.0); } for (int i = 0;i < 30;i++) { addVertex(cos(deg[0]) * rad[0], sin(deg[0]) * rad[0], true); addVertex(cos(deg[1]) * rad[1], sin(deg[1]) * rad[1], false); for (int j = 0;j < 2;j++) deg[j] += 0.1 + (i * 0.01); } endPattern(); } }
GLfloat Boid::var(GLint _step){ return (GLfloat)(ofRandomf() * _step); }
//http://www.cs.cmu.edu/~mws/rpos.html ofVec3f ofRandomPointOnUnitSphere(){ float phi = 2*PI*ofRandomuf(); float theta = acos(ofRandomf()); return ofVec3f(sin(theta)*cos(phi),sin(theta)*sin(phi),cos(theta)); }
void Ray::randomiseVectors(float amplitude) { infinite = true; s = ofVec3f(ofRandomf(), ofRandomf(), ofRandomf()) * amplitude; t = ofVec3f(ofRandomf(), ofRandomf(), ofRandomf()) * amplitude; }
void Maho::draw( float x, float y){ if (!drawing) return; //phase0 // if (lastMaho) { // float lastMahoLineNum = line1Num *2; // int lastMahoBlobPointNum = blobPointNum * 3; // float lastMahoSparkRangeMax = 180.0f; // float lastMahoLine2MinLength = 180.0f;//2.0f - 300.0f // float lastMahoLine2MaxLength = 500.0f; // float mahoLine2MaxLength = 110.5f;// // ofPushStyle(); // ofPushMatrix(); // ofTranslate(x, y); // // // for (int i = 0; i < lines2.size(); i++) { // lines2[i].draw(); // } // ofFill(); // b.draw(); // b2.draw(); // for (int i = 0; i < bunshis.size(); i++) { // bunshis[i].draw(); // } // ofNoFill(); // ofSetLineWidth(4.0f); // for (int i = 0; i < lines.size(); i++) { // ofPushMatrix(); // ofRotateZ(lines[i].angle); // lines[i].draw(); // ofPopMatrix(); // } // ofPopMatrix(); // ofPopStyle(); // ofPushStyle(); // lastparticles.draw(); // ofPopStyle(); // // return; // } if (mahoPhase == 0){ ofPushStyle(); ofPushMatrix(); ofTranslate(x, y); for (int i = 0; i < lines2.size(); i++) { lines2[i].draw(); } ofFill(); b.draw(); b2.draw(); for (int i = 0; i < bunshis.size(); i++) { bunshis[i].draw(); } ofNoFill(); ofSetLineWidth(4.0f); for (int i = 0; i < lines.size(); i++) { ofPushMatrix(); ofRotateZ(lines[i].angle); lines[i].draw(); ofPopMatrix(); } ofPopMatrix(); ofPopStyle(); ofPushStyle(); lastparticles.draw(); ofPopStyle(); } else if (mahoPhase == 1){ if ( currentMahoTime < keenTime) {//Keen ofPushStyle(); ofPushMatrix(); ofNoFill(); ofSetColor(mainPink); ofSetLineWidth(keenWidth); ofPoint v = mahoPos[1] - mahoPos[0]; ofLine(mahoPos[0], mahoPos[1]); ofPopMatrix(); ofPopStyle(); } else if ( currentMahoTime > keenTime && currentMahoTime < mahoPhase2Time[0]) {//本棚がグニャグニャ hondana //fade if (mahoIndex == 1) { //gunya1 ofPushStyle(); ofPushMatrix(); ofFill(); ofSetColor(color); ofBeginShape(); for (int i = 0; i < HONDANA_INDEX_NUM; i++) { ofVertex(hondanaPoints[i]); hondanaPoints[i] += ofRandomf() * hondanaNoiseAmt; } ofEndShape(); ofBeginShape(); for (int i = HONDANA_INDEX_NUM - 1; i >= 0; i--) { ofVertex(hondanaPoints[i]); hondanaPoints[i] += ofSignedNoise(ofGetElapsedTimeMillis()) * hondanaNoiseAmt; } ofEndShape(); ofPopMatrix(); ofPopStyle(); } } //sera if (currentMahoTime > keenTime && mahoIndex == 2) {//sera if (!seraDid) { if (choicedXtion == 0) { bDrawSeraBlob = true; } else { for (int i = 1; i <= XTION_NUM; i++) { if (choicedXtion - 1 == i){ bDraw[i] = true; }else bDraw[i] = false; } bOpenCv = true; } seraDid = true; } if (bSera) { if (bDrawSeraBlob){ ofPushStyle(); ofFill(); if (toggleCvFadeOut) { if (openCvDrawColor.r > 2)openCvDrawColor.r -= 3; if (openCvDrawColor.g > 2)openCvDrawColor.g -= 3; if (openCvDrawColor.b > 2)openCvDrawColor.b -= 3; if (openCvDrawColor.r < 3) { bDrawSeraBlob = false; } } ofSetColor(openCvDrawColor); // ofBeginShape(); // for (int i = 0; i < 6; i++) { // ofVertex(seraBlob[i].x + ofRandomf() * 10.0f, seraBlob[i].y + ofRandomf() * 10.0f); // } // ofEndShape(); // ofBeginShape(); // for (int i = 0; i < 6; i++) { // ofVertex(seraBlob[i].x + ofRandomf() * 10.0f, seraBlob[i].y + ofRandomf() * 10.0f); // } // ofEndShape(); // ofPoint centerOfSera(0.0f, 0.0f); // for (int i = 0; i < 6; i++) { // centerOfSera.x += seraBlob[i].x; // centerOfSera.y += seraBlob[i].y; // } // centerOfSera /= 6.0f; // for (int i = 0; i < 100; i++) { // float length = ofRandom(0.0f, 100.0f); // float angle = ofRandom(0.0f, 360.0f); // float xx = length * cos(angle); // float yy = length * sin(angle); // if (sin(angle) < 0) yy *= 0.5f; // // ofRect(2.0f + centerOfSera.x + xx, 2.0f + centerOfSera.y + yy, 8.0f, 8.0f); // } for (int i = 0; i < 100; i++) { float length = ofRandom(0.0f, 100.0f); float angle = ofRandom(0.0f, 360.0f); float xx = length * cos(angle) * 0.4; float yy = length * sin(angle); if (sin(angle) < 0) yy *= 0.5f; ofRect(4.0f + seraHeadPos[0].x + xx, 4.0f + seraHeadPos[0].y + yy, 8.0f, 8.0f); } for (int i = 0; i < 100; i++) { float length = ofRandom(0.0f, 100.0f); float angle = ofRandom(0.0f, 360.0f); float xx = length * cos(angle) * 0.4; float yy = length * sin(angle); if (sin(angle) < 0) yy *= 0.5f; ofCircle(seraHeadPos[0].x + xx, seraHeadPos[0].y + yy, 8.0f); } // float noiseLineLength = 30.0f; // ofNoFill(); // ofSetColor(openCvDrawColor); // ofSetLineWidth(2.0f); // ofEnableBlendMode(OF_BLENDMODE_SUBTRACT); // for (int i = 0; i < 50; i++) { // ofLine(centerOfSera.x - noiseLineLength /2.0f, centerOfSera.y + ofNoise(ofGetElapsedTimef() * 100 * i)*noiseLineLength, centerOfSera.x + noiseLineLength /2.0f, centerOfSera.y + ofNoise(ofGetElapsedTimef() * 100 * i)*noiseLineLength); // } // ofDisableBlendMode(); } sera.draw(); } else { sera.toggleGo(); bSera = true; } } //harada door if (currentMahoTime > keenTime && mahoIndex == 3) { //gunya1 ofPushStyle(); ofFill(); ofSetColor(color); ofBeginShape(); for (int i = 0; i < 6; i++) { ofVertex(doorPos[i]); } ofEndShape(); ofBeginShape(); for (int i = 0; i < 6; i++) { ofVertex(doorPosDamy[i]); doorPosDamy[i].x += ofRandomf() * doorGunyaAmt; } ofEndShape(); ofBeginShape(); for (int i = 4 - 1; i >= 0; i--) { ofVertex(doorPosDamy[i]); doorPosDamy[i].x += ofRandomf() * doorGunyaAmt; } ofEndShape(); ofPopStyle(); } //harada fire if (currentMahoTime > keenTime && mahoIndex == 6) { bHaradaFire = true; haradaFire.setup(); haradaFire.toggleGo(); mahoIndex = 0; } //sushi if (currentMahoTime > keenTime && mahoIndex == 7) { //rokka- ofPushStyle(); ofPushMatrix(); ofFill(); ofSetColor(color); ofBeginShape(); for (int i = 0; i < 4; i++) { ofVertex(rokkaPos[i]); } ofEndShape(); ofBeginShape(); for (int i = 0; i < 4; i++) { ofVertex(rokkaPosDamy[i].x + ofRandomf() * hondanaNoiseAmt, rokkaPosDamy[i].y + ofRandomf() * hondanaNoiseAmt); } ofEndShape(); ofBeginShape(); for (int i = 3; i >= 0; i--) { ofVertex(rokkaPosDamy[i].x + ofSignedNoise(ofGetElapsedTimeMillis()) * hondanaNoiseAmt, rokkaPosDamy[i].y + ofSignedNoise(ofGetElapsedTimeMillis()) * hondanaNoiseAmt); } ofEndShape(); ofPopMatrix(); ofPopStyle(); } //gomory if (currentMahoTime > keenTime && mahoIndex == 8) { ofPushStyle(); ofPushMatrix(); ofFill(); ofSetColor(color); ofBeginShape(); for (int i = 0; i < 6; i++) { ofVertex(doorPos[i]); } ofEndShape(); ofBeginShape(); for (int i = 0; i < 6; i++) { ofVertex(doorPosDamy[i]); doorPosDamy[i].x += ofRandomf() * doorGunyaAmt; } ofEndShape(); ofBeginShape(); for (int i = 4 - 1; i >= 0; i--) { ofVertex(doorPosDamy[i]); doorPosDamy[i].x += ofRandomf() * doorGunyaAmt; } ofEndShape(); ofPopMatrix(); ofPopStyle(); } } }
//-------------------------------------------------------------- void testApp::setup(){ ofSetDataPathRoot("../Resources/"); ofDisableArbTex(); ofEnableAlphaBlending(); ofEnableSmoothing(); ofBackground(255, 255, 255); // defaultShader.setup("default"); // showDepthShader.setup("showdepth"); ssaoShader.load("ssao"); dofShader.load("dof"); depthFBO.setup(ofGetWidth(), ofGetHeight()); colorFBO.setup(ofGetWidth(), ofGetHeight()); ssaoFBO.setup(ofGetWidth(), ofGetHeight()); ofSetSphereResolution(100); numObj = 200; for (int i = 0; i < numObj; i++) { float x = ofRandom(ofGetWidth()/2-200, ofGetWidth()/2+200); float y = ofRandom(ofGetHeight()/2-200, ofGetHeight()/2+200); float z = ofRandom(-100, 500); ofVec3f pos = ofVec3f(x,y,z); float r = ofRandom(0.0, 255.0); float g = ofRandom(0.0, 255.0); float b = ofRandom(0.0, 255.0); float a = ofRandom(200.0, 255.0); ofVec4f col = ofVec4f(r,g,b,a); int size = ofRandom(10, 50); ofQuaternion qua = ofQuaternion(ofRandomf(), ofRandomf(), ofRandomf(), ofRandomf()); int typ = ofRandom(1, 3); objPos.push_back(pos); objRot.push_back(qua); objCol.push_back(col); objSize.push_back(size); objType.push_back(typ); } //.setNewColumn(true); gui.addTitle("SSAO Setting"); gui.addSlider("camerarangex", camerarangex, 0, 10000); gui.addSlider("camerarangey", camerarangey, 0, 10000); gui.addSlider("aoCap", aoCap, 0.0, 2.0); gui.addSlider("aoMultiplier", aoMultiplier, 0.0, 20000.0); gui.addSlider("depthTolerance", depthTolerance, 0.000, 0.002); gui.addSlider("aorange", aorange, 0.0, 2.0); gui.addSlider("readDepthVal", readDepthVal, 0.0, 20.0); gui.addTitle("DOF Setting").setNewColumn(true); gui.addSlider("focus", focus, 0.0, 2.0); gui.addSlider("aspectratiox", aspectratiox, 0.0, ofGetWidth()); gui.addSlider("aspectratioy", aspectratioy, 0.0, ofGetHeight()); gui.addSlider("blurclamp", blurclamp, 0.0, 1.0); gui.addSlider("bias", bias, 0.0, 1.0); gui.loadFromXML(); gui.show(); camerarangex = 6113.28; camerarangey = 4121.09; aoCap = 1.8795; aoMultiplier = 1523.5625; depthTolerance = 0.0001130; aorange = 0.285156; readDepthVal = 2.0; focus = 0.808594; aspectratiox = ofGetWidth(); aspectratioy = ofGetHeight(); blurclamp = 0.0253910; bias = 0.041016; }
inline ofVec3f ofRandVec3f(){ return ofVec3f(ofRandomf(),ofRandomf(),ofRandomf()).normalize().scale(ofRandomf()); }
//-------------------------------------------------------------- void PartyCLApp::randomizeBodies() { switch (activeConfig) { default: case NBODY_CONFIG_RANDOM: { float scalePos = clusterScale * MAX(1.0f, numBodies / (1024.f)); float scaleVel = velocityScale * scalePos; ofVec3f pos; ofVec3f vel; for (int i = 0; i < numBodies; ++i) { pos.x = ofRandomf(); pos.y = ofRandomf(); pos.z = ofRandomf(); if (pos.lengthSquared() > 1) continue; vel.x = ofRandomf(); vel.y = ofRandomf(); vel.z = ofRandomf(); if (vel.lengthSquared() > 1) continue; hPos[i].x = pos.x * scalePos; hPos[i].y = pos.y * scalePos; hPos[i].z = pos.z * scalePos; hPos[i].w = 1.0f; // mass hVel[i].x = vel.x * scaleVel; // pos.x hVel[i].y = vel.y * scaleVel; // pos.x hVel[i].z = vel.z * scaleVel; // pos.x hVel[i].w = 1.0f; // inverse mass } } break; case NBODY_CONFIG_SHELL: { float scalePos = clusterScale; float scaleVel = scalePos * velocityScale; float inner = 2.5f * scalePos; float outer = 4.0f * scalePos; ofVec3f pos; ofVec3f vel; ofVec3f axis; for (int i = 0; i < numBodies; ++i) { pos.x = ofRandomf(); pos.y = ofRandomf(); pos.z = ofRandomf(); if (pos.lengthSquared() > 1) continue; hPos[i].x = pos.x * ofRandom(inner, outer); hPos[i].y = pos.y * ofRandom(inner, outer); hPos[i].z = pos.z * ofRandom(inner, outer); hPos[i].w = 1.0f; // mass axis.set(0.0f, 0.0f, 1.0f); if (1.0f - pos.dot(axis) < 1e-6) { axis.x = pos.y; axis.y = pos.x; axis.normalize(); } vel.set(hPos[i].x, hPos[i].y, hPos[i].z); vel.cross(axis); hVel[i].x = vel.x * scaleVel; hVel[i].y = vel.y * scaleVel; hVel[i].z = vel.z * scaleVel; hVel[i].x = 1.0f; // inverse mass } } break; case NBODY_CONFIG_EXPAND: { float scalePos = clusterScale * MAX(1.0f, numBodies / (1024.0f)); float scaleVel = scalePos * velocityScale; ofVec3f point; for (int i = 0; i < numBodies; ++i) { point.x = ofRandomf(); point.y = ofRandomf(); point.z = ofRandomf(); if (point.lengthSquared() > 1) continue; hPos[i].x = point.x * scalePos; hPos[i].y = point.y * scalePos; hPos[i].z = point.z * scalePos; hPos[i].w = 1.0f; // mass hVel[i].x = point.x * scaleVel; hVel[i].y = point.y * scaleVel; hVel[i].z = point.z * scaleVel; hVel[i].w = 1.0f; // inverse mass } } break; } // if (color) { // int v = 0; // for(int i=0; i < numBodies; i++) { // //const int scale = 16; // color[v++] = rand() / (float) RAND_MAX; // color[v++] = rand() / (float) RAND_MAX; // color[v++] = rand() / (float) RAND_MAX; // color[v++] = 1.0f; // } // } }
void testApp::draw(){ ofSetMinMagFilters(GL_NEAREST, GL_NEAREST); ofBackground(0); ofSetColor(255); if(playerCount == 0) { float rescale = ofMap(sin(ofGetElapsedTimef() * 5), -1, 1, .8, 1.2); ofSetColor(magenta); drawTitle("WAITING FOR PLAYER", rescale); } else if(playerCount == 1) { ofVec2f offset(ofRandomf(), ofRandomf()); offset *= 5; ofSetColor(cyan); ofPushMatrix(); ofTranslate(offset.x, offset.y); drawTitle("AWAITING CHALLENGER"); ofPopMatrix(); } else if(playerCount == 2) { for(int i = 0; i < projectiles.size(); i++) { projectiles[i].draw(); } ofSetColor(255); for(int i = 0; i < players.size(); i++) { if(players[i].life > 0) { ofPushMatrix(); ofTranslate((int) players[i].position.x, (int) players[i].position.y); ofScale(2, 2); if(players[i].position.x > ofGetWidth() / 2) { ofScale(-1, 1); } if(i == 0) { maskedDraw(ryu); } else { maskedDraw(ken); } ofPopMatrix(); } } } int winner = 0; if(playerCount == 2) { bool done = false; for(int i = 0; i < players.size(); i++) { drawLife(i); if(players[i].life <= 0) { done = true; } else { winner = i; } } if(done && !lastDone) { youWin.play(); } lastDone = done; } if(playerCount == 2 && lastDone) { bool flash = sin(2. * ofGetElapsedTimef() * TWO_PI) > 0; ofSetColor(flash ? yellow : 0); drawTitle("PLAYER " + ofToString(winner + 1) + " WINS"); } if(panel.getValueB("debug")) { ofSetColor(255); for(int i = 0; i < players.size(); i++) { ofCircle(players[i].position, 32); } } }
void electromagnetica::update(float d1){ hands.update(); //actualiza la sombra de las manos int singleWaveId= wavesm.getSingleWaveId(); int singleWaveIndex=-1; if(singleWaveId!=-1){ for (int i=0; i< hands.objectsCol.size(); i++){ if(hands.objectsCol[i]->cursor_id== singleWaveId){ singleWaveIndex=i; } } } //tuioClientEm.getMessage(); wavesm.update(); //actualiza la onda matematica if(wavesm.howManyWaves()==0){ //ruido puro int tmpIndex=0; for(int i=0; i< meshParticles.getVertices().size(); i++){ //ofSeedRandom(); if(ofRandomf()>0.3) meshParticles.getColors()[i].set(ofRandom(0,200)); else meshParticles.getColors()[i].set(0); ofPoint p= ofPoint(particles[i]._x,particles[i]._y); //si no hay ninguna onda, sólo ruido, las partículas de alrededor de la mano son las que forman la onda. if(singleWaveIndex!=-1 && p.distanceSquared( ofPoint( hands.objectsCol[singleWaveIndex]->x, hands.objectsCol[singleWaveIndex]->y ) ) <10000 ){ ofPoint p1=((noiseShadow *)hands.objectsCol[singleWaveIndex])->getDstPoint(particles[i]._x, particles[i]._y,tmpIndex); particles[i].steer( p1, true, 7, 10); tmpIndex++; meshParticles.getColors()[i].set(ofColor(0,160,176,255)); }else{ particles[i].steer( p, true, 7, 10); } particles[i].update(); meshParticles.getVertices()[i].set(particles[i].position); } } else if(wavesm.howManyWaves()>=1){ // Dependiendo de numero de ondas mas o menos particulas irán a cada onda. //ondas entre 2 puntos // oculto el resto /* int puntos_ondas=0; int ondasAct=wavesm.howManyWaves(); for(int i=0; i<wavesm.howManyWaves(); i++){ puntos_ondas+=wavesm.waveslist[i].AbsPoints.size(); }*/ int rows=W_WIDTH/options_sampling; //check if there is any single cursor where we need to draw the magnetic field ofPoint positionCursor; if(singleWaveIndex!=-1){ positionCursor=ofPoint( hands.objectsCol[singleWaveIndex]->x, hands.objectsCol[singleWaveIndex]->y ); } else positionCursor=ofPoint(0,0); // Aquí se mandan las particulas que son parte de dibujar el campo Magnetico for(int i=0; i< meshAux.getVertices().size(); i++){ if(singleWaveIndex!=-1){ //ofPoint p= ofPoint(particlesAux[i]._x,particlesAux[i]._y); ofPoint p1=((noiseShadow *)hands.objectsCol[singleWaveIndex])->getDstPoint2(particlesAux[i]._x, particlesAux[i]._y,i); particlesAux[i].steer( p1, true, 7,20); if(meshAux.getColors()[i].a<=1) meshAux.getColors()[i].a+=0.5; particlesAux[i].update(); meshAux.getVertices()[i].set(particlesAux[i].position); } else{ // si ya ha retirado la mano le quitamos opacidad hasta que desaparezca ofPoint p= ofPoint(particlesAux[i]._x,particlesAux[i]._y); particlesAux[i].steer( p, true, 7,20); particlesAux[i].update(); meshAux.getVertices()[i].set(particlesAux[i].position); if(meshAux.getColors()[i].a>=0) meshAux.getColors()[i].a-=0.05; } } // dibujado de las ondas normales for(int i=0; i< meshParticles.getVertices().size(); i++){ int num_onda=i % MAX_ONDAS; //num_onda es la onda a la que se va a asignar trIndices index= wavesm.num_onda(num_onda,i); //Aquí se asigna ofPoint p= wavesm.waveslist[index.n_wave].AbsPoints[index.new_index]; particles[i].steer(p , true, 15, 20); int len=wavesm.waveslist[index.n_wave].npuntos; ofColor color1=ofColor::fromHsb( ofMap(len, 0, W_WIDTH, 0,170),255,255) ; color1.a=230; meshParticles.getColors()[i].set(color1); particles[i].update(); meshParticles.getVertices()[i].set(particles[i].position); } } /* for(int i =0; i<hands.objectsCol.size(); i++){ int mx= hands.objectsCol[i]->x; int my= hands.objectsCol[i]->y; ofPoint p= ofPoint(mx,my); for(int j=1; j<100; j++){ int jj=(int) (numParticles/j); particles[jj].steer(p , true, 5, 10); particles[jj].update(); meshParticles.getColors()[jj].set(colours[(int)( hands.objectsCol[i]->cursor_id % colours.size()-1) ]); meshParticles.getVertices()[jj].set(particles[jj].position); } }*/ /*OSC SENDING UPDATES */ if(ofGetFrameNum()%2==0){ for(int i=0; i<wavesm.howManyWaves(); i++){ int waveLength=wavesm.waveslist[i].getLength(); if(wavesm.waveslist[i].waveID!=-1){ cheapComm::getInstance()->sendAudio2("/audio/electromagnetism/wave_length",wavesm.waveslist[i].waveID, ofMap(waveLength,0,W_WIDTH,1,0)); cheapComm::getInstance()->sendSync2("/sync/electromagnetism/wave_length", wavesm.waveslist[i].waveID, waveLength); } #ifdef OSCDEBUG cout << wavesm.waveslist[i].waveID << " "; #endif } cheapComm::getInstance()->sendSync1("/sync/electromagnetism/number_waves",wavesm.howManyWaves()); } }
void chispa::init(int iX, int iY) { x = iX + ofRandom(-5, 5); y = iY + ofRandom(0, 3); for (s = 0; s == 0; s = 5 * ofRandomf()); v = MAX_VIDA; }