Bubble::Bubble(const QPointF &position, qreal radius, const QPointF &velocity) : position(position), vel(velocity), radius(radius) { innerColor = randomColor(); outerColor = randomColor(); updateBrush(); }
void WitchLightshow::scrambleColors() { for ( byte s = 0; s < NUM_STRIPS; s++) { for (byte b = 0; b < NUM_BLOCKS; b++) { RGBB color = randomColor(); while ( _blocks[s][b].color == color ) { color = randomColor(); } _blocks[s][b].color = color; } } }
ibool polyDemo(MGLDC *dc) /**************************************************************************** * * Function: polyDemo * Parameters: dc - Device context * * Description: Display a random pattern of polygons on the screen with * random fill styles. * ****************************************************************************/ { int i,maxx,maxy,val; fxpoint_t poly[MAXPTS]; /* Space to hold polygon data */ mainWindow(dc,"MGL_fillPolygon Demonstration"); statusLine("Press any key to continue, ESC to Abort"); maxx = MGL_maxx(); maxy = MGL_maxy(); while (!checkEvent()) { /* Define a random polygon */ for (i = 0; i < MAXPTS; i++) { poly[i].x = MGL_randoml(MGL_TOFIX(maxx)); poly[i].y = MGL_randoml(MGL_TOFIX(maxy)); } MGL_setColor(randomColor()); MGL_setBackColor(randomColor()); if ((val = MGL_random(3)) == 0) { MGL_setPenStyle(MGL_BITMAP_TRANSPARENT); MGL_setPenBitmapPattern(0,&bitpat[MGL_random(NUMPATS)+1]); MGL_usePenBitmapPattern(0); } else if (val == 1) { MGL_setPenStyle(MGL_BITMAP_OPAQUE); MGL_setPenBitmapPattern(0,&bitpat[MGL_random(NUMPATS)+1]); MGL_usePenBitmapPattern(0); } else { MGL_setPenStyle(MGL_BITMAP_SOLID); } MGL_fillPolygonFX(MAXPTS,poly,sizeof(fxpoint_t),0,0); } defaultAttributes(dc); return pause(); }
// Draw polygons, rectangles, and circles (center, radius) on img in // random colors. All vectors have the same element count. // // The reference implies that drawContours() ignores hierarchy when // maxLevel is 0 though. =tbl // static void drawBounds(cv::Mat &img, const std::vector<cv::Vec4i> &hierarchy, std::vector<std::vector<cv::Point> > &polygon, std::vector<cv::Rect> &rectangle, std::vector<cv::Point2f> ¢er, std::vector<float> &radius) { static const cv::Point offset(0, 0); static const int maxLevel = 0; static const int polyThickness = 1; static const int boundThickness = 2 * polyThickness; static const int lineType = 8; static const int shift = 0; const int size = hierarchy.size(); for (int i = 0; i < size; ++i) { const cv::Scalar color = randomColor(); const cv::Rect &r = rectangle[i]; cv::drawContours(img, polygon, i, color, polyThickness, lineType, hierarchy, maxLevel, offset); cv::rectangle(img, r.tl(), r.br(), color, boundThickness, lineType, shift); cv::circle(img, center[i], radius[i], color, boundThickness, lineType, shift); } }
void LetterHunter::resetTextObject(TextObject* textObject) { // Set text position float windowWidth = (float)getwindowWidth(); D2D1_RECT_F textBoundRect = textObject->getBoundaryRect(); float maxRight = windowWidth - (textBoundRect.right -textBoundRect.left); float positionX = randomFloat(0, maxRight); D2D1_POINT_2F position = {positionX, 0}; // Set text velocity float velocityX = 0; float velocityY = randomFloat(0.1f, 0.5f); D2D_VECTOR_2F velocity = textObject->getVelocity(); // Create text string const int strLength = 3; wchar_t* strBuffer = new wchar_t[strLength + 1]; // one more space for '\0' randomString(strBuffer, strLength); // Create text color D2D1_COLOR_F fillColor = randomColor(); textObject->setFillColor(fillColor); // Reset text object textObject->reset(strBuffer, position, velocity, fillColor); SAFE_DELETE(strBuffer); }
PathAreaView::PathAreaView(QGraphicsItem* parent): AreaView{parent}, m_pen{randomColor()}, m_brush{m_pen.color().lighter()}, m_stroker{m_pen} { }
// Draw a circle with center and radius on image in a random color. // static void drawCircle(cv::Mat &image, const cv::Point ¢er, int radius) { static const int thickness = -1; static const int lineKind = 8; static const int shift = 0; const cv::Scalar color = randomColor(); cv::circle(image, center, radius, color, thickness, lineKind, shift); }
box::box(double xx,double yy) { placed=false; dude=false; x=xx; y=yy; z=0; angle=0; c=randomColor(); }
void BorderMattingHandler::watchpixelidx(){ Mat img = _img.clone(); for (int i = 0; i < pixelidx.size(); i++) { Scalar color = randomColor(); for (int j = 0; j < pixelidx[i].size(); j++) { Point p = pixelidx[i][j]; circle(img, p, 1, color); } } imshow("pixelidx", img); }
/** * ControlDisplayProperties constructor. This sets default values and * constructs the object *. * * * @param displayName The filename (fully expanded) of the object. * @param parent Qt parent object (this is destroyed when parent is destroyed) */ ControlDisplayProperties::ControlDisplayProperties(QString displayName, QObject *parent) : DisplayProperties(displayName, parent) { m_propertiesUsed = None; m_propertyValues = new QMap<int, QVariant>; // set all of the defaults to prevent unwanted change signals from // being emitted later. setShowLabel(false); setSelected(false); setValue(Color, QVariant::fromValue(randomColor())); }
void QgsDiagramProperties::addAttribute( QTreeWidgetItem * item ) { QTreeWidgetItem *newItem = new QTreeWidgetItem( mDiagramAttributesTreeWidget ); newItem->setText( 0, item->text( 0 ) ); newItem->setData( 0, Qt::UserRole, item->data( 0, Qt::UserRole ) ); newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled ); //set initial color for diagram category int red = 1 + ( int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) ); int green = 1 + ( int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) ); int blue = 1 + ( int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) ); QColor randomColor( red, green, blue ); newItem->setBackground( 1, QBrush( randomColor ) ); mDiagramAttributesTreeWidget->addTopLevelItem( newItem ); }
void LetterHunter::initializeText() { ID2D1Factory* D2DFactory = d2d_->getD2DFactory(); ID2D1HwndRenderTarget* renderTarget = d2d_->getD2DHwndRenderTarget(); IDWriteFactory* DWriteFactory = d2d_->getDWriteFactory(); for(int i = 0; i < TEXTCOUNT; ++i) { // Geneate a random string const int strLength = 1; wchar_t* strBuffer = new wchar_t[strLength + 1]; randomString(strBuffer, strLength); TextObject* textObj = new TextObject( D2DFactory, renderTarget, DWriteFactory, strBuffer, 100 ); SAFE_DELETE(strBuffer); // Generate 10 random numbers between 1 and 100 float a[10] = {0}; float velocityY = randomFloat(10.0f, 50.0f); D2D_VECTOR_2F velocity = {0, velocityY}; // Set text position float windowWidth = (float)getwindowWidth(); D2D1_RECT_F textBoundRect = textObj->getBoundaryRect(); float maxRight = windowWidth - (textBoundRect.right -textBoundRect.left); float positionX = randomFloat(0, maxRight); D2D1_POINT_2F position = {positionX, 0}; textObj->setPosition(position); // Set text velocity textObj->setVelocity(velocity); D2D1_COLOR_F fillColor = randomColor(); textObj->setFillColor(fillColor); textBuffer_.push_back(textObj); } }
bool NumberData::writeToFile(string fileName, bool) { // Draw a graph using a palette object Palette graph(1024,512); GraphOptions options; options.setMinY(0); options.setMaxY(1500); options.useBcgd = true; for (auto &data : numberData) { RGBApixel line = randomColor(); options.setLineColor(line); graph.drawGraph2d(data, options); } graph.writeToFile(fileName+"/numberdata.bmp"); return true; }
void MainWindow::addShape() { Document *doc = currentDocument(); if (doc == 0) return; Shape::Type type; if (sender() == actionAddCircle) type = Shape::Circle; else if (sender() == actionAddRectangle) type = Shape::Rectangle; else if (sender() == actionAddTriangle) type = Shape::Triangle; else return; Shape newShape(type, randomColor(), randomRect(doc->size())); doc->undoStack()->push(new AddShapeCommand(doc, newShape)); }
/* geometry ID and primitive ID shading */ Vec3fa renderPixelGeomIDPrimID(float x, float y, const Vec3fa& vx, const Vec3fa& vy, const Vec3fa& vz, const Vec3fa& p) { /* initialize ray */ RTCRay ray; ray.org = p; ray.dir = normalize(x*vx + y*vy + vz); ray.tnear = 0.0f; ray.tfar = inf; ray.geomID = RTC_INVALID_GEOMETRY_ID; ray.primID = RTC_INVALID_GEOMETRY_ID; ray.mask = -1; ray.time = g_debug; /* intersect ray with scene */ rtcIntersect(g_scene,ray); /* shade pixel */ if (ray.geomID == RTC_INVALID_GEOMETRY_ID) return Vec3fa(0.0f); else return randomColor(ray.geomID ^ ray.primID)*Vec3fa(embree::abs(dot(ray.dir,normalize(ray.Ng)))); }
void Render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clean up the colour of the window // and the depth buffer glMatrixMode(GL_MODELVIEW); glLoadIdentity(); randomColor(); // Set drawing colour = orange for (float f = 0.0f; f < 20.0f; f++) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clean up the colour of the window // and the depth buffer glutSolidTeapot( f ); // Draw a built-in primitive glutSwapBuffers(); Sleep(100); } }
void QgsUniqueValueDialog::randomizeColors() { QList<QListWidgetItem *> selection = mClassListWidget->selectedItems(); if ( selection.size() == 0 ) selection = mClassListWidget->findItems( "", Qt::MatchContains ); for ( int i = 0; i < selection.size(); i++ ) { QListWidgetItem *item = selection[i]; if ( !item ) continue; if ( !mValues.contains( item->text() ) ) continue; QgsSymbol *symbol = mValues[ item->text()]; setSymbolColor( symbol, randomColor() ); updateEntryIcon( symbol, item ); } selectionChanged(); }
QImage FrostedGlassFilter::apply(const QImage& _image, const QRect& clipRect) { QMutexLocker locker(&m_mutex); QImage image = _image; if (image.width() > 800 || image.height() > 800) { image = _image.scaled(QSize(800, 800), Qt::KeepAspectRatio, Qt::SmoothTransformation); } QImage resultImg = image.convertToFormat(QImage::Format_ARGB32); QRect rc = clipRect; if (rc.isEmpty()) { rc = image.rect(); } rc &= resultImg.rect(); m_isAborting = false; qreal brushSize = qreal(m_brushSize) * image.width() / 800; qreal floatBrush = qMax(0.0, qMin(1.0, (1 - (ceil(brushSize) - brushSize)))); for (int y = rc.y(); y <= rc.bottom(); ++y) { if (m_isAborting) { return QImage(); } QRgb* line = reinterpret_cast<QRgb*>(resultImg.scanLine(y)); for (int x = rc.x(); x <= rc.right(); ++x) { QRgb pixel = randomColor(image, rc, QPoint(x,y), ceil(brushSize)); if (brushSize < 1.0) { line[x] = Blending::interp(line[x], pixel, 255 * floatBrush); } else { line[x] = pixel; } } setProgress(int((y - rc.y()) * 100.0 / rc.height())); } return resultImg; }
void QgsUniqueValueDialog::addClass( QString value ) { QgsDebugMsg( "called." ); if ( mValues.contains( value ) ) { int i; for ( i = 0; mValues.contains( value + QString::number( i ) ); i++ ) ; value += QString::number( i ); } QgsSymbol *symbol = new QgsSymbol( mVectorLayer->geometryType(), value, value, value.isNull() ? tr( "default" ) : "" ); mValues.insert( value, symbol ); QListWidgetItem *item = new QListWidgetItem( value ); item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ); item->setData( Qt::UserRole, value ); item->setToolTip( symbol->label() ); mClassListWidget->addItem( item ); setSymbolColor( symbol, randomColor() ); updateEntryIcon( symbol, item ); }
void Kek::peano(const QPoint &topleft, const QRect& rect) { int smallest{rect.height()}; if (smallest > rect.width()) smallest = rect.width(); int level{4}; int step{smallest/(level*level)}; p->begin(img); p->setPen(randomColor()); PEANO drawer; drawer.step = step; drawer.x = 0; drawer.y = 0; drawer.p = p; drawer.start = topleft; drawer.A(level); p->end(); }
/****************************************************************** * 函数功能:画匹配的特征点对 * 参考:https://gist.github.com/thorikawa/3398619 */ void plotMatches(const cv::Mat &srcColorImage, const cv::Mat &dstColorImage, std::vector<cv::Point2f> &srcPoints, std::vector<cv::Point2f> &dstPoints){ // Create a image for displaying mathing keypoints cv::Size sz = cv::Size(srcColorImage.size().width + dstColorImage.size().width, srcColorImage.size().height + dstColorImage.size().height); cv::Mat matchingImage = cv::Mat::zeros(sz, CV_8UC3); // Draw camera frame cv::Mat roi1 = cv::Mat(matchingImage, cv::Rect(0, 0, srcColorImage.size().width, srcColorImage.size().height)); srcColorImage.copyTo(roi1); // Draw original image cv::Mat roi2 = cv::Mat(matchingImage, cv::Rect(srcColorImage.size().width, srcColorImage.size().height, dstColorImage.size().width, dstColorImage.size().height)); //cv::Mat roi2 = cv::Mat(matchingImage, cv::Rect(srcColorImage.size().width, 0, dstColorImage.size().width, dstColorImage.size().height)); dstColorImage.copyTo(roi2); cv::RNG rng(0xFFFFFFFF); // Draw line between nearest neighbor pairs for (int i = 0; i < (int)srcPoints.size(); ++i) { cv::Point2f pt1 = srcPoints[i]; cv::Point2f pt2 = dstPoints[i]; cv::Point2f from = pt1; cv::Point2f to = cv::Point(srcColorImage.size().width + pt2.x, srcColorImage.size().height + pt2.y); //cv::Point2f to = cv::Point(srcColorImage.size().width + pt2.x, pt2.y); cv::line(matchingImage, from, to, randomColor(rng), 2); } // 在图像中显示匹配点数文本 /*Point org; org.x = rng.uniform(matchingImage.cols/10, matchingImage.rows/10); org.y = rng.uniform(matchingImage.rows/10, matchingImage.rows/10); putText(matchingImage, "Testing text rendering", org, rng.uniform(0,8), rng.uniform(0,10)*0.05+0.1, randomColor(rng), rng.uniform(1, 10), 8);*/ // Display mathing image cv::resize(matchingImage, matchingImage, cv::Size(matchingImage.cols/1.5, matchingImage.rows/1.5)); //cv::resize(matchingImage, matchingImage, cv::Size(matchingImage.cols, matchingImage.rows)); cv::imshow("Geometric Verification", matchingImage); cvWaitKey(0); }
ibool fastPolyDemo(MGLDC *dc) /**************************************************************************** * * Function: fastPolyDemo * Parameters: dc - Device context * * Description: Display a random pattern of convex triangular polygons * in replace mode at full speed. * ****************************************************************************/ { int maxx,maxy; fxpoint_t poly[4]; /* Space to hold polygon data */ mainWindow(dc,"MGL_fillPolygonFast Demonstration"); statusLine("Press any key to continue, ESC to Abort"); maxx = MGL_maxx(); maxy = MGL_maxy(); while (!checkEvent()) { /* Define a random polygon */ poly[0].x = MGL_randoml(MGL_TOFIX(maxx)); poly[0].y = MGL_randoml(MGL_TOFIX(maxy)); poly[1].x = MGL_randoml(MGL_TOFIX(maxx)); poly[1].y = MGL_randoml(MGL_TOFIX(maxy)); poly[2].x = MGL_randoml(MGL_TOFIX(maxx)); poly[2].y = MGL_randoml(MGL_TOFIX(maxy)); MGL_setColor(randomColor()); MGL_fillPolygonFX(3,poly,sizeof(fxpoint_t),0,0); } defaultAttributes(dc); return pause(); }
void WitchLightshow::updatePixels() { if (_crashDarkMode == true) { if ( ! _crashDarkModeBlastHappened) { Pixels::floodFill(_pixels, randomColor(), 1.0); _crashDarkModeBlastHappened = true; } } else { for ( byte s = 0; s < NUM_STRIPS; s++) { for (byte b = 0; b < NUM_BLOCKS; b++) { RGBB color = BLACK; if ( ( ! _soloColorMode ) || ( _soloColorMode && _blocks[s][b].color == _soloColor ) ) { color = _blocks[s][b].color; } byte first_pixel = b * BLOCK_SIZE; byte last_pixel = first_pixel + BLOCK_SIZE - 1 ; for (byte p = first_pixel; p < last_pixel; p++) { Pixels::pixelSet(_pixels, s, p, color, 1.0); } Pixels::pixelSet(_pixels, s, last_pixel, BLACK, 0); } } } }
/** * Actualiza las particulas * @param elapsedTime Tiempo desde el último frame */ void SpriteParticleSystem::update(sf::Time elapsedTime) { //Calculamos el número de particulas a mostrar while(m_particles.size() != m_numParticles) { float particles = m_particles.size() - m_numParticles; if(m_particles.size() > m_numParticles) { this->removeParticles(particles); } else this->addParticles(particles); } //Recorremos todas las particulas ... for(SpriteParticleIterator it = m_particles.begin(); it != m_particles.end(); it++) { //Disminuimos el tiempo de vida de la particula (*it)->lifeTime -= elapsedTime; //Si la particula muere, generamos una nueva if((*it)->lifeTime <= sf::Time::Zero) { resetParticle(std::distance<std::vector<SpriteParticle*>::const_iterator>(m_particles.begin(), it)); } //Controlamos el cambio de color if(m_twoColors) { m_color = randomColor(m_colorInit, m_colorEnd, (*it)->lifeTime); (*it)->sprite.setColor(m_color); } if(m_dissolve) { //Actualizamos el alpha (transparencia) de la particula de acuerdo a su tiempo de vida (*it)->sprite.setColor(sf::Color((*it)->sprite.getColor().r, (*it)->sprite.getColor().g, (*it)->sprite.getColor().b, static_cast<sf::Uint8>(m_lifeTime.asSeconds() * 255))); } //Actualizamos la velocidad de las particulas if(m_rotateParticle) { m_rotate = ((std::rand() % 360) * m_particleRotate / 180.f) * (*it)->lifeTime.asSeconds(); (*it)->sprite.setRotation(m_rotate); } (*it)->velocity.x += m_gravity.x * elapsedTime.asSeconds(); (*it)->velocity.y += m_gravity.y * elapsedTime.asSeconds(); //Actualizamos el tamaño de las particulas if(m_grow) { m_scale = randomVector2f(m_growScale.x, m_growScale.y, (*it)->lifeTime); (*it)->sprite.setScale(m_scale); } else { if(m_uniformScale) { m_scale = randomVector2f(m_scale.x, m_scale.y, (*it)->lifeTime); (*it)->sprite.setScale(m_scale); } else { (*it)->sprite.setScale(m_scale.x, m_scale.y); } } //Actualizamos la posicion del sprite correspondiente float getPosX = (*it)->sprite.getPosition().x; float getPosY = (*it)->sprite.getPosition().y; float posX = getPosX += (*it)->velocity.x * elapsedTime.asSeconds() * m_particleSpeed; float posY = getPosY += (*it)->velocity.y * elapsedTime.asSeconds() * m_particleSpeed; (*it)->sprite.setPosition(posX, posY); } }
bool loadConfig(const std::string &filename, ConfigInfo *config) { std::ifstream file(filename.c_str()); std::string read_buffer; bool hasHuman = false; if (!file) { DEBUG_ERROR("error on file " << filename); return false; } file >> read_buffer; while (!file.eof()) { if (read_buffer == "PLAYER") { std::string type_string; PlayerType t; file >> type_string; if (type_string == "HUMAN") { if (hasHuman) { std::cerr << "can't have two Humans" << std::endl; exit(1); } hasHuman = true; t = HUMAN; } else if (type_string == "AI_DFS") { t = AI_DFS; } else if (type_string == "AI_SMART") { t = AI_SMART; } else if (type_string == "AI_DUMB") { t = AI_DUMB; } else { std::cerr << "invalid player with type " << type_string << std::endl; exit(1); } std::string robotName; std::string isRandom; glm::vec3 robotColor; file >> robotName; file >> isRandom; if (isRandom == "random") { robotColor = randomColor(); } else { float g, b; file >> g >> b; robotColor = glm::vec3(std::atof(isRandom.c_str()), g, b); } config->playerConfigs.push_back(PlayerConfig(t, robotName, robotColor)); } else if (read_buffer == "ALGORITHM") {
bool HitMeScene::onContactBegin(PhysicsContact& contact) { Color3B randomColor(CCRANDOM_0_1()*255, CCRANDOM_0_1()*255, CCRANDOM_0_1()*255); _bgColorLayer->setColor(randomColor); return true; }
///Level 2 void CColor::newRandomColor(int pos) { this->colorAsked = randomColor(pos); }
int main() { //vars int x = 800; int y = 600; int framerate = 60; const enum modes{BALLS, TRIS, BOXES, ALL}; int mode; const int balls = 0; const int triangles = 10; const int boxes = 10; BouncingObject* shapes[balls + triangles + boxes]; CollisionDetection col; ////// sf::ConvexShape box(4); box.setPointCount(4); box.setPosition(sf::Vector2f(x - 10, y - 10)); box.setPoint(0, sf::Vector2f(-10, -10)); box.setPoint(1, sf::Vector2f(10, -10)); box.setPoint(2, sf::Vector2f(10, 10)); box.setPoint(3, sf::Vector2f(-10, 10)); box.setFillColor(sf::Color(160, 20, 40, 128)); ////// // Create the main window sf::RenderWindow window(sf::VideoMode(x, y, 32), "BOUNCING SHAPES"); window.setFramerateLimit(framerate); srand(time(NULL)); mode = modes::ALL; int total = 0; if (mode == modes::BALLS || mode == modes::ALL) { int j; for (j = total; j < total + balls; j++) { shapes[j] = new BouncingBall(16, Vector2f(randomFloat(x - 16, 1, false), randomFloat(y - 16, 1, false)), randomColor()); shapes[j]->impulse(Vector2f(randomFloat(8, 1, true), randomFloat(8, 1, true))); shapes[j]->setRotate(false); } total += j; } if (mode == modes::TRIS || mode == modes::ALL) { int j = total; for (j; j < total + triangles; j++) { //shapes[j] = new BouncingTriangle(32, Vector2f(0,0), randomColor()); //shapes[j] = new BouncingTriangle(32, Vector2f(x / 4 , y / 4), randomColor()); shapes[j] = new BouncingTriangle(16, Vector2f(randomFloat(x - 16, 1, false), randomFloat(y - 16, 1, false)), randomColor()); shapes[j]->impulse(Vector2f(randomFloat(80, 1, true), randomFloat(80, 1, true))); shapes[j]->spin(randomFloat(8, 1, true)); } total += j - total; } if (mode == modes::BOXES || mode == modes::ALL) { int j = total; for (j; j < total + boxes; j++) { shapes[j] = new BouncingRectangle(16, Vector2f(randomFloat(x - 16, 1, false), randomFloat(y - 16, 1, false)), randomColor()); shapes[j]->impulse(Vector2f(randomFloat(8, 1, true), randomFloat(8, 1, true))); shapes[j]->spin(randomFloat(8, 1, true)); } total += j - total; } // Start game loop while (window.isOpen()) { // Process events sf::Event Event; while (window.pollEvent(Event)) { // Close window : exit if (Event.type == sf::Event::Closed) window.close(); // Escape key : exit if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape)) window.close(); if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Num1)) shapes[0]->setPosition(sf::Vector2f(sf::Mouse().getPosition(window))); if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Num2)) shapes[1]->setPosition(sf::Vector2f(sf::Mouse().getPosition(window))); } //Declare looping vars int i, j; //update items for (i = 0; i < total; i++) { shapes[i]->update(0.05, x, y); } //check collisions for (i = 0; i < total - 1; i++) { bool collision = false; for (j = i + 1; j < total; j++) { if (col.CheckBoundingSphere(shapes[i]->getPosition(), shapes[j]->getPosition(), shapes[i]->getRadius(), shapes[j]->getRadius())) { if (col.CheckCollisionSAT(*shapes[i], *shapes[j])) { shapes[i]->bounceOther(shapes[j]->getPosition()); shapes[j]->bounceOther(shapes[i]->getPosition()); } } } } //prepare frame window.clear(); //draw frame items for (int i = 0; i < total; i++) { //shapes[i]->draw(window); window.draw(shapes[i]->getShape()); //window.setTitle("" + sf::Mouse().getPosition(window).x + ", " + sf::Mouse().getPosition(window).x); } // Finally, display rendered frame on screen window.display(); } //loop back for next frame return EXIT_SUCCESS; }
//-------------------------------------------------------------- void ofApp::keyPressed(int key){ ///screen false/true if(key=='a'){ ofColor transpaColor(colorPicked.r,colorPicked.g,colorPicked.b,ofRandom(20,150)); selectedColor.clear(); selectedColor.push_back(transpaColor); ofSetBackgroundAuto(false); } //easycam if(key=='z'){ camActive=true; randomZ=ofRandom(-1000,1000); }else{ camActive=false; } // ///close path with spacebar // if(key==' '){ // if(ofFill){ // ofNoFill(); // }else{ // ofFill; // } // } ///DELETE LAST POINT if(key=='b' && curveVertices.size()>0){ open=true; curveVertices.pop_back(); myPoints.pop_back(); ableClick=true; saveXml(); //saving Xml file } //DELETE ALL if(key==OF_KEY_BACKSPACE){ curveVertices.clear(); myPoints.clear(); distance=0; open=true; ableClick=true; saveXml(); //saving Xml file } ///MAKE IT CURVE if(key=='c' && curveVertices.size()>0){ if (curved) { curved=false; curvedVal= "Curved"; } else { curved=true; curvedVal= "Straight"; } saveXml(); //saving Xml file } ///FULLSCREEN if(key=='f'){ ofToggleFullscreen(); // set fullscreen } ///TEST RANDOM if(key=='k'){ if (curved) { // ofBackground(15); ofColor randomColor(ofRandom(255), ofRandom(255),ofRandom(255),curveVertices.size()*10); selectedColor.clear(); selectedColor.push_back(randomColor); for (int i = 0; i < curveVertices.size(); i++){ curveVertices[i].x=ofRandom(ofGetWidth()); curveVertices[i].y=ofRandom(ofGetHeight()); } } else { ofColor randomColor(ofRandom(255), ofRandom(255),ofRandom(255),curveVertices.size()*10); selectedColor.clear(); selectedColor.push_back(randomColor); // ofSetBackgroundAuto(false); for (int i = 0; i < curveVertices.size(); i++){ ofPoint position(curveVertices[i].x,curveVertices[i].y); ofPoint centre(ofGetWidth()/2,ofGetHeight()/2); float dist = ofDist(position.x,position.y , centre.x,centre.y); if (stage.inside(curveVertices[i].x,curveVertices[i].y)) { directionX=ofMap(mouseX, 0, ofGetWidth(), -100, 100); directionY=ofMap(mouseY, 0, ofGetHeight(), -100, 100); curveVertices[i].x+=ofRandom(directionX); curveVertices[i].y+=ofRandom(directionY); } else { curveVertices[i].x=ofGetWidth() - curveVertices[i].x; curveVertices[i].y=ofGetHeight() - curveVertices[i].y; curveVertices[i].x+=ofRandom(directionX); curveVertices[i].y+=ofRandom(directionY); } } } saveXml(); //saving Xml file } }
void myKeyboard(unsigned char key, int mouseX, int mouseY) { switch(key) { case 'q': //terminate program: exit(-1); break; case 'b': //changes background color to a random color glClearColor( randomColor(), randomColor(), randomColor(), 0.0); glutPostRedisplay(); break; case 'c': //changes background color back to black glClearColor(0.0,0.0,0.0,0.0); glutPostRedisplay(); break; case 'a': //increases the value of A if (A <= MAX_A_VALUE) //won't increase past the max value set for A A = A + 0.1; glutPostRedisplay(); break; case 's': //Decreases the value of A if (A > MIN_A_VALUE) //won't decrease past the min value set for A A = A - 0.1; glutPostRedisplay(); break; case 'w': //Swing-type mode swingInc = true; swingMode(0); break; case 'f': //Fading ON/OFF fadingMode = !fadingMode; colorSpiral = false; //turns off colorSpiral so it turns off, so fading mode can be seen glutPostRedisplay(); break; case 'u': //translates spiral +y if (spiralHeight < SCREEN_HEIGHT_MAX) //doesnt translate past certain +y point spiralHeight += 10; glutPostRedisplay(); break; case 'i': //translates spiral -y if (spiralHeight > SCREEN_HEIGHT_MIN) //doesnt translate past certain -y point spiralHeight -= 10; glutPostRedisplay(); break; case 'j': //translates spiral +x if (spiralWidth < SCREEN_WIDTH_MAX) spiralWidth += 10; glutPostRedisplay(); break; case 'k': //translates spiral -x if (spiralWidth > SCREEN_WITDH_MIN) spiralWidth -= 10; glutPostRedisplay(); break; case 'z': //changes background color to white glClearColor(1.0f,1.0f,1.0f,0.0); glutPostRedisplay(); break; case 'o': //translates spiral back to the default origin point spiralWidth = 0; spiralHeight = 0; glutPostRedisplay(); break; case 'r': //rotates spiral if (rotation >= PI_TWO) //prevents having to store a big value and causing issues rotation = 0; rotation += PI_THIRD; glutPostRedisplay(); break; case 'h': //color changes smoothly for spiral colorSpiral = !colorSpiral; //turns on/off the color variance fadingMode = false; //turns off fading mode to avoid issues glutPostRedisplay(); break; case 'n': //flipping x axis glMatrixMode (GL_PROJECTION); glLoadIdentity (); //Swaps left and right tempFlip = left; left = right; right = tempFlip; gluOrtho2D (left, right, bottom, top); glutPostRedisplay(); break; case 'm': //flipping y axis glMatrixMode (GL_PROJECTION); glLoadIdentity (); //Swaps bottom and top tempFlip = bottom; bottom = top; top = tempFlip; gluOrtho2D (left, right, bottom, top); glutPostRedisplay(); break; default: break; //do nothing } }