//-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ //sets the origin to the mouse position when clicked xOrig = mouseX; yOrig = mouseY; float radius = 300; float angle = ofGetElapsedTimeMillis()*3.5; //sets the position of the particles to appear in a circle x = xOrig + radius * cos(angle * 1.3); y = yOrig + radius * -sin(angle * 2.4); setRandomColor(); float speed = 3; //make some particles!!! for (int i = 0; i <100; i++){ particle myParticle; float angle = ofGetElapsedTimef() * (i * 10); float velX = speed * sin(i); float velY = speed * -cos(i); myParticle.setInitialCondition(x, y, velX, velY); myParticle.damping = ofRandom(0.01, 0.05); myParticle.setInitialColor(randR, randG, randB); particles.push_back(myParticle); } }
/** * CallBack creating markers based on received toaster_msgs and adding then to area_list * There is two differents types of area markers so this function manages both circle and polygon types * @param msg reference to receive toaster_msgs::AreaList * @return void */ void chatterCallbackAreaList(const toaster_msgs::AreaList::ConstPtr& msg) { area_list.markers.clear(); for (int i = 0; i < msg->areaList.size(); i++) { if (msg->areaList[i].isCircle == true) //circle case { visualization_msgs::Marker m = defineCircle(msg->areaList[i].center, msg->areaList[i].ray, msg->areaList[i].name); m = setRandomColor(m); visualization_msgs::Marker mn = defineName(m); mn = setSize(mn, 0.0, 0.0, 0.4); mn = setPosition(mn, mn.pose.position.x, mn.pose.position.y, 1); area_list.markers.push_back(m); area_list.markers.push_back(mn); ROS_DEBUG("circle %d", m.id); } else // polygon case { visualization_msgs::Marker m = definePolygon(msg->areaList[i].poly, 0.2, msg->areaList[i].name); m = setRandomColor(m); visualization_msgs::Marker mn = defineName(m); mn = setSize(mn, 0.0, 0.0, 0.4); int posx = 0; int posy = 0; for (int i = 0; i < m.points.size(); i++) { posx = posx + m.points[i].x; posy = posy + m.points[i].y; } mn = setPosition(mn, posx / m.points.size(), posy / m.points.size(), 1); area_list.markers.push_back(m); area_list.markers.push_back(mn); ROS_DEBUG("poly %d", m.id); } } }
CDotOverlord::CDotOverlord(void) { maxDots = MAX_DOTS; CFlockingDot * tempDot; for(int i = 0; i < maxDots; i++) { tempDot = new CFlockingDot(); setRandomColor((CFlockingDot&)*tempDot); tempDot->position = getRandomPosition(2000,1400); tempDot->velocity.x = getRandom(1,2); tempDot->velocity.y = getRandom(1,2); if((getRandom(0, 3) % 3) == 0) { tempDot->velocity.x*=-1; } if((getRandom(0, 3) % 3) == 0) { tempDot->velocity.y*=-1; } tempDot->maxSpeed = getRandom(3, 12); tempDot->maxForce = getRandom(1, 3); //tempDot->drawTrails = true; dots.push_back(tempDot); if((getRandom(0, 5) % 5) == 0) { int rdot = getRandom(0, dots.size()-1); tempDot->setSeek(dots[rdot]); tempDot->drawTrails = true; setRandomColor((CFlockingDot&)*tempDot); } tempDot->wander(); tempDot->wander(); cout << tempDot->position.toString() << endl; } }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetVerticalSync(true); ofSetFrameRate(60); ofBackground(50, 50, 50); ofEnableAlphaBlending(); //set a random position and color for fireworks //setRandomPos(); setRandomColor(); }
/* Like randomtriangle() but vertex/radius can't be more than 'delta' pixel * away from initial random coordinates. */ void randomsmalltriangle(struct triangle *r, int width, int height, int delta) { int x = random()%width; int y = random()%height; r->type = selectShapeType(); if (r->type == TYPE_TRIANGLE) { r->u.t.x1 = x + randbetween(-delta,delta); r->u.t.y1 = y + randbetween(-delta,delta); r->u.t.x2 = x + randbetween(-delta,delta); r->u.t.y2 = y + randbetween(-delta,delta); r->u.t.x3 = x + randbetween(-delta,delta); r->u.t.y3 = y + randbetween(-delta,delta); } else { r->u.c.x1 = x; r->u.c.y1 = y; r->u.c.radius = randbetween(1,delta); } setRandomColor(r); normalize(r,width,height); }
//-------------------------------------------------------------- void ofApp::keyPressed(int key){ if (key == ' '){ setRandomColor(); particles.clear(); } }
void ChangingColor::timerEvent(QTimerEvent *event) { Q_UNUSED(event); setRandomColor(); }
/* Create a random triangle or circle. */ void randomtriangle(struct triangle *r, int width, int height) { r->type = selectShapeType(); setRandomVertexes(r,width,height); setRandomColor(r); normalize(r,width,height); }
/* Handler for window-repaint event. Call back when the window first appears and whenever the window needs to be re-painted. */ void display() { glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer with current clearing color // Define shapes enclosed within a pair of glBegin and glEnd glBegin(GL_QUADS); glColor3f(0.7f, 0.7f, 0.7f); glVertex2f(0.0f, 1.0f); glColor3f(0.5f, 0.5f, 0.5f); glVertex2f(0.0f, 0.0f); glColor3f(0.7f, 0.7f, 0.7f); glVertex2f(1.0f, 0.0f); glColor3f(0.5f, 0.5f, 0.5f); glVertex2f(1.0f, 1.0f); glEnd(); for(float i = 0.0; i < 1.0; i += 0.05){ glBegin(GL_LINES); glColor3f(0.3f, 0.3f, 0.3f); glVertex2f(0.0f, i); glVertex2f(1.0f, i); glEnd(); } for(float i = 0.0; i < 1.0; i += 0.05){ glBegin(GL_LINES); glColor3f(0.3f, 0.3f, 0.3f); glVertex2f(i, 0.0f); glVertex2f(i, 1.0f); glEnd(); } /*****************************************************************************/ /* AFISARE TRIUNGHIURI */ glBegin(GL_TRIANGLES); for(unsigned int i = 0; i < Tris.size(); i ++){ setRandomColor(); glVertex2f(Tris.at(i).at(0).getX(), Tris.at(i).at(0).getY()); glVertex2f(Tris.at(i).at(1).getX(), Tris.at(i).at(1).getY()); glVertex2f(Tris.at(i).at(2).getX(), Tris.at(i).at(2).getY()); } glEnd(); /*****************************************************************************/ /* AFISARE LINII concav concav = blue convex convex = red concav convex = yellow */ glEnable(GL_LINE_SMOOTH); glColor3dv(black); //glLineWidth(1.0); glBegin(GL_LINE_STRIP); for (unsigned int i = 0; i < Points.size(); i++){ if (i == (Points.size() - 1)){ if ((getPointType(i) == CONVEX) && (getPointType(0) == CONVEX)){ glColor3dv(red); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(0).getX(), Points.at(0).getY()); } else if ((getPointType(i) == CONCAVE) && (getPointType(0) == CONCAVE)){ glColor3dv(blue); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(0).getX(), Points.at(0).getY()); } else{ glColor3dv(yellow); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(0).getX(), Points.at(0).getY()); } } else{ if ((getPointType(i) == CONVEX) && (getPointType(i + 1) == CONVEX)){ glColor3dv(red); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(i + 1).getX(), Points.at(i + 1).getY()); } else if ((getPointType(i) == CONCAVE) && (getPointType(i + 1) == CONCAVE)){ glColor3dv(blue); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(i + 1).getX(), Points.at(i + 1).getY()); } else{ glColor3dv(yellow); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(i + 1).getX(), Points.at(i + 1).getY()); } } } glEnd(); /*****************************************************************************/ /* AFISARE PUNCTE convex = green concav = black */ glColor3dv(v); glPointSize(4.0); glBegin(GL_POINTS); for (unsigned int i = 0; i < Points.size(); i++){ if (getPointType(i) == CONVEX){ glColor3dv(green); glVertex2d(Points.at(i).getX(), Points.at(i).getY()); } else{ glColor3dv(black); glVertex2d(Points.at(i).getX(), Points.at(i).getY()); } } glEnd(); //glLineWidth(1.0); glFlush(); // Render now }