void loop() { while (Serial.available() > 0) { int mode = Serial.parseInt(); Serial.println(mode); switch (mode) { case 1: red(); break; case 2: green(); break; case 3: blue(); break; case 4: yellow(); break; case 5: pink(); break; default: LEDOff(); break; } } }
//expects blocks, not clusters!! void NandWindow::DrawBlockMap( QList<quint16> newFile ) { if( blocks.size() != 0x1000 ) { qWarning() << "NandWindow::DrawBlockMap -> current blocks are f****d up, son" << hex << blocks.size(); return; } QPixmap blue( ":/blue.png" ); QPixmap green( ":/green.png" ); QPixmap pink( ":/pink.png" ); QPixmap grey( ":/grey.png" ); QPixmap black( ":/black.png" ); for( quint16 i = 0; i < 0x1000; i++ ) { quint16 thisBlock; if( !newFile.contains( i ) ) { thisBlock = blocks.at( i ); } else { thisBlock = 2; } switch( thisBlock ) { default: case 1://used, but not in this file pmi[ i ]->setPixmap( green ); break; case 2://used in this file pmi[ i ]->setPixmap( pink ); break; case 0xFFFE://free block pmi[ i ]->setPixmap( grey ); break; case 0xFFFC://reserved pmi[ i ]->setPixmap( blue ); break; case 0xFFFD: // bad block pmi[ i ]->setPixmap( black ); break; } } }
////////////////////////////////////////// // TODO: using rand() is not really a good idea here, need a better solution void Noise::uGenerate( float * pChannels, const int numChannels ) { float n; switch (mTint) { // BROWN is a 1/f^2 spectrum (20db/decade, 6db/octave). // There is some disagreement as to whether // brown and red are the same, but here they are. case eTintBrown : case eTintRed : { // I admit that I'm using the filter coefficients and // amplitude correction from audacity, a great audio editor. float normRand = (float)rand() / RAND_MAX; // assert( normRand >= 0 && normRand <= 1 ); n = amplitude.getLastValue()*(2.0f*normRand - 1.0f); n = mBrownAlpha*n + ( 1 - mBrownAlpha )*mLastOutput; mLastOutput = n; n *= mBrownAmpCorr; } break; // PINK noise has a 10db/decade (3db/octave) slope case eTintPink : n = amplitude.getLastValue()*pink(); break; case eTintWhite : default : { float normRand = (float)rand() / (float)RAND_MAX; // assert( normRand >= 0 && normRand <= 1 ); n = amplitude.getLastValue()*(2.0f*normRand - 1.0f); } break; } for(int i = 0; i < numChannels; i++) { pChannels[i] = n + offset.getLastValue(); } }
int menu_proc(RenderWindow & win){ int status[3] = {CHOSE_PERSON, LOAD_SAVE_GAME, EXIT}; Texture t_fon; t_fon.loadFromFile("Labelmenu1.png"); Sprite s_fon; s_fon.setTexture(t_fon); Font font; font.loadFromFile("GoodDog.otf"); //Text text("text", font); char text[3][15] = {"New Game", "Load Game", "Exit"}; Text t[3]; Color pink(254, 137, 245); Color yellow(255, 214, 136); for(int i = 0; i < 3; i++){ t[i].setString(text[i]); t[i].setFont(font); t[i].setCharacterSize(100); t[i].setPosition(190, i*90+160); t[i].setColor(pink); } int cur = 0; t[cur].setColor(yellow); bool IsKeyPressedOneTime = false; while (win.isOpen()){ Event event; while (win.pollEvent(event)){ if (event.type == sf::Event::Closed || Keyboard::isKeyPressed(Keyboard::Escape)){ win.close(); } } if(Keyboard::isKeyPressed(Keyboard::Down) && !IsKeyPressedOneTime){ IsKeyPressedOneTime = true; t[cur].setColor(pink); if(cur < 2) cur++; t[cur].setColor(yellow); } else if(Keyboard::isKeyPressed(Keyboard::Up) && !IsKeyPressedOneTime){ IsKeyPressedOneTime = true; t[cur].setColor(pink); if(cur > 0) cur--; t[cur].setColor(yellow); } else if(Keyboard::isKeyPressed(Keyboard::Return)){ break; } win.clear(); win.draw(s_fon); for(int i = 0; i < 3; i++) win.draw(t[i]); win.display(); Sleep(100); IsKeyPressedOneTime = false; } return status[cur]; }
void NavigationMapObject::paint(QPainter &painter, QRect view, int scale) { // Save the painter state for this paint session // so that it can be restored after without influencing other objects painter.save(); { // Translate, scale, and rotate... QTransform t; t.scale(1.0/scale, 1.0/scale); t.translate(x - view.x()*scale, view.height()*scale - y + view.y()*scale); painter.setTransform(t, true); if(navigation != NULL) { // Init QColor pink(255,68,224); width = 0; height = 0; painter.setPen(Qt::transparent); painter.setOpacity(0.5); painter.setBrush(QBrush(pink)); QList<Vector2D> navPoints = navigation->getNavPoints(); // Draw all nav points for(int i = 0; i < navPoints.count(); i++) { // Calc size and coord int size = 100; if(navigation->getCurrentNavPoint()+1 == i) size = 200; int x = (int)navPoints.at(i).x(); int y = (int)navPoints.at(i).y(); // Set object dimensions based on most distant points... if(x > width) width = x; if(y > height) height = y; painter.setPen(Qt::transparent); painter.setOpacity(0.5); painter.setBrush(QBrush(pink)); painter.drawEllipse(QRect(x - (size / 2), (-y) - (size / 2), size, size)); painter.setFont(QFont("Arial Black", 120, QFont::Bold)); painter.setPen(pink); painter.setOpacity(0.5); painter.drawText(x + 150, (-y) - 150, QString("%1").arg(i)); if(i > 0) { QPen pen = painter.pen(); pen.setWidth(20); painter.setPen(pen); painter.drawLine((int)navPoints.at(i-1).x(), -((int)navPoints.at(i-1).y()), x, -y); } } // Draw splines if(navigation->name == "SplineNavigation") { // drawSpline(painter, ((SplineNavigation*)navigation)->getNavSplineX(), ((SplineNavigation*)navigation)->getNavSplineY(), scale, Qt::yellow, 20); // drawSpline(painter, ((SplineNavigation*)navigation)->getWheelLeftSplineX(), ((SplineNavigation*)navigation)->getWheelLeftSplineY(), scale, Qt::red, 1); // drawSpline(painter, ((SplineNavigation*)navigation)->getWheelRightSplineX(), ((SplineNavigation*)navigation)->getWheelRightSplineY(), scale, Qt::green, 1); } } } painter.restore(); }
int main(int argc, char* argv[]) { // Build your scene and setup your camera here, by calling // functions from Raytracer. The code here sets up an example // scene and renders it from two different view points, DO NOT // change this if you're just implementing part one of the // assignment. Raytracer raytracer; int width = 320; int height = 240; if (argc == 3) { width = atoi(argv[1]); height = atoi(argv[2]); } /***********************************************************Testing ******************************** // Camera parameters. Point3D eye(0, 0, 1); Vector3D view(0, 0, -1); Vector3D up(0, 1, 0); double fov = 60; // Defines a material for shading. Material gold( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648), Colour(0.628281, 0.555802, 0.366065), 51.2,0.3,0,NULL ); Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63), Colour(0.316228, 0.316228, 0.316228), 12.8,0.3,0,NULL); // Defines a point light source. raytracer.addLightSource( new PointLight(Point3D(0.0, 0, 5), Colour(0.9, 0.9, 0.9) ) ); // Add a unit square into the scene with material mat. SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &gold ); SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &jade ); // Apply some transformations to the unit square. double factor1[3] = { 1.0, 2.0, 1.0 }; double factor2[3] = { 6.0, 6.0, 6.0 }; raytracer.translate(sphere, Vector3D(0, 0, -5)); raytracer.rotate(sphere, 'x', -45); raytracer.rotate(sphere, 'z', 45); raytracer.scale(sphere, Point3D(0, 0, 0), factor1); raytracer.translate(plane, Vector3D(0, 0, -7)); raytracer.rotate(plane, 'z', 45); raytracer.scale(plane, Point3D(0, 0, 0), factor2); // Render the scene, feel free to make the image smaller for // testing purposes. raytracer.render(width, height, eye, view, up, fov, "view4.bmp"); // Render it from a different point of view. Point3D eye2(4, 2, 1); Vector3D view2(-4, -2, -6); raytracer.render(width, height, eye2, view2, up, fov, "view5.bmp"); ***********************************************************Testing ********************************/ /***********************************************************Final Scene********************************/ // Camera parameters. // Point3D eye(0, 8, -3); // Vector3D view(0, -1,0); Point3D eye(0, 0, 1); Vector3D view(0, 0, -1); Vector3D up(0, 1, 0); double fov = 60; // Defines a material for shading. Material gold( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648), Colour(0.628281, 0.555802, 0.366065), 51.2,0.2,NULL); // Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63), // Colour(0.316228, 0.316228, 0.316228), // 12.8,0.5,NULL); Material jade( Colour(0, 0, 0), Colour(0.47, 0.576, 0.859), Colour(0.316228, 0.316228, 0.316228), 12.8,0.5,NULL); Material red( Colour(0.3, 0.3, 0.3), Colour(1, 0, 0), Colour(0.628281, 0.555802, 0.366065), 51.2,0.2,NULL); Material white( Colour(0.3, 0.3, 0.3), Colour(1, 0.8549, 0.7255), Colour(0.628281, 0.555802, 0.366065), 51.2,0.2,NULL); Material pink( Colour(0.3, 0.3, 0.3), Colour(0.9412, 0.502, 0.502), Colour(0.628281, 0.555802, 0.366065), 51.2,0.2,NULL); Material mirror( Colour(0.0, 0.0, 0.0), Colour(0.0, 0.0, 0.0), Colour(0.0, 0.0, 0.0), 51.2,1,NULL); Material glass( Colour(0.3, 0.3, 0.3), Colour(1, 1, 1), Colour(0.628281, 0.555802, 0.366065), 51.2,0,1,NULL); glass.R_index = 1.3; glass.transparency_coef=1; // Defines a point light source. raytracer.addLightSource( new PointLight(Point3D(0, 0, 5), Colour(0.9, 0.9, 0.9) ) ); raytracer.addLightSource( new PointLight(Point3D(0, 6, -1), Colour(0.9, 0.3, 0.1) ) ); Material test( Colour(0.3, 0.3, 0.3), Colour(0.3, 0.60648, 0.22648), Colour(0.628281, 0.555802, 0.366065), 51.2 ,0.1,NULL); Material test3( Colour(0.3, 0.3, 0.3), Colour(0.3, 0.5, 0.22648), Colour(0.628281, 0.555802, 0.366065), 51.2,1,NULL ); Material test2( Colour(0, 0, 0), Colour(0.3, 0.3, 0.3), Colour(1.0, 1.0, 1.0), 51.2,0,NULL ); Texture sky("/Users/bingxu/Documents/graphics/COMP3271_assignment_4_template/raytracerMacOS/sky.bmp"); Texture board("/Users/bingxu/Documents/graphics/COMP3271_assignment_4_template/raytracerMacOS/board.bmp"); Material starrysky(Colour(0, 0, 0),Colour(0, 0, 0), Colour(0.1, 0.1, 0.1), 11.264, 0, &sky); Material board_mat(Colour(0, 0, 0),Colour(0, 0, 0), Colour(0.1, 0.1, 0.1), 11.264, 1, &board); SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &jade ); SceneDagNode* plane1 = raytracer.addObject( new UnitSquare(), &jade ); SceneDagNode* plane2 = raytracer.addObject( new UnitSquare(), &board_mat );//the bottom SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &mirror); SceneDagNode* sphere1 = raytracer.addObject( new UnitSphere(), &white ); SceneDagNode* mars = raytracer.addObject( new UnitSphere(), &glass ); SceneDagNode* earth = raytracer.addObject( new UnitSphere(), &pink ); SceneDagNode* cylinder1 = raytracer.addObject( new UnitFiniteCylinder(), &gold ); SceneDagNode* cylinder2 = raytracer.addObject( new UnitFiniteCylinder(), &gold ); SceneDagNode* cylinder3 = raytracer.addObject( new UnitFiniteCylinder(), &gold ); SceneDagNode* cone = raytracer.addObject( new UnitFiniteCone(), &red ); double factor1[3] = { 2.0, 2.0, 2.0 }; double factor2[3] = {50,50,50}; double factor3[3] = { 1.0, 1.0, 1.0}; double factor4[3] = { 1.0, 2, 1.0}; double factor5[3] = {0.5,0.5,0.5}; double factor6[3] = {0.5,1.5,0.5}; double factor7[3] = {1.0,4.0,1.0}; //3 squares raytracer.translate(plane, Vector3D(0, 0, -15)); raytracer.scale(plane, Point3D(0, 0, 0), factor2); raytracer.translate(plane1, Vector3D(-15, 0, 0)); raytracer.rotate(plane1, 'y', 90); raytracer.scale(plane1, Point3D(0, 0, 0), factor2); raytracer.translate(plane2, Vector3D(0, -8, 0)); raytracer.rotate(plane2, 'x', -90); raytracer.scale(plane2, Point3D(0, 0, 0), factor2); //four balls raytracer.translate(sphere, Vector3D(-1, -6, -2)); raytracer.scale(sphere, Point3D(0, 0, 0), factor3); raytracer.translate(sphere1,Vector3D(-4.5, -6, 1)); raytracer.scale(sphere1, Point3D(0, 0, 0), factor3); raytracer.translate(mars, Vector3D(3, -3, -1)); raytracer.scale(mars, Point3D(0, 0, 0), factor3); raytracer.translate(earth, Vector3D(-8, -6, -2)); raytracer.scale(earth, Point3D(0, 0, 0), factor3); raytracer.rotate(cylinder1, 'z', -30); //raytracer.rotate(cylinder1, 'x', -15); raytracer.translate(cylinder1, Vector3D(0, -4, -2)); raytracer.scale(cylinder1, Point3D(0, 0, 0), factor7); raytracer.rotate(cylinder2, 'z', -30); raytracer.translate(cylinder2, Vector3D(1.5, -3, -2)); raytracer.scale(cylinder2, Point3D(0, 0, 0), factor6); raytracer.rotate(cylinder3, 'z', -30); raytracer.translate(cylinder3, Vector3D(-1.5, -3, -2)); raytracer.scale(cylinder3, Point3D(0, 0, 0), factor6); raytracer.rotate(cone, 'z', -30); raytracer.translate(cone, Vector3D(0, 2, -2)); raytracer.scale(cone, Point3D(0, 0, 0), factor4); std::clock_t start; double duration; start = std::clock(); // raytracer.render(width, height, eye, view, up, fov, "view4.bmp"); duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC; //std::cout<<"The rendering duration 1 is .......: "<< duration <<'\n'; // Render it from a different point of view. Point3D eye2(3, 1, 5); Vector3D view2(-10, -8, -15); std::clock_t start1; double duration1; start1 = std::clock(); raytracer.render(width, height, eye2, view2, up, fov, "view5.bmp"); duration1 = ( std::clock() - start1 ) / (double) CLOCKS_PER_SEC; // std::cout<<"The rendering duration 2 is .......: "<< duration1 <<'\n'; /***********************************************************Final Scene********************************/ return 0; }
int lavelMap_proc(Game * game, RenderWindow & win){ const int num = 4; int pos[num][2] = {{250, 567}, {305, 535}, {358, 505}, {408, 474}}; Image i_pod; i_pod.loadFromFile("podsvet.png"); i_pod.createMaskFromColor(Color::White); Texture t_fon, t_pod, t_p; t_p.loadFromFile(game_getNameSprite(game)); t_pod.loadFromImage(i_pod); t_fon.loadFromFile("lavel_map.png"); Sprite s_fon, s_pod, s_p; s_p.setTexture(t_p); s_p.setTextureRect(IntRect(40, 0, 40, 55)); s_pod.setTexture(t_pod); s_fon.setTexture(t_fon); Font font; font.loadFromFile("GoodDog.otf"); Color pink(255, 0, 128); Color blue(63, 200, 210); Text text("Lavel map", font); text.setCharacterSize(90); text.setPosition(200, 0); text.setColor(pink); bool IsKeyPressedOneTime = false; int cur = 0; while (win.isOpen()){ Event event; while (win.pollEvent(event)){ if (event.type == sf::Event::Closed || Keyboard::isKeyPressed(Keyboard::Escape)){ win.close(); } } if(Keyboard::isKeyPressed(Keyboard::Right) && !IsKeyPressedOneTime){ IsKeyPressedOneTime = true; if(cur < num-1) cur++; } else if(Keyboard::isKeyPressed(Keyboard::Left) && !IsKeyPressedOneTime){ IsKeyPressedOneTime = true; if(cur > 0) cur--; } else if(Keyboard::isKeyPressed(Keyboard::Return)){ game_setCurLavel(game, cur); break; } else if(Keyboard::isKeyPressed(Keyboard::BackSpace)){ return MAIN_MENU; } s_p.setPosition(pos[cur][0]+7, pos[cur][1]-38); s_pod.setPosition(pos[cur][0], pos[cur][1]); win.clear(); win.draw(s_fon); win.draw(s_pod); win.draw(text); win.draw(s_p); win.display(); Sleep(100); IsKeyPressedOneTime = false; } return LAVEL; }
void GameScreen::paintEvent(QPaintEvent * event) { if (r >= 255) { r_dir = RANGE_DOWN; g_dir = RANGE_UP; b_dir = RANGE_IDLE; } if (g >= 255) { r_dir = RANGE_IDLE; g_dir = RANGE_DOWN; b_dir = RANGE_UP; } if (b >= 255) { r_dir = RANGE_UP; g_dir = RANGE_IDLE; b_dir = RANGE_DOWN; } if (r_dir == RANGE_UP) { r += 5; } else if (r_dir == RANGE_DOWN){ r -= 5; } if (g_dir == RANGE_UP) { g += 5; } else if (g_dir == RANGE_DOWN){ g -= 5; } if (b_dir == RANGE_UP) { b += 5; } else if (b_dir == RANGE_DOWN) { b -= 5; } QColor white(255, 255, 255); QColor darkWhite(250, 250, 250); QColor pink(255, 192, 203); QColor brown(97, 25, 11); QColor rainbow(r, g, b); QColor neg_rainbow(255 - r, 255 - g, 255 - b); QPainter painter(this); painter.fillRect(0, 0, width(), height(), darkWhite); painter.setPen(QPen(Qt::black, 1)); if (mode == MODE_MENU) { painter.drawText(400, 300, "Press the Space Key to Start"); } else if (mode == MODE_RUNNING) { //draw coffee painter.setPen(QPen(darkWhite, 1)); for (int i = 0; i < coffee_loc.size(); i++) { painter.drawRect(coffee_loc[i].first * sq_s, coffee_loc[i].second * sq_s, sq_s, sq_s); painter.fillRect(coffee_loc[i].first * sq_s + 1, coffee_loc[i].second * sq_s + 1, sq_s - 1, sq_s - 1, rainbow); } //draw fruit painter.setPen(QPen(pink, 1)); painter.setBrush(pink); for (int i = 0; i < fruit_loc.size(); i++) { painter.drawEllipse((fruit_loc[i].first * sq_s), (fruit_loc[i].second * sq_s), sq_s, sq_s); } //draw snake painter.setPen(QPen(darkWhite, 1)); for (int i = 0; i < body.size(); i++) { painter.drawRect(body[i].first * sq_s, body[i].second * sq_s, sq_s, sq_s); painter.fillRect(body[i].first * sq_s + 1, body[i].second * sq_s + 1, sq_s - 1, sq_s - 1,neg_rainbow); } } else if (mode == MODE_GAMEOVER) { painter.setPen(QPen(Qt::lightGray, 1)); for (int i = 0; i < body.size(); i++) { painter.drawRect(body[i].first * sq_s, body[i].second * sq_s, sq_s, sq_s); painter.fillRect(body[i].first * sq_s + 1, body[i].second * sq_s + 1, sq_s - 1, sq_s - 1, Qt::gray); } painter.setPen(QPen(Qt::red, 1)); painter.drawText(400, 300, "GAMEOVER"); } }
//-------------------------------------------------------------- void ofApp::setup(){ numSmallCircles = 41; //11 purple, 7 blue, 5 top right, 11 sleave, 7 but, 14 bottom grabbed = false; ofColor purple (161, 99, 128); ofColor pink (214, 73, 89); // 1 pink ofColor lightPink (147,131,17); //2 light pink ofColor yellow (212,179,14); //3 yellow ofColor black (44,53,71); //4 middle black ofColor blue (47,96,137);//5 blue ofColor green (28,124,92);//6 green ofColor orange (228,95,79);//7 orange bottom circles ofColor moreYellow (204, 155, 82); ofColor orangeLighter (232,105,92); ofColor darkBlue (38,81,126); //purple circle positions 0-11 circlePositions.push_back(ofPoint(436, 342)); //0 circlePositions.push_back(ofPoint(446, 358)); //1 circlePositions.push_back(ofPoint(438, 385)); //2 circlePositions.push_back(ofPoint(414,352)); //3 circlePositions.push_back(ofPoint(429, 369)); //4 circlePositions.push_back(ofPoint(423, 385)); //5 circlePositions.push_back(ofPoint(425, 395)); //6 circlePositions.push_back(ofPoint(402,337)); //7 circlePositions.push_back(ofPoint(403, 376)); //8 circlePositions.push_back(ofPoint(389, 392)); //9 circlePositions.push_back(ofPoint(381, 348)); //10 circlePositions.push_back(ofPoint(382, 365)); //11 for(int i=0; i<11; i++){ CirclesWoman tempCircle; smallCircles.push_back(tempCircle); } int width = ofRandom(20,30); int height = ofRandom(10,20); smallCircles[1].setup(width, height, pink, lightPink, black, circlePositions[1]); smallCircles[2].setup(width, height, purple, yellow, black, circlePositions[2]); smallCircles[3].setup(width, height, yellow, pink, black, circlePositions[3]); smallCircles[4].setup(width, height, pink, lightPink, black, circlePositions[4]); smallCircles[5].setup(width, height, purple, yellow, black, circlePositions[5]); smallCircles[6].setup(width, height, yellow, lightPink, black, circlePositions[6]); smallCircles[7].setup(width, height, pink, yellow, yellow, circlePositions[7]); smallCircles[8].setup(width, height, pink, yellow, black, circlePositions[8]); smallCircles[9].setup(width, height, blue, green, green, circlePositions[9]); smallCircles[10].setup(width, height, pink, purple, black, circlePositions[10]); smallCircles[11].setup(width, height, purple, yellow, black, circlePositions[11]); //blue circles for(int i=11; i<19; i++){ CirclesWoman tempBlueCircle; tempBlueCircle.randomSetup("blue"); smallCircles.push_back(tempBlueCircle); } // setup(int _width, int _height, ofColor color1, ofColor color2, ofColor color3 , ofPoint _position) for(int i=19; i<26; i++){ CirclesWoman tempButtCircle; tempButtCircle.randomSetup("butt"); smallCircles.push_back(tempButtCircle); } for(int i=26; i<41; i++){ CirclesWoman tempBottomCircle; smallCircles.push_back(tempBottomCircle); } smallCircles[26].setup(13.33, 9.33, orange, moreYellow, moreYellow, ofPoint(447,727)); smallCircles[27].setup(17.33, 18.833, orange, moreYellow, moreYellow, ofPoint(447,738.5)); smallCircles[28].setup(17.33, 15.75, orange, moreYellow, green, ofPoint(450,753)); smallCircles[29].setup(16, 11.875, orange, moreYellow, moreYellow, ofPoint(442,769)); smallCircles[30].setup(17.33, 14.542, orange, moreYellow, green, ofPoint(429,722)); smallCircles[31].setup(18.267, 14.751, orange, moreYellow, moreYellow, ofPoint(430,733)); smallCircles[32].setup(24.99, 18.17, orange, orangeLighter, black, ofPoint(430,748)); smallCircles[33].setup(19.313, 15.34, darkBlue, darkBlue, black, ofPoint(418,762.566)); smallCircles[34].setup(18.3, 13.602, orange, moreYellow, moreYellow, ofPoint(415.33,720)); smallCircles[35].setup(23.54, 16.605, orange, orangeLighter, black, ofPoint(408,736)); smallCircles[36].setup(22, 14, darkBlue, darkBlue, black, ofPoint(389,722)); smallCircles[37].setup(21, 14, orange, yellow, yellow, ofPoint(385,740)); smallCircles[38].setup(21, 14, orange, orangeLighter, black, ofPoint(395,750)); smallCircles[39].setup(21, 18, orange, moreYellow, moreYellow, ofPoint(382,763)); smallCircles[40].setup(21, 17, orange, moreYellow, moreYellow, ofPoint(404,765)); //<-------------- squiggly lines dress ----------------> numLines = 30; int startingX = 332; int endingX = 500; int interval = (endingX-startingX)/numLines; for(int i=0; i<numLines; i++){ SquigglyLine tempSquiggle; tempSquiggle.setup(startingX + interval*i); lines.push_back(tempSquiggle); } //<-------------- images ----------------> arm.loadImage("arm.png"); greenCircle.loadImage("green_circle.png"); orangeBackground.loadImage("orange_background.jpg"); heads.loadImage("heads.png"); spiralBackground.loadImage("under_spirals.png"); background.loadImage("background.jpg"); man.loadImage("man.png"); //<-------------- little squares dress ----------------> numLittleSquares = 120; for(int i=0; i<numLittleSquares; i++){ LittleSquares tempSquare; tempSquare.setup(); dressSquares.push_back(tempSquare); } //<-------------- big circles dress ----------------> numBigCirclesDress = 10; // for(int i=0; i<numBigCirclesDress; i++){ // bigCirclesDress tempBigCircle; // tempBigCircle.setup(); // bigCircles.push_back(tempBigCircle); // // // } // for(int i=0; i<numBigCirclesDress; i++){ bigCirclesDress tempBigCircle; bigCircles.push_back(tempBigCircle); } bigCircles[0].setupFixed(ofPoint(411,488),22,16); bigCircles[1].setupFixed(ofPoint(412,637),20,16); bigCircles[2].setupFixed(ofPoint(457,330),22,14); bigCircles[3].setupFixed(ofPoint(417,543),21,15); bigCircles[4].setupFixed(ofPoint(342,500),18,11); bigCircles[5].setupFixed(ofPoint(377,519),18,13); bigCircles[6].setupFixed(ofPoint(449,548),22,16); bigCircles[7].setupFixed(ofPoint(388,590),21,15); bigCircles[8].setupFixed(ofPoint(392,649),15,11); bigCircles[9].setupFixed(ofPoint(465,726),19,15); //<-------------- spirals ----------------> numSpirals = 12; for(int i=0; i<numSpirals; i++){ spiral tempSpiral; spirals.push_back(tempSpiral); //spirals[i].setupRandom(); } spirals[0].setup(ofPoint(495,373), 35,35, 4); spirals[1].setup(ofPoint(537,355), 52,52, 4); spirals[2].setup(ofPoint(560, 506), 40, 38, 4); spirals[3].setup(ofPoint(499, 473), 60, 55, 5); spirals[4].setup(ofPoint(520, 438), 35, 32, 4); spirals[5].setup(ofPoint(553, 414), 29, 29, 3); spirals[6].setup(ofPoint(483, 598), 50, 45, 4); spirals[7].setup(ofPoint(540, 619), 40, 35, 4); spirals[8].setup(ofPoint(595, 554), 34, 32, 3); spirals[9].setup(ofPoint(479, 414), 45, 40, 4); spirals[10].setup(ofPoint(534, 537), 54, 44, 6); spirals[11].setup(ofPoint(490, 530), 36, 31, 4); // int posX = 495; // float radius = 35; // for(var i=0; i<numSpirals; i++){ // if(posX < 650){ // posX += numSpirals[i-1].radius/2 // } // spirals[i].setup(ofPoint()); // } }
int main() { Tserial *com; char ch; com = new Tserial(); com->connect("COM3", 4800, spNONE); CvCapture *capture = 0; IplImage *frame = 0; int key = 0; // com->sendChar('a'); int pinkx,pinky,yellowx,yellowy,bluey,greeny,violetx,violety,botx,boty,i=0; int hb,sb,cb,wb; int greenx[21]={1},bluex[21]={1}; double bottheta,theta2,slope; int flag=1,flag1=1,flag2=1; /* initialize camera */ capture = cvCaptureFromCAM(0); //cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 1024 ); //cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 720 ); /* always check */ if ( !capture ) { fprintf( stderr, "Cannot open initialize webcam!\n" ); return 1; } /* create a window for the video */ cvNamedWindow( "image", CV_WINDOW_AUTOSIZE ); while( key != 'q' ) { /* get a frame */ img = cvQueryFrame( capture ); /* always check */ if( !img ) break; cvErode(img,img,NULL,1); cvDilate(img,img,NULL,1); cvErode(img,img,NULL,1); cvDilate(img,img,NULL,1); cvErode(img,img,NULL,1); cvDilate(img,img,NULL,1); img0=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3); imgblue=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3); imgpink=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3); imgyellow=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3); imggreen=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3); imgblack=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3); imgviolet=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3); cvCvtColor(img,img0,CV_BGR2HSV); cvSetMouseCallback( "image", mouseHandler, img0 ); // cvThreshold(img0, img0, 85, 255, CV_THRESH_BINARY); /*cvErode(img0,img0,NULL,1); cvDilate(img0,img0,NULL,1); cvErode(img0,img0,NULL,1); cvDilate(img0,img0,NULL,1); cvErode(img0,img0,NULL,1); cvDilate(img0,img0,NULL,1);*/ /* display curent frame */ cvShowImage( "image", img ); pinkx=pink(img0,1); yellowx=yellow(img0,1); for(i=20;i>0;i--) { bluex[i]=bluex[i-1]; } bluex[0]=blue(img0,1); for(i=20;i>0;i--) { greenx[i]=greenx[i-1]; } greenx[0]=green(img0,1); violetx=violet(img0,1); black(img,1); uchar* datablack=(uchar*)imgblack->imageData; hb=img0->height; wb=img0->width; cb=img0->nChannels; sb=img0->widthStep; uchar* datablue=(uchar*)imgblue->imageData; uchar* datayellow=(uchar*)imgyellow->imageData; pinky=pink(img0,0); yellowy=yellow(img0,0); bluey=blue(img0,0); greeny=green(img0,0); violety=violet(img0,0); cvShowImage( "imageblue", imgblue ); cvShowImage( "imagepink", imgpink ); cvShowImage( "imageyellow", imgyellow ); cvShowImage( "imagegreen", imggreen ); cvShowImage( "imageblack", imgblack ); cvShowImage( "imageviolet", imgviolet ); botx=pinkx-violetx; boty=pinky-violety; bottheta=atan((double)boty/(double)botx)*180/PI; if(pinky>giy && pinky<gfy && pinkx < 225&& flag2==1){ if(greenx[0]-greenx[20]>1 && greenx[0]>gix ){ com->sendChar('F'); printf("1"); flag2=0; } else{ com->sendChar('s'); printf("stop"); } } else if(bottheta<45 && bottheta >-45 && pinkx>violetx && flag==1){//right flag1=1; printf("right\n"); if(datablack[pinky*sb+(pinkx+l)*cb+0]!=0) { if(bottheta >20) { com->sendChar('l'); printf("R\n"); } else if (bottheta <-20) { com->sendChar('r'); printf("L\n"); } else if(bottheta >10) { com->sendChar('r'); printf("r\n"); } else if (bottheta <-10) { com->sendChar('l'); printf("l\n"); } else { com->sendChar('F'); printf("F\n"); } } else if(datablack[pinky*sb+(pinkx+l)*cb+0]==0) { if((pinky-m)>0){ if(datablack[(pinky-m)*sb+(pinkx)*cb+0]!=0) { com->sendChar('L'); printf("Left\n"); flag=0; } else if((pinky+m)<479){ if(datablack[(pinky+m)*sb+(pinkx)*cb+0]!=0) { com->sendChar('R'); printf("Right\n"); flag=0; } } } } } else if((bottheta>45 || 180+bottheta <135) && pinky > violety && flag1==1){//back flag=1; printf("back\n"); if((pinky+n)<479){ if(datablack[(pinky+n)*sb+(pinkx)*cb+0]!=0&&(pinky+l)<479) { if(bottheta <75 && bottheta>45) { com->sendChar('r'); printf("R\n"); } else if (180+bottheta >105&&180+bottheta <135) { com->sendChar('l'); printf("L\n"); } else if(bottheta <85&&bottheta>45) { com->sendChar('e'); printf("r\n"); } else if (180+bottheta >95 && 180+bottheta <135) { com->sendChar('d'); printf("l\n"); } else { com->sendChar('F'); printf("F\n"); } } else if(datablack[(pinky+n)*sb+(pinkx)*cb+0]==0) { if((pinkx-m)>0){ if(datablack[(pinky)*sb+(pinkx-m)*cb+0]!=0) { com->sendChar('R'); printf("Right\n"); flag1=0; } else if(datablack[(pinky)*sb+(pinkx+m)*cb+0]!=0) { com->sendChar('L'); printf("Left\n"); flag1=0; } } } } } else if(180+bottheta>135 && 180+bottheta < 225 && pinkx<violetx && flag==1){//left flag1=1; printf("left\n"); if((pinkx-l) >0){ if(datablack[pinky*sb+(pinkx-l)*cb+0]!=0) { if(180+bottheta <160) { com->sendChar('r'); printf("R\n"); } else if (180+bottheta >200) { com->sendChar('l'); printf("L\n"); } else if(180+bottheta <170) { com->sendChar('e'); printf("r\n"); } else if (180+bottheta>190) { com->sendChar('d'); printf("l\n"); } else { com->sendChar('F'); printf("F\n"); } } else if(datablack[pinky*sb+(pinkx-l)*cb+0]==0) { if((pinky-m)>0&&pinky+m<479){ if(datablack[(pinky-m)*sb+(pinkx)*cb+0]!=0) { com->sendChar('R'); printf("Right\n"); flag=0; } else if(datablack[(pinky+m)*sb+(pinkx)*cb+0]!=0) { com->sendChar('L'); printf("Left\n"); flag=0; } } } } } else if((180+bottheta > 225 || bottheta < -45) && pinky < violety && flag1==1){//straight flag=1; printf("straight\n"); if((pinky-l)>0 || pinky<125){ if(datablack[(pinky-l)*sb+(pinkx)*cb+0]!=0) { if((180+bottheta <250) && (180+bottheta > 225)) { com->sendChar('r'); printf("R\n"); } else if ((bottheta > -70) && (bottheta < -45)) { com->sendChar('l'); printf("L\n"); } else if((180+bottheta <260) && (180+bottheta > 225)) { com->sendChar('e'); printf("r\n"); } else if ((bottheta > -80) && (bottheta < -45)) { com->sendChar('d'); printf("l\n"); } else if((pinkx > bix && pinky < biy)==0) { com->sendChar('F'); printf("F\n"); } else{ if(((datablue[(pinky-40)*sb+(pinkx-30)*cb+0]!=0)&&(bluex[20]-bluex[0]<0))) { com->sendChar('F'); printf("blueforward\n"); } else{ com->sendChar('s'); printf("bluesstop\n"); } } } else if(datablack[(pinky-l)*sb+(pinkx)*cb+0]==0) { if((pinkx-l)> 0){ if(datablack[(pinky)*sb+(pinkx+m)*cb+0]!=0) { com->sendChar('R'); printf("Right\n"); flag1=0; } else if(datablack[(pinky)*sb+(pinkx-m)*cb+0]!=0) { com->sendChar('L'); printf("Left\n"); flag1=0; } } } } } key = cvWaitKey(1); cvReleaseImage(&img0); //cvReleaseImage(&img); cvReleaseImage(&imgblue); cvReleaseImage(&imgpink); cvReleaseImage(&imgyellow); cvReleaseImage(&imggreen); cvReleaseImage(&imgblack); cvReleaseImage(&imgviolet); } /* free memory */ cvDestroyWindow( "image" ); cvDestroyWindow( "imageblue"); cvDestroyWindow( "imagepink"); cvDestroyWindow( "imageyellow"); cvDestroyWindow( "imageblack"); cvDestroyWindow( "imagegreen"); cvDestroyWindow( "imageviolet"); cvReleaseCapture( &capture ); com->disconnect(); return 0; }