t_opt *createopt(char *s) { t_opt *opt; opt = (t_opt*)malloc(sizeof(t_opt)); initalize(opt); if (s) { while (*s) { if (*s == 'a') opt->a = 1; else if (*s == 'r') opt->r = 1; else if (*s == 't') opt->t = 1; else if (*s == 'l') opt->l = 1; else if (*s == '1') opt->c = 1; else if (*s == 'R') opt->rec = 1; s++; } } return (opt); }
DoorEntity::DoorEntity(const TextureManager& textures, World* world) : Entity(world) { mSprite.setTexture(textures.get(Textures::AutoDoors)); setTilePosition(TilePosition(5,1)); mSprite.setScale(world->getWorldScale()); initalize(); }
main () { int st, en; // initalize (); printf ("Enter the start and the end:"); scanf ("%d %d", &st, &en); path (st, en); getchar (); getchar (); }
void RenderSystem::added(artemis::Entity& e) { auto spatial = this->getSpatial(e); if (nullptr != spatial) { spatial->initalize(); auto material = spatial->getMaterial(); if (material) { _canvas->addChild(material); } _spatials->set(e.getId(), spatial); } }
main () { int icounter; int jcounter; double k = 1; double T = 1; const int seed_occ = 1; const int seed_pos = 2; const int seed_en = 3; const double p = 0.6; std::mt19937 gen_pos(seed_pos); std::mt19937 gen_en(seed_en); std::uniform_real_distribution<double> en(0,1); std::uniform_int_distribution<> pos(0,N-1); std::vector< std::vector<char> > cluster(N, std::vector<char>(N)); initalize(cluster, seed_occ, p); Print_lattice (cluster, N, N, ImageWidth, ImageHeight, "random1.ppm"); int steps = pow(10,5); int i,j; // ferromagnetism 1 or -1 int ferro = -1; for(icounter = 0; icounter < steps; icounter++) { i = pos(gen_pos); j = pos(gen_pos); int this_energy = energy_diff(cluster, i, j, ferro); if( this_energy < 0 ) flip(cluster, i, j); else { if( std::min(double(1),exp(-double(this_energy)/(k*T))) >= en(gen_en)) { flip(cluster, i, j); } } } Print_lattice (cluster, N, N, ImageWidth, ImageHeight, "random2.ppm"); }
Engine::Engine() { initalize(); }
int main ( int argc, char** argv ) { std::cout << "Starting\n"; initalize(); //TODO add resource load error handling add_surface("spaceb", load_surface("gray_space.png",1) ); add_surface("spacem", load_surface("gray_space.png",1) ); add_surface("spacef", load_surface("gray_space.png",1) ); for(int i=-2; i < 20+2; i++) meta::objects.push_back(new psrect_static(200*i, 200, 200, 200)); //meta::objects.push_back(new psrect_static(320, 20, 320, 20)); //meta::objects.push_back(new psrect_static(0, -400,1, 1000)); //meta::objects.push_back(new psrect_static(1000, -400, 1, 1000)); meta::objects.push_back(new rocket(2000,-100, 50,70)); //load_map("test.json"); float32 timeStep = 1.0f / 30.0f; int32 velocityIterations = 6; int32 positionIterations = 2; FPSmanager manager; SDL_initFramerate(&manager); SDL_setFramerate(&manager, 30); // program main loop bool done = false; while (!done) { SDL_framerateDelay(&manager); // message processing loop SDL_Event event; while (SDL_PollEvent(&event)) { // check for messages switch (event.type) { // exit if the window is closed case SDL_QUIT: done = true; break; // check for keypresses case SDL_KEYDOWN: // exit if ESCAPE is pressed if (event.key.keysym.sym == SDLK_ESCAPE) done = true; break; } // end switch } // end of message processing // DRAWING STARTS HERE // clear screen //SDL_FillRect(meta::screen, 0, SDL_MapRGB(meta::screen->format, 0, 0, 0 )); SDL_FillRect(meta::screen, 0, SDL_MapRGB(meta::screen->format, meta::background_red , meta::background_green, meta::background_blue )); draw_background(); // Instruct the world to perform a single step of simulation. // It is generally best to keep the time step and iterations fixed. meta::world.Step(timeStep, velocityIterations, positionIterations); update_objects(); meta::world.DrawDebugData(); // DRAWING ENDS HERE // finally, update the screen :) SDL_Flip(meta::screen); } // end main loop // all is well ;) printf("Exited cleanly\n"); return 0; }
Application::Application(QString configurationFile) { _configurationFile = configurationFile; initalize(); }
void Application::handleIncomingGuiReloadConfigCommand() { deinitalize(false); initalize(false); }
void moveXY(int Xdist, int Ydist) { char TextLine[1000] = ""; long tempX = 0, tempY = 0; int i = 0; unsigned char reverseX = 0, reverseY = 0; sprintf(TextLine, "Moving X: %ld, Moving Y: %ld", Xdist, Ydist); MessageText(TextLine, MessageX, MessageY, 0); if(posX==-1||posY==-1) initalize(); if(posX+Xdist>MAXSIZEX) //make sure we dont go out of bounds too high Xdist = MAXSIZEX-posX; if(posX+Xdist<0) //make sure we dont go out of bound too low Xdist = -posX; if(posY+Ydist>MAXSIZEY) Ydist = MAXSIZEY-posY; if(posY+Ydist<0) Ydist = -posY; if(Xdist==0&&Ydist==0) return; int Xspeed = 100; int Yspeed = 100; bool foundX = false; bool foundY = false; if(Xdist==0||Ydist==0) { if(Xdist>0) //need to go fowards { power(motorXA,Xspeed); power(motorXB,0); }else if (Xdist<0) //need to go backword { power(motorXA,0); power(motorXB,Xspeed); }else //already at the correct x point { power(motorXA,0); power(motorXB,0); foundX = true; } if(Ydist>0) { //need to go fowards power(motorYA,Yspeed); power(motorYB,0); }else if (Ydist<0) //need to go backwords { power(motorYA,0); power(motorYB,Yspeed); }else //alrady at the correct pint { power(motorYA,0); power(motorYB,0); foundY = true; } }else { if(abs(Xdist)>=abs(Ydist)) { Xspeed = 100; Yspeed = (abs(Ydist)/abs(Xdist))*Xspeed; } else { Yspeed = 100; Xspeed = (abs(Xdist)/abs(Ydist))*Yspeed; } } while(!foundX||!foundY) { int result = didTick(!foundX,!foundY); if(!foundX) { if(result==1) { if(Xdist>0) { posX += 10; Xdist -= 10; //increment the posY for we moved the machine //decrease the value that we still have to go } else { posX -= 10; Xdist += 10; } if(abs(Xdist)<20) { if(Xdist>0) //need to go fowards { power(motorXA,.5*Xspeed); power(motorXB,0); }else //need to go backword { power(motorXA,0); power(motorXB,.5*Xspeed); } } if(Xdist==0) { power(motorXA,0); power(motorXB,0); foundX = true; } } } if(!foundY) { if(result==-1) { if(Ydist>0) { posY += 10; Ydist -= 10; //increment the posY for we moved the machine //decrease the value that we still have to go } else { posY -= 10; Ydist += 10; } if(abs(Ydist)<20) { if(Ydist>0) //need to go fowards { power(motorYA,.5*Yspeed); power(motorYB,0); }else //need to go backword { power(motorYA,0); power(motorYB,.5*Yspeed); } } if(Ydist==0) { power(motorYA,0); power(motorYB,0); foundY = true; } } } delay(1); } }
int main(int argc, char **argv) { int ADCvalue01 = 0; int StepSpeed = 100; //Stepping speed (smaler value = faster) int i = 0; int KeyHit = 0; int KeyCode[5]; int SingleKey=0; char TextLine[300]; char FileName[100] = ""; char FileNameOld[100] = ""; char FullFileName[300]; char a; char IsDigit[]="-1234567890"; int ReadState = 0; int MenueLevel = 0; int FileSelected = 0; int FileStartRow = 0; int stopPlot = 0; long xMin = 1000000, xMax = -1000000; long yMin = 1000000, yMax = -1000000; long coordinateCount = 0; long coordinatePlot = 0; long currentPlotX = 0, currentPlotY = 0, currentPlotDown = 1; long xNow = 0, yNow = 0, zNow = 0; char *pEnd; FILE *PlotFile; double Scale = 1.0; double OldScale = 1.0; double PicWidth = 0.0; double PicHeight = 0.0; long MoveLength = 100; long OldMoveLength = 200; long PlotStartTime = 0; int MoveFinished = 0; long stepPause = 5000; long stepPauseNormal = 5000; long stepPauseMaterial = 20000; long zHub = 200; int plotterMode = 1; char FileInfo[3]; long FileSize; long LongTemp; long DataOffset; long HeaderSize; long PictureWidth; long PictureHeight; int IntTemp; int ColorDepth; long CompressionType; long PictureSize; long XPixelPerMeter; long YPixelPerMeter; long ColorNumber; long ColorUsed; int PixelRed, PixelGreen, PixelBlue; int PixOK = 0; long StepsPerPixelX = 50, StepsPerPixelY = 50; long JetOffset1 = 40, JetOffset2 = 40; //Mapping between wiringPi and pin order of my I/O board. //This was necessary, because I used a wrong description of the GPIOs //You have to change the order according to your board! //@@@THESE ARE ALL OUTPUS!! strcpy(FileName, "noFiLE"); if (wiringPiSetup () == -1){ printf("Could not run wiringPiSetup!"); exit(1); } getmaxyx(stdscr, MaxRows, MaxCols); MessageY = MaxRows-3; clrscr(1, MaxRows); PrintRow('-', MessageY - 1); initscr(); noecho(); cbreak(); start_color(); while(!quit) { clearScreen(); char * choices[] = {"Plot File","Manual Control","Servo Control","Opto Sensor Control","X&Y Control","initalize","Exit"}; char *description[] = { "You select a file to plot and will plot the file on the plotter", "Will give you full control over the plotter for debuging or demenstration", "Lets you enter and test different duration of pulses sent to the servo for fine tuning and debugging", "Will read in the togleing of the opto sensor for debuging", "Will let you have control how much to move in x and y by ticks more precisly", "Test initalization procedure", "Will exit the prgram"}; int result = menus("Hello and Welcome to my creation please sleect a mode", choices,description,7,20); switch (result) { case 1: ; /* FILE * fp; char * line = NULL; size_t len = 0; ssize_t read; fp = fopen ("sampleGcode.txt","r");*/ //Plot file char dir[1024]; getcwd(dir,sizeof(dir)); MessageText("3 seconds until plotting starts !!!!!!!!!!!!!!!!!", 1, 2, 0); delay(3000); if((PlotFile=chooseFile(dir))==NULL){ sprintf(TextLine, "Can't open file '%s'!\n", FullFileName); strcpy(FileName, "NoFiLE"); ErrorText(TextLine); } else{ currentPlotX = 0; currentPlotY = 0; PlotStartTime = time(0); PrintMenue_03(FullFileName, coordinateCount, 0, 0, 0, PlotStartTime,Scale); coordinatePlot = 0; stopPlot = 0; if(currentPlotDown == 1){ penMove(1); currentPlotDown = 0; } while(!(feof(PlotFile)) && stopPlot == 0){ fread(&a, 1, 1, PlotFile); if(a == '>'){ ReadState = 0; } if(ReadState == 0 || ReadState == 1){ TextLine[i] = a; TextLine[i+1] = '\0'; i++; } if(ReadState == 2 || ReadState == 3){ if(strchr(IsDigit, a) != NULL){ TextLine[i] = a; TextLine[i+1] = '\0'; i++; } } if(ReadState == 2){ if(strchr(IsDigit, a) == NULL){ if(strlen(TextLine) > 0){ xNow = (strtol(TextLine, &pEnd, 10) - xMin) * 0.33333 * Scale; ReadState = 3; i=0; TextLine[0]='\0'; } } } if(ReadState == 3){ if(strchr(IsDigit, a) == NULL){ if(strlen(TextLine) > 0){ yNow = ((yMax - strtol(TextLine, &pEnd, 10)) - yMin) * 0.33333 * Scale;//Flip around y-axis coordinatePlot++; PrintMenue_03(FullFileName, coordinateCount, coordinatePlot, xNow, yNow, PlotStartTime, Scale); if(stopPlot == 0){ stopPlot =0; moveXY(xNow - currentPlotX, yNow - currentPlotY); currentPlotX = xNow; currentPlotY = yNow; // sprintf(TextLine, "xNow=%ld, yNow=%ld", xNow, yNow); // MessageText(TextLine, MessageX+1, MessageY+1, 0); // getch(); } else{ if(currentPlotDown == 1){ if(plotterMode == 1){ penMove(1); } currentPlotDown = 0; } } if(currentPlotDown == 0){ if(stopPlot == 0){ penMove(0); currentPlotDown = 1; } } ReadState = 2; i=0; TextLine[0]='\0'; } } } if(strcmp(TextLine, "<path") == 0){ if(currentPlotDown == 1){ penMove(1); currentPlotDown = 0; } ReadState = 2; i = 0; TextLine[0]='\0'; } if(a == '<'){ i = 1; TextLine[0] = a; TextLine[1] = '\0'; ReadState = 1; } } fclose(PlotFile); if(currentPlotDown == 1){ penMove(1); currentPlotDown = 0; } PrintMenue_03(FullFileName, coordinateCount, coordinatePlot, 0, 0, PlotStartTime,Scale); moveXY(-currentPlotX, -currentPlotY); currentPlotX = 0; currentPlotY = 0; while(kbhit()){ getch(); } MessageText("Finished! Press any key to return to main menu.", MessageX, MessageY, 0); getch(); break; } break; case 2: manualControl(); break; case 3: servoControl(); break; case 4: optoControl(); break; case 5: xyControl(); break; case 6: initalize(); break; case -1: default: system("reset"); quit=true; break; } } allSTOP(); endwin(); return 0; }