Esempio n. 1
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    int i, j, k;
    System.out.println("Starting painting");
    // draw sets

    if (firstTimeAround) {
      drawSet(g2);
      render();
      viewer.save("final_product_full.png");
      firstTimeAround = false;
    }
    // render();
    /* for(i=0;i<viewer.getWidth();i++){
        for(j=0;j<viewer.getHeight();j++){
            viewer.setPixel(i,j,Color3.BLACK);
        }
    }
    */

    g2.setBackground(Color.BLACK);

    //        if(newRender){
    for (i = minX; i < maxX; i++) {
      // System.out.println("line "+i);
      for (j = minY; j < maxY; j++) {

        g2.setColor(
            new Color(
                (float) viewer.getPixel(i, j).getR(),
                (float) viewer.getPixel(i, j).getG(),
                (float) viewer.getPixel(i, j).getB()));
        // g2.drawLine(i,j,1,1);
        Ellipse2D.Double node_circ = new Ellipse2D.Double(i, j, 1, 1);
        g2.fill(node_circ);

        g2.setColor(Color.BLACK);

        // if(j*scale<viewer.getHeight()){
        //       j=0;//viewer.getHeight();
        // }

      }
      // if(i*scale<viewer.getWidth()){
      //    i=0;//viewer.getWidth();
      //  }
    }

    //  g2.drawImage(viewer.1)
    newRender = false;
    // }
    System.out.println("end painting");
  }
Esempio n. 2
0
  void render() {
    Color3 endColor = Color3.BLACK;
    System.out.println("RE calculating the image");
    int i, j, k;
    for (i = 0; i < viewer.getWidth(); i++) {
      for (j = 0; j < viewer.getHeight(); j++) {
        endColor = Color3.BLACK;
        for (k = 0; k < numScreens; k++) {
          float tempr =
              ((float) screens[k].getPixel(i, j).getR())
                  * ((float) ((instrument) proj_class.instruments.get_object(k)).getLevel()
                      / (float) 100.0);
          float tempg =
              ((float) screens[k].getPixel(i, j).getG())
                  * ((float) ((instrument) proj_class.instruments.get_object(k)).getLevel()
                      / (float) 100.0);
          float tempb =
              ((float) screens[k].getPixel(i, j).getB())
                  * ((float) ((instrument) proj_class.instruments.get_object(k)).getLevel()
                      / (float) 100.0);
          if ((tempr != 0) || (tempg != 0) || (tempb != 0)) {

            float newr = tempr + (float) endColor.getR();
            float newg = tempg + (float) endColor.getG();
            float newb = tempb + (float) endColor.getB();
            if (newr > 1) {
              newr = 1;
            }
            if (newg > 1) {
              newg = 1;
            }
            if (newb > 1) {
              newb = 1;
            }
            endColor = new Color3(newr, newg, newb);
          }
        }
        viewer.setPixel(i, j, endColor.toRGB());
      }
    }
    newRender = true;
    repaint();
  }
Esempio n. 3
0
  public void loadData() {
    //    if(!dataLoaded){

    scale = 1;
    maxX = 0;
    maxY = 0;
    minX = 640;
    minY = 480;
    numScreens = proj_class.instruments.get_num_objects();

    screens = new Bitmap[numScreens];
    levels = new int[numScreens];

    int i;
    for (i = 0; i < (proj_class.instruments.get_num_objects()); i++) {
      ((instrument) proj_class.instruments.get_object(i)).setLevel(100);
    }

    for (i = 0; i < numScreens; i++) {
      screens[i] = new Bitmap(640, 480, false);
      int x, y;
      for (x = 0; x < 640; x++) {
        for (y = 0; y < 480; y++) {
          screens[i].setPixel(x, y, Color3.BLACK);
        }
      }

      levels[i] = 0;
      int j;
      for (j = 0; j < proj_class.photonmap.getStoredPhotons(); j++) {
        Photon pho = proj_class.photonmap.getPhoton(j);
        if (pho != null) {
          if (pho.lightSource == i) {

            screens[i].setPixel((int) pho.x, 480 - (int) pho.z, new Color3(pho.R, pho.G, pho.B));
            if ((int) pho.x > maxX) {
              maxX = (int) pho.x;
            }
            if ((480 - (int) pho.z) > maxY) {
              maxY = (480 - (int) pho.z);
            }
            if ((int) pho.x < minX) {
              minX = (int) pho.x;
            }
            if ((480 - (int) pho.z) < minY) {
              minY = (480 - (int) pho.z);
            }
          }
        }
      }

      screens[i].save("lightscreen" + i + ".png");
    }
    viewer = new Bitmap(640, 480, false);
    int j;
    for (i = 0; i < viewer.getWidth(); i++) {
      for (j = 0; j < viewer.getHeight(); j++) {
        viewer.setPixel(i, j, Color3.BLACK);
      }
    }
    //            dataLoaded=true;
    //      }
    int tempx = 0;
    int tempy = 0;
    if (maxX != 0) {
      tempx = 640 / maxX;
    }

    if (maxY != 0) {
      tempy = 480 / maxY;
    }

    if (tempx > 0) {
      if (tempx > tempy) {
        scale = tempx;
      }
    }
    if (tempy > 0) {
      if (tempy > tempx) {
        scale = tempy;
      }
    }
  }