Esempio n. 1
0
  public void paint(Graphics g) {
    g.setColor(Color.pink);

    g.drawRect(40, 40, 80, 80);
    g.drawLine(80, 10, 40, 40);
    g.drawLine(80, 10, 120, 40);
    g.drawRect(70, 80, 20, 40);
  }
Esempio n. 2
0
  protected void drawVectors(Graphics g, Rectangle w) {

    int ix0, iy0;
    int ix1, iy1;

    double x0, y0, x1, y1, dx, dy;

    //      Is there any data to draw? Sometimes the draw command will
    //      will be called before any data has been placed in the class.

    if (data == null || data.length < stride) return;

    //      Lets draw the vectors

    for (int i = 0; i < length; i += stride) {

      x0 = data[i];
      y0 = data[i + 1];
      dx = data[i + 2] * getScaleFactor();
      dy = data[i + 3] * getScaleFactor();

      x1 = x0 + dx;
      y1 = y0 + dy;

      if (inside(x0, y0) || inside(x1, y1)) {

        ix0 = (int) (w.x + ((x0 - xmin) / xrange) * w.width);
        iy0 = (int) (w.y + (1.0 - (y0 - ymin) / yrange) * w.height);

        ix1 = (int) (w.x + ((x1 - xmin) / xrange) * w.width);
        iy1 = (int) (w.y + (1.0 - (y1 - ymin) / yrange) * w.height);

        g.drawLine(ix0, iy0, ix1, iy1);

        /*
         ** Now draw the head of the vector. To avoid scaling problems
         ** the head is drawn using pixel units. This would not work
         ** if we had multiple output devices.
         */

        dx = (double) (ix1 - ix0);
        dy = (double) (iy1 - iy0);

        ix0 = ix1 - (int) (0.25 * (dx - dy) + 0.5);
        iy0 = iy1 - (int) (0.25 * (dx + dy) + 0.5);

        g.drawLine(ix0, iy0, ix1, iy1);

        ix0 = ix1 - (int) (0.25 * (dx + dy) + 0.5);
        iy0 = iy1 - (int) (0.25 * (-dx + dy) + 0.5);

        g.drawLine(ix0, iy0, ix1, iy1);
      }
    }
  }
Esempio n. 3
0
 void PressedRect(Graphics g, int x, int y, int w, int h) {
   Color dg = new Color(128, 128, 128);
   g.setColor(Color.lightGray);
   g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1);
   g.setColor(dg);
   g.drawLine(x, y, x + w - 1, y);
   g.drawLine(x, y, x, y + h - 1);
   g.setColor(Color.black);
   g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
   g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
   g.setColor(Color.white);
   g.drawLine(x + w, y, x + w, y + h);
   g.drawLine(x + w, y + h, x, y + h);
 }
Esempio n. 4
0
  public void draw(Graphics g) {
    animate();

    g.setColor(Color.black);
    g.fillRect(0, 0, dim.width, dim.height);
    g.setColor(Color.white);

    numpaint++;
    DebugPrinter dbg = new DebugPrinter(g, 50, 60);
    dbg.print(
        "Spring-mass demo by yigal irani, drag balls or create new ones by clicking inside box");
    dbg.print("frame", numpaint);
    dbg.print("fps", 1 / timer.time_diff);

    Point top_left = point_by_vec(new Vec(-1, 1));
    g.draw3DRect(top_left.x, top_left.y, screen_dist(2), screen_dist(2), true);
    for (int i = 0; i < springs.size(); i++) {
      Spring spring = springs.get2(i);
      Point p1 = point_by_vec(balls.get2(spring.start).pos);
      Point p2 = point_by_vec(balls.get2(spring.end).pos);
      g.drawLine(p1.x, p1.y, p2.x, p2.y);
    }
    for (int i = 0; i < balls.size(); i++) {
      Ball ball = balls.get2(i);
      Point p = point_by_vec(ball.pos);
      int screen_radius = screen_dist(RADIUS);
      g.setColor(Color.blue);
      g.fillOval(p.x - screen_radius, p.y - screen_radius, screen_radius * 2, screen_radius * 2);

      g.setColor(Color.white);
      g.drawOval(p.x - screen_radius, p.y - screen_radius, screen_radius * 2, screen_radius * 2);

      g.drawString("" + i, p.x, p.y);
    }
  }
 public void paint(Graphics g) {
   msg = this.getParameter("p1");
   System.out.println("paint...");
   g.setColor(Color.red);
   g.drawLine(10, 20, 50, 50);
   g.drawString(msg, 100, 200);
 }
Esempio n. 6
0
  public void run() {
    int i = -1, tx = -1, ty = -1, alive_cnt;
    int[] dx = {0, 1, 0, -1};
    int[] dy = {-1, 0, 1, 0};
    Graphics g = getGraphics();

    while (true) {
      try {
        alive_cnt = 0;
        for (i = 0; i < NUM_PLAYERS; i++) {
          if (palive[i] == 1) {
            if (i > 0) DoAI(i);
            tx = px[i] + dx[pdir[i]];
            ty = py[i] + dy[pdir[i]];
            if ((tx < 0)
                || (tx >= SIZE_X)
                || (ty < 0)
                || (ty >= SIZE_Y)
                || (map[tx + ty * SIZE_X] != 0)) {
              palive[i] = 0;
            } else {
              px[i] = tx;
              py[i] = ty;
              map[tx + ty * SIZE_X] = (byte) (i + 1);
            }
          }
          if (palive[i] == 1) {
            alive_cnt++;
            g.setColor(new Color(pcolor[i]));
            g.drawLine(px[i], py[i], px[i], py[i]);
          }
        }
        if (palive[0] == 0) {
          g.setColor(new Color(0xff7070));
          g.drawString("You Lose!", 50, 120);
          repaint();
          stop();
        } else if (alive_cnt == 1) {
          g.setColor(new Color(0x7070ff));
          g.drawString("You Win!", 50, 120);
          repaint();
          stop();
        }

        repaint();
        Thread.sleep(25);
      } catch (InterruptedException e) {

        g.drawString("IException!", 50, 100);
        repaint();
        stop();
      } catch (Exception e) {
        g.drawString("Exception:" + e.toString() + "\n", 50, 100);
        repaint();
      }
    }
  }
Esempio n. 7
0
 public static void drawWindows(Graphics g) {
   g.setColor(Color.black);
   g.drawRect(220, 220, 60, 60);
   g.drawLine(220, 250, 280, 250);
   g.drawLine(250, 220, 250, 280);
   g.drawRect(420, 220, 60, 60);
   g.drawLine(420, 250, 480, 250);
   g.drawLine(450, 220, 450, 280);
   g.drawRect(320, 220, 60, 60);
   g.drawLine(320, 250, 380, 250);
   g.drawLine(350, 220, 350, 280);
   g.drawRect(220, 320, 60, 60);
   g.drawLine(220, 350, 280, 350);
   g.drawLine(250, 320, 250, 380);
   g.drawRect(420, 320, 60, 60);
   g.drawLine(420, 350, 480, 350);
   g.drawLine(450, 320, 450, 380);
 }
Esempio n. 8
0
  public static int drawTree(Graphics g, int left, int right, int n, int x1, int y1) {
    int x2 = (left + right) / 2;
    int y2 = y1 + 70;
    if (n < number) {
      g.drawLine(x1, y1, x2, y2);
      g.drawString(String.valueOf(n), x2 - 10, y2 + 10);
    } else g.drawString(String.valueOf(n), x2 - 10, y2);

    if (n == 0 || n == 1) return n;
    else return drawTree(g, left, x2, n - 1, x2, y2) + drawTree(g, x2, right, n - 2, x2, y2);
  }
  /** Paint it. */
  public void paint(Graphics g) {
    Dimension d = getSize();
    g.setColor(Color.black);
    int xoff = d.width / 3;
    int yoff = d.height / 3;
    g.drawLine(xoff, 0, xoff, d.height);
    g.drawLine(2 * xoff, 0, 2 * xoff, d.height);
    g.drawLine(0, yoff, d.width, yoff);
    g.drawLine(0, 2 * yoff, d.width, 2 * yoff);

    int i = 0;
    for (int r = 0; r < 3; r++) {
      for (int c = 0; c < 3; c++, i++) {
        if ((white & (1 << i)) != 0) {
          g.drawImage(notImage, c * xoff + 1, r * yoff + 1, this);
        } else if ((black & (1 << i)) != 0) {
          g.drawImage(crossImage, c * xoff + 1, r * yoff + 1, this);
        }
      }
    }
  }
Esempio n. 10
0
  public void paint(Graphics g) {

    // double p = 1000;
    // double m = 100;
    double nr = r / 12;
    double b = 0;
    int v = 0;
    g.setColor(new Color(255, 255, 255));
    g.fillRect(0, 0, 500, 300);

    g.setColor(new Color(0, 0, 255));
    g.drawRect(0, 10, 400, 210);
    g.drawLine(0, 50, 400, 50);
    g.drawLine(0, 85, 400, 85);
    g.drawLine(0, 120, 400, 120);
    g.drawLine(0, 155, 400, 155);
    g.drawLine(0, 190, 400, 190);

    g.setColor(new Color(0, 0, 0));
    g.drawString("INITIAL INVESTMENT = $" + p, 20, 50);
    g.drawString("MONTHY INVESTMENT = $" + m, 20, 85);
    g.drawString("INTEREST RATE = " + r, 20, 120);
    g.drawString("YEARS OF INVESTMENT = " + y, 20, 155);

    double n = 0;
    b = p;
    while (n < (y * 12)) {
      b = (b * (1 + nr)) + m;

      n++;
    }
    n = 0;
    v = (int) b;
    g.setColor(new Color(255, 0, 0));
    g.drawString("ENDING BALANCE= $" + v, 20, 190);
  } // end paint
Esempio n. 11
0
  public void drawVertArrow(Graphics g, int x1, int y1, int x2, int y2) {
    g.drawLine(x1, y1, x2, y2);

    int[] axPoints = new int[3];
    int[] ayPoints = new int[3];

    axPoints[0] = x2;
    ayPoints[0] = y2;
    axPoints[1] = x2 - 1;
    ayPoints[1] = y2 - 2;
    axPoints[2] = x2 + 2;
    ayPoints[2] = y2 - 2;

    g.fillPolygon(axPoints, ayPoints, 3);
  }
Esempio n. 12
0
  public void paint(Graphics g) {
    g.setFont(bigFont);
    g.drawString("Shapes and Colors", 80, 20);

    g.setColor(redColor);

    g.drawRect(100, 100, 100, 100);

    g.fillRect(110, 110, 80, 80);
    g.setColor(weirdColor);
    g.fillArc(120, 120, 60, 60, 0, 360);
    g.setColor(Color.yellow);
    g.drawLine(140, 140, 160, 160);
    g.setColor(Color.black);
  }
Esempio n. 13
0
 public void drawBomb(Graphics g, int x, int y) {
   Color c = g.getColor();
   g.setColor(new Color(128, 128, 128));
   g.drawLine(x + 2, y + 7, x + 12, y + 7);
   g.drawLine(x + 7, y + 2, x + 7, y + 12);
   g.fillRect(x + 6, y + 4, 3, 7);
   g.fillRect(x + 4, y + 6, 7, 3);
   g.setColor(Color.black);
   g.fillRect(x + 5, y + 5, 5, 5);
   g.drawLine(x + 3, y + 7, x + 11, y + 7);
   g.drawLine(x + 7, y + 3, x + 7, y + 11);
   g.drawLine(x + 4, y + 4, x + 4, y + 4);
   g.drawLine(x + 4, y + 10, x + 4, y + 10);
   g.drawLine(x + 10, y + 4, x + 10, y + 4);
   g.drawLine(x + 10, y + 10, x + 10, y + 10);
   g.setColor(Color.white);
   g.drawLine(x + 6, y + 6, x + 6, y + 6);
   g.setColor(c);
 }
Esempio n. 14
0
  public void paint(Graphics g) {
    // clears the area that the pannel is on
    gBuffer.setColor(Color.white);
    gBuffer.fillRect(0, 0, 65, 415);

    // pannel
    gBuffer.setColor(Color.black);
    gBuffer.drawRect(5, 15, 60, 400);

    // color buttons
    gBuffer.setColor(Color.black); // first column
    gBuffer.fillRect(15, 20, 20, 20);
    gBuffer.setColor(Color.red);
    gBuffer.fillRect(15, 40, 20, 20);
    gBuffer.setColor(Color.blue);
    gBuffer.fillRect(15, 60, 20, 20);
    gBuffer.setColor(Color.green);
    gBuffer.fillRect(15, 80, 20, 20);
    gBuffer.setColor(Color.yellow);
    gBuffer.fillRect(15, 100, 20, 20);
    gBuffer.setColor(Color.gray); // second column
    gBuffer.fillRect(35, 20, 20, 20);
    gBuffer.setColor(Color.magenta);
    gBuffer.fillRect(35, 40, 20, 20);
    gBuffer.setColor(Color.cyan);
    gBuffer.fillRect(35, 60, 20, 20);
    gBuffer.setColor(Color.orange);
    gBuffer.fillRect(35, 80, 20, 20);
    gBuffer.setColor(Color.pink);
    gBuffer.fillRect(35, 100, 20, 20);
    gBuffer.setColor(Color.black); // draw first column button outlines
    gBuffer.drawRect(15, 20, 20, 20);
    gBuffer.drawRect(15, 40, 20, 20);
    gBuffer.drawRect(15, 60, 20, 20);
    gBuffer.drawRect(15, 80, 20, 20);
    gBuffer.drawRect(15, 100, 20, 20);
    gBuffer.fillRect(15, 20, 20, 20);
    gBuffer.drawRect(35, 20, 20, 20); // draw second column button outlines
    gBuffer.drawRect(35, 40, 20, 20);
    gBuffer.drawRect(35, 60, 20, 20);
    gBuffer.drawRect(35, 80, 20, 20);
    gBuffer.drawRect(35, 100, 20, 20);

    // pen button design
    gBuffer.setColor(Color.black);
    gBuffer.drawRect(23, 125, 3, 20);
    penta = new Polygon();
    penta.addPoint(23, 145);
    penta.addPoint(26, 145);
    penta.addPoint(25, 148);
    gBuffer.drawPolygon(penta);

    // brush button design
    gBuffer.setColor(Color.gray);
    gBuffer.fillRect(45, 128, 3, 10);
    penta = new Polygon();
    penta.addPoint(45, 138);
    penta.addPoint(48, 138);
    penta.addPoint(51, 141);
    penta.addPoint(42, 141);
    gBuffer.drawPolygon(penta);
    gBuffer.setColor(Color.black);
    gBuffer.drawRect(42, 141, 9, 5);
    gBuffer.drawLine(45, 146, 45, 144);
    gBuffer.drawLine(48, 146, 48, 143);

    // roller button design
    gBuffer.setColor(Color.black); // handle
    gBuffer.fillRect(23, 155, 3, 10);
    gBuffer.drawRect(19, 165, 9, 4);
    gBuffer.setColor(Color.white); // roller front
    gBuffer.fillOval(27, 166, 4, 4);
    gBuffer.setColor(Color.black); // roller round side
    gBuffer.drawOval(27, 166, 3, 3);

    // spray paint button design
    gBuffer.setColor(Color.black); // top of can
    penta = new Polygon();
    penta.addPoint(43, 156);
    penta.addPoint(48, 160);
    penta.addPoint(43, 163);
    gBuffer.drawPolygon(penta);
    gBuffer.setColor(Color.blue); // spray button
    gBuffer.fillRect(42, 155, 2, 3);
    for (int n = 0; n <= 20; n++) // paint spray
    {
      x = 39 + ((int) (3 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
      y = 157 + ((int) (3 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
      gBuffer.fillRect(x, y, 1, 1);
    }
    penta = new Polygon(); // can
    penta.addPoint(43, 163);
    penta.addPoint(48, 160);
    penta.addPoint(53, 172);
    penta.addPoint(48, 177);
    gBuffer.fillPolygon(penta);
    gBuffer.setColor(Color.black);
    gBuffer.drawPolygon(penta);

    // rubber band drawing button design (20,185,30,205);
    gBuffer.setColor(Color.black);
    for (int a = 18, b = 200; a <= 35; a += 4, b += 2) {
      gBuffer.drawLine(18, 183, a, b);
    }

    // eraser button design
    gBuffer.setColor(Color.yellow); // top
    penta = new Polygon();
    penta.addPoint(45, 185);
    penta.addPoint(50, 185);
    penta.addPoint(45, 200);
    penta.addPoint(40, 200);
    gBuffer.fillPolygon(penta);
    gBuffer.setColor(Color.black); // outline
    gBuffer.drawPolygon(penta);
    gBuffer.setColor(Color.yellow); // side
    penta = new Polygon();
    penta.addPoint(50, 185);
    penta.addPoint(45, 200);
    penta.addPoint(48, 204);
    penta.addPoint(52, 189);
    gBuffer.fillPolygon(penta);
    gBuffer.setColor(Color.black); // outline
    gBuffer.drawPolygon(penta);
    penta = new Polygon(); // front
    penta.addPoint(40, 200);
    penta.addPoint(45, 200);
    penta.addPoint(48, 204);
    penta.addPoint(43, 204);
    gBuffer.drawPolygon(penta);

    // clear button design
    gBuffer.setColor(Color.black);
    gBuffer.setFont(new Font("Arial", Font.BOLD, 20));
    gBuffer.drawString("Clear", 10, 239);
    gBuffer.drawRect(10, 220, 50, 25);

    gBuffer.setColor(Color.cyan);
    switch (numSize) {
      case 1:
        gBuffer.drawRect(15, 120, 20, 30);
        break;
      case 2:
        gBuffer.drawRect(35, 120, 20, 30);
        break;
      case 3:
        gBuffer.drawRect(15, 150, 20, 30);
        break;
      case 4:
        gBuffer.drawRect(35, 150, 20, 30);
        break;
      case 5:
        gBuffer.drawRect(15, 180, 20, 30);
        break;
      case 6:
        gBuffer.drawRect(35, 180, 20, 30);
        break;
    }

    if ((numSize == 4) || (numSize == 6)) {
      // draw different size buttons for spray paint, eraser, and rubber band
      gBuffer.setColor(Color.white);
      gBuffer.fillRect(20, 265, 35, 75);
      gBuffer.setColor(Color.cyan);
      switch (size) {
        case 1:
          gBuffer.drawRect(26, 271, 18, 18);
          break;
        case 2:
          gBuffer.drawRect(26, 291, 18, 18);
          break;
        case 3:
          gBuffer.drawRect(26, 311, 18, 18);
      }
      gBuffer.setColor(Color.black);
      gBuffer.drawRect(20, 265, 30, 70); // size pannel
      gBuffer.drawRect(25, 270, 20, 20); // small
      gBuffer.drawRect(25, 290, 20, 20); // medium
      gBuffer.drawRect(25, 310, 20, 20); // large

      if (numSize == 4) {
        for (int n = 0; n <= 20; n++) {
          x = 35 + ((int) (4 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
          y = 280 + ((int) (4 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
          gBuffer.fillRect(x, y, 1, 1);
        }
        for (int n = 0; n <= 40; n++) {
          x = 34 + ((int) (6 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
          y = 300 + ((int) (6 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
          gBuffer.fillRect(x, y, 1, 1);
        }
        for (int n = 0; n <= 70; n++) {
          x = 35 + ((int) (8 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
          y = 319 + ((int) (8 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
          gBuffer.fillRect(x, y, 1, 1);
        }
        switch (size) {
          case 1:
            s = 4;
            break;
          case 2:
            s = 6;
            break;
          case 3:
            s = 8;
        }
      } else if (numSize == 6) {
        gBuffer.drawRect(33, 278, 4, 4);
        gBuffer.drawRect(32, 297, 7, 7);
        gBuffer.drawRect(30, 315, 10, 10);

        switch (size) {
          case 1:
            s = 4;
            break;
          case 2:
            s = 7;
            break;
          case 3:
            s = 10;
        }
      }
    } else {
      gBuffer.setColor(Color.white);
      gBuffer.fillRect(20, 265, 35, 75);
    }

    // draw pannel and buttons
    g.drawImage(virtualMem, 0, 0, this);

    // changing what color it draws with
    switch (numColor) {
      case 1:
        gBuffer.setColor(Color.black);
        break;
      case 2:
        gBuffer.setColor(Color.red);
        break;
      case 3:
        gBuffer.setColor(Color.blue);
        break;
      case 4:
        gBuffer.setColor(Color.green);
        break;
      case 5:
        gBuffer.setColor(Color.yellow);
        break;
      case 6:
        gBuffer.setColor(Color.gray);
        break;
      case 7:
        gBuffer.setColor(Color.magenta);
        break;
      case 8:
        gBuffer.setColor(Color.cyan);
        break;
      case 9:
        gBuffer.setColor(Color.orange);
        break;
      case 10:
        gBuffer.setColor(Color.pink);
        break;
      case 11:
        gBuffer.setColor(Color.white);
        break;
      default:
        gBuffer.setColor(Color.black);
    }

    // changing how it draws
    switch (numDraw) {
      case 1: // clear drawing
        gBuffer.setColor(Color.white);
        gBuffer.fillRect(0, 0, appletWidth, appletHeight);
        g.drawImage(virtualMem, 0, 0, this);
        numDraw = 0;
        repaint();
        break;
      default:
        switch (numSize) {
          case 1: // draw with pen
            if (!first) {
              gBuffer.drawLine(oldX, oldY, newX, newY);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 2: // draw with brush
            if (!first) {
              gBuffer.fillRect(oldX, oldY, 4, 4);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 3: // draw with roller
            if (!first) {
              gBuffer.fillRect(oldX, oldY, 10, 10);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 4: // draw with spray paint
            if (!first) {
              for (int n = 0; n <= 20; n++) {
                x = oldX + ((int) (s * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
                y = oldY + ((int) (s * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
                gBuffer.fillRect(x, y, 1, 1);
                g.drawImage(virtualMem, 0, 0, this);
              }
            } else first = false;

            break;
          case 5: // draw with rubber band style
            if (!first) {
              gBuffer.drawLine(startX, startY, endX, endY);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 6: // eraser drawer
            if (!first) {
              gBuffer.fillRect(oldX, oldY, s, s);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          default: // default to drawing with pen
            if (!first) {
              gBuffer.drawLine(oldX, oldY, newX, newY);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
        }
    }
  }
Esempio n. 15
0
  /**
   * Draw a legend for this Vector set
   *
   * @param g Graphics context
   * @param w Data Window
   */
  protected void draw_legend(Graphics g, Rectangle w) {
    Color c = g.getColor();
    TextLine value = new TextLine();
    double dx;
    int ix, iy;
    int length;

    if (!drawlegend) return;
    /*
     ** Calculate the vector magnitude of a line legend_length
     ** pixels long. This will be our standard vector
     */

    dx = xrange * ((double) legend_length) / ((double) w.width) / getScaleFactor();

    value.parseDouble(dx, 3);
    /*
     ** Calculate the length of the legend
     */
    length = legend_length + value.getWidth(g) + value.charWidth(g, ' ');
    /*
     ** Calculate the position of the legend if needed.
     */

    if (legend_ix == 0 && legend_iy == 0) {
      legend_ix = (int) (w.x + ((legend_dx - xmin) / xrange) * w.width);
      legend_iy = (int) (w.y + (1.0 - (legend_dy - ymin) / yrange) * w.height);
    } else if (legend_ix == -1 && legend_iy == -1) {
      legend_ix = w.x + w.width / 2 - length / 2;
      legend_iy = w.y - value.getAscent(g) / 2;
    }

    /*
     ** In what follows the vector tail is the zero point. It is on
     ** the right - the vector points to the left
     */
    if (linecolor != null) g.setColor(linecolor);
    /*
     ** Draw the standard vector
     */

    g.drawLine(legend_ix, legend_iy, legend_ix + legend_length, legend_iy);

    ix = legend_ix + (int) (0.25 * (double) legend_length + 0.5);
    iy = legend_iy - (int) (0.25 * (double) legend_length + 0.5);

    g.drawLine(legend_ix, legend_iy, ix, iy);

    ix = legend_ix + (int) (0.25 * (double) legend_length + 0.5);
    iy = legend_iy + (int) (0.25 * (double) legend_length + 0.5);

    g.drawLine(legend_ix, legend_iy, ix, iy);
    /*
     ** Add the value of the standard vector. To the right of the vector
     */
    value.draw(g, legend_ix + legend_length + value.charWidth(g, ' '), iy, TextLine.LEFT);
    /*
     ** Add any legend text (above the vector) that might have been
     ** defined.
     */

    g.setColor(c);

    if (legend_text != null && !legend_text.isNull()) {

      legend_text.draw(
          g,
          legend_ix + length / 2,
          iy - value.getAscent(g) - legend_text.getDescent(g) - legend_text.getLeading(g),
          TextLine.CENTER);
    }
  }
Esempio n. 16
0
  public void paint(Graphics g) {

    // Draw Grid
    g.drawRect(10, 10, 780, 580);
    g.drawLine(400, 10, 400, 590);
    g.drawLine(10, 300, 790, 300);

    Random rnd = new Random(1234);
    for (int k = 10; k <= 400; k += 10) { // The first box lines
      g.drawLine(k, 20, k, 290);
    } // The dimentions of the lines
    for (int k = 10; k <= 290; k += 10) { // The second box lines
      g.drawLine(420, k, 770, k); // The dimestions
      int red = rnd.nextInt(256); // The colors
      int green = rnd.nextInt(256);
      int blue = rnd.nextInt(256);
      g.setColor(new Color(red, green, blue)); // The randomness of colors
    }
    for (int k = 1; k <= 100; k++) { // The 3rd circles
      int x = rnd.nextInt(330); // the random of x lo
      int y = rnd.nextInt(230); // the randm of y
      int red = rnd.nextInt(256); // the random of colors
      int green = rnd.nextInt(256);
      int blue = rnd.nextInt(256);
      g.setColor(new Color(red, green, blue));
      g.fillOval(x + 10, y + 300, 50, 50);
    } // the place of all the ovals

    Polygon side1 = new Polygon(); // blue side of cube
    side1.addPoint(600, 410);
    side1.addPoint(635, 410);
    side1.addPoint(635, 480);
    side1.addPoint(600, 445);
    g.setColor(Color.blue);
    g.fillPolygon(side1);
    Polygon side2 = new Polygon(); // green side of cube
    side2.addPoint(510, 380);
    side2.addPoint(550, 410);
    side2.addPoint(550, 495);
    side2.addPoint(510, 455);
    g.setColor(Color.green);
    g.fillPolygon(side2);
    Polygon side3 = new Polygon(); // yellow side of cube
    side3.addPoint(550, 445);
    side3.addPoint(600, 445);
    side3.addPoint(635, 480);
    side3.addPoint(550, 495);
    g.setColor(Color.yellow);
    g.fillPolygon(side3);
    Polygon side4 = new Polygon(); // red side of cube
    side4.addPoint(510, 380);
    side4.addPoint(550, 410);
    side4.addPoint(635, 410);
    side4.addPoint(600, 380);
    g.setColor(Color.red);
    g.fillPolygon(side4);
    // TODO Auto-generated method stub

    // TODO Auto-generated method stub

  }
Esempio n. 17
0
 public void drawBlock(Graphics g, int r, int c, int mode) {
   Color curr = g.getColor();
   g.setColor(Color.black);
   int inc = 2;
   int xpos = inc + (c * wt), ypos = inc + (r * ht);
   switch (mode) {
     case 1:
       { // drawn on a square with an unclicked
         // bomb
         drawBomb(g, xpos, ypos);
         break;
       }
     case 2:
       { // draws a cell with a number on it
         g.setColor(Color.lightGray);
         g.fillRect(xpos, ypos, wt, ht);
         if (field[r][c] > 0) {
           g.setFont(new Font("Serif", Font.BOLD, 12));
           g.setColor(list[field[r][c] - 1]);
           g.drawString(field[r][c] + "", xpos + 5, ypos + 12);
         }
       }
       break;
     case 3:
       { // drawn on the square where the bomb was clicked
         g.setColor(Color.red);
         g.fillRect(xpos, ypos, wt, ht);
         g.setColor(Color.black);
         drawBomb(g, xpos, ypos);
       }
       break;
     case 4:
       { // draws a plain unrevealed cell
         g.setColor(Color.lightGray);
         g.fill3DRect(xpos, ypos, wt, ht, true);
       }
       break;
     case 5:
       { // a Flag.
         g.setColor(Color.lightGray);
         g.fill3DRect(xpos, ypos, wt, ht, true);
         g.setColor(Color.red);
         g.fillRect(xpos + 4, ypos + 3, 4, 4);
         g.setColor(Color.red.darker());
         g.drawLine(xpos + 8, ypos + 3, xpos + 8, ypos + 6);
         g.drawLine(xpos + 8, ypos + 6, xpos + 5, ypos + 6);
         g.drawLine(xpos + 6, ypos + 5, xpos + 7, ypos + 5);
         g.drawLine(xpos + 7, ypos + 5, xpos + 7, ypos + 4);
         g.setColor(new Color(128, 128, 128));
         g.drawLine(xpos + 5, ypos + 12, xpos + 11, ypos + 12);
         g.drawLine(xpos + 7, ypos + 11, xpos + 9, ypos + 11);
         g.setColor(Color.black);
         g.drawLine(xpos + 8, ypos + 7, xpos + 8, ypos + 11);
         g.drawLine(xpos + 6, ypos + 12, xpos + 10, ypos + 12);
       }
       break;
     case 6:
       { // A red cross - flag over non mine block
         g.setColor(Color.red);
         g.drawLine(xpos + 3, ypos + 3, xpos + 11, ypos + 11);
         g.drawLine(xpos + 4, ypos + 3, xpos + 12, ypos + 11);
         g.drawLine(xpos + 12, ypos + 3, xpos + 4, ypos + 11);
         g.drawLine(xpos + 3, ypos + 11, xpos + 11, ypos + 3);
         g.setColor(Color.red.darker());
         g.drawLine(xpos + 3, ypos + 12, xpos + 4, ypos + 12);
         g.drawLine(xpos + 4, ypos + 12, xpos + 7, ypos + 9);
         g.drawLine(xpos + 8, ypos + 9, xpos + 11, ypos + 12);
         g.drawLine(xpos + 11, ypos + 12, xpos + 12, ypos + 12);
         g.drawLine(xpos + 3, ypos + 4, xpos + 6, ypos + 7);
         g.drawLine(xpos + 12, ypos + 4, xpos + 9, ypos + 7);
       }
       break;
     case 7:
       {
         g.setColor(Color.lightGray);
         g.fillRect(xpos, ypos, wt, ht);
       }
       break;
   }
   g.setColor(curr);
 }
Esempio n. 18
0
 public static void drawRoof(Graphics g) {
   g.setColor(Color.red);
   g.drawLine(200, 200, 350, 100);
   g.drawLine(500, 200, 350, 100);
   g.drawLine(200, 200, 500, 200);
 }
Esempio n. 19
0
  public void paint(Graphics g) {
    // Draw Grid
    g.drawRect(0, 0, 780, 580);
    g.drawLine(400, 0, 400, 580);
    g.drawLine(0, 300, 780, 300);

    Random rndInt = new Random(1234);

    // Draw Random Squares

    for (int k = 1; k <= 1000; k++) {
      int x = rndInt.nextInt(385);
      int y = rndInt.nextInt(275);
      int red = rndInt.nextInt(256);
      int green = rndInt.nextInt(120);
      int blue = rndInt.nextInt(120);
      g.setColor(new Color(red, green, blue));
      g.fillRect(x, y, 15, 15);
    }
    // Draw Random Lines

    for (int k = 1; k <= 1000; k++) {
      int x1 = rndInt.nextInt(350);
      int y1 = rndInt.nextInt(300);
      int x2 = rndInt.nextInt(370);
      int y2 = rndInt.nextInt(300);
      g.drawLine(x1 + 400, y1, x2 + 400, y2);
      int red = rndInt.nextInt(100);
      int green = rndInt.nextInt(100);
      int blue = rndInt.nextInt(100);
      g.setColor(new Color(red, green, blue));
    }

    // Draw Random Circles
    for (int k = 1; k <= 1000; k++) {
      int x3 = rndInt.nextInt(385);
      int y3 = rndInt.nextInt(272);
      int red = rndInt.nextInt(240);
      int green = rndInt.nextInt(255);
      int blue = rndInt.nextInt(255);
      g.setColor(new Color(red, green, blue));
      g.drawOval(x3, y3 + 300, 11, 11);
    }
    // Draw 3-D Box
    {
      g.setColor(Color.blue);
      int x[] = {575, 675, 675, 575};
      int y[] = {425, 425, 525, 525};
      g.drawPolygon(x, y, 4);
      g.fillPolygon(x, y, 4);
    }
    {
      g.setColor(Color.yellow);
      int x1[] = {525, 575, 575, 525};
      int y1[] = {375, 425, 525, 475};
      g.drawPolygon(x1, y1, 4);
      g.fillPolygon(x1, y1, 4);
    }
    {
      g.setColor(Color.green);
      int x2[] = {525, 625, 625, 575};
      int y2[] = {375, 375, 425, 425};
      g.drawPolygon(x2, y2, 4);
      g.fillPolygon(x2, y2, 4);
    }
    {
      g.setColor(Color.red);
      int x3[] = {625, 625, 675};
      int y3[] = {375, 425, 425};
      g.drawPolygon(x3, y3, 3);
      g.fillPolygon(x3, y3, 3);
    }
  }
Esempio n. 20
0
 public static void drawChimney(Graphics g) {
   g.setColor(Color.red);
   g.drawLine(420, 146, 420, 80);
   g.drawLine(420, 80, 450, 80);
   g.drawLine(450, 80, 450, 166);
 }