Beispiel #1
0
static void PlotAll (Scene& scene, Plotter& plotter)
{
  Vector x(1,steps), Pot(1,steps);
  for (int i = 1; i <= steps; i++) {
    x(i) = xmin + (i-1)*(xmax-xmin)/(steps-1);
    Pot(i) = V(x(i));
  }
  plotter.clear();
  double ymin = -1, ymax = min(6.0,max(1.0,Max(Pot))); // betwwen 1 and 6 !!
  plotter.axisframe(xmin,xmax,ymin,ymax, "x","V(x), Psi(x)");
  plotter.style(plotter.LINES);

  plotter.plot(x,Pot);			// potential
  scene.Line(xmin,ymin,xmin,ymax);
  scene.Line(xmax,ymin,xmax,ymax);

  scene.SetColor(ColorB(255,0,0));	// wave function
  plotter.plot(x,Psi);

  scene.SetColor(ColorB(0,0,255));	// eigen energy
  scene.Line(xmin,E,xmax,E);	
  scene.SetTextStyle(Standard);
  char label[60];
  sprintf(label,"E=%.8g",E);
  scene.Write(xmin+0.01,E+0.05,label);
}
Beispiel #2
0
 void paddleType::erase (Plotter& g)
 {
     if (oldLoc.getX() != loc.getX())
     {
         g.setColor(black);
         for(int i = -width/2; i <= width/2; i ++)
         {
             g.plot(oldLoc.getX() + i, oldLoc.getY(), SQUARE);
         }
     }
 }
Beispiel #3
0
 void paddleType::draw (Plotter& g)
 {
     if (oldLoc.getX() != loc.getX())
     {
         g.setColor(color);
         for(int i = -width/2; i <= width/2; i ++)
         {
             g.plot(loc.getX() + i, loc.getY(), SQUARE);
         }
     }
     oldLoc = loc;
 }
void Ship::Draw(double x, double y)
{
    // draw ship
    Plotter p;




    for (int r = 0; r < 5; r++)
    {
        for (int c = 0; c < 5; c++)
        {
            p.setColor(rocket[r][c]);
            p.plot(x + c, y + r, SQUARE);
        }
    }

}
//Picture that prints rocket
void printPicture(char ch)
{
    Plotter screen;
    int x=200;
    int y=200;

    if(ch=='@')
      {
          screen.setColor(darkgreen);
          screen.plot(x,y,SQUARE);
          x++;
          y++;
      }
      else if(ch=='0')
      {
          screen.setColor(darkgreen);
          screen.plot(x,y,SQUARE);
          x++;
          y++;

      }
       else if(ch=='8')
      {
          screen.setColor(green);
          screen.plot(x,y,SQUARE);
          x++;
          y++;

      }
       else if(ch=='b')
      {
          screen.setColor(blue);
          screen.plot(x,y,SQUARE);
          x++;
          y++;

      }
       else if(ch=='C')
      {
          screen.setColor(yellow);
          screen.plot(x,y,SQUARE);
          x++;
          y++;

      }
       else if(ch=='G')
      {
          screen.setColor(darkyellow);
          screen.plot(x,y,SQUARE);
          x++;
          y++;

      }
      else if(ch=='O')
      {
          screen.setColor(black);
          screen.plot(x,y,SQUARE);
          x++;
          y++;
      }


      else if(ch=='#')
      {
          screen.setColor(red);
          screen.plot(x,y,SQUARE);
          x++;
          y++;
      }
      else if (ch==';')
      {
          screen.setColor(red);
          screen.plot(x,y,SQUARE);
          x++;
          y++;
      }

      else if(ch==',')
      {
          screen.setColor(white);
          screen.plot(x,y,SQUARE);
          x++;
          y++;
      }

      else if(ch=='+')
      {
        screen.setColor(grey);
         screen.plot(x,y,SQUARE);
         x++;
          y++;
      }
      else if(ch=='`')
      {
         screen.setColor(grey);
         screen.plot(x,y,SQUARE);
         x++;
         y++;
      }
      else if (ch=='.')
      {
         screen.setColor(lightgrey);
         screen.plot(x,y,SQUARE);
         x++;
         y++;
      }
       else if (ch=='B')
      {
         screen.setColor(cyan);
         screen.plot(x,y,SQUARE);
         x++;
         y++;
      }
      else if (ch=='W')
      {
         screen.setColor(white);
         screen.plot(x,y,SQUARE);
         x++;
         y++;
      }
      else if (ch=='w')
      {
         screen.setColor(white);
         screen.plot(x,y,SQUARE);
         x++;
         y++;
      }
       else if(ch=='*')
      {
          cout<<endl;
          x++;
          y++;
      }
      else if (ch==' ')
      {
          screen.setColor(black);
          screen.plot(x,y,SQUARE);
          x++;
          y++;
      }
}
Beispiel #6
0
int main(int argc, char *argv[]) {
  FILE* fp = fopen("config.txt", "r");
  if (fp) {
    int a, b;
    if (fscanf(fp," cores %d", &a) == 1) plotter.n_threads = a;
    if (fscanf(fp," def_res %d %d", &a, &b) == 2) {
      gfx.screen_w_default = a;
      gfx.screen_h_default = b;
    }
    if (fscanf(fp," max_iter %d", &a) == 1) plotter.max_iter = a;
  }

  if (SDL_Init(SDL_INIT_EVERYTHING) == -1 || !gfx.init()) return 1;

  plotter.init();
  plotter.resize(gfx.get_screen_w(), gfx.get_screen_h());
  plotter.plot();

  while (true) {
    frame_time = SDL_GetTicks();
    input.update();

    if (input.key_pressed(SDLK_ESCAPE) || input.is_quitting())
      break;

    if (input.key_down( SDLK_LCTRL ) &&
               input.mouse_pressed(SDL_BUTTON_LEFT)) {
      plotter.center();
    } else if (input.mouse_pressed(SDL_BUTTON_LEFT)) {
      if (input.key_down(SDLK_LSHIFT)) {
        plotter.zoom(zoom_factor * 5);
      } else {
        plotter.zoom(zoom_factor);
      }
    } else if (input.mouse_pressed(SDL_BUTTON_RIGHT)) {
      if (input.key_down(SDLK_LSHIFT)) {
        plotter.zoom(1/(zoom_factor * 5));
      } else {
        plotter.zoom(1/zoom_factor);
      }
    }

    if (input.key_pressed(SDLK_f)) {
      plotter.end_plotting();
      gfx.toggle_fullscreen();
      plotter.resize(gfx.get_screen_w(), gfx.get_screen_h());
      plotter.plot();
      //zoom_on();
    }

    if (input.key_pressed(SDLK_p)) {
      plotter.print_pos();
    }

    gfx.update();
    int time_rem = 1000 / FPS - (SDL_GetTicks() - frame_time);
    if (time_rem >= 5)
      SDL_Delay(time_rem);
  }
  plotter.end_plotting();

  SDL_Quit();
  return 0;
}