示例#1
0
    public final StickMan draw(
        final double[] locations,
        final Canvas canvas,
        final Canvas ids,
        final AtomicInteger idUnderMouse,
        final OrbiterMouseHandler orbiter) {
      final Graphics2D g = canvas.getGraphics();
      final int bottom = canvas.getHeight() - 1;

      {
        g.setColor(Color.CYAN);

        final int n = this.segments.length;

        for (int i = 0; i < n; i += 2) {
          final int v0 = this.offset + 3 * this.segments[i + 0];
          final int v1 = this.offset + 3 * this.segments[i + 1];

          g.drawLine(
              iround(locations[v0 + 0]),
              bottom - iround(locations[v0 + 1]),
              iround(locations[v1 + 0]),
              bottom - iround(locations[v1 + 1]));
        }
      }

      {
        g.setColor(Color.YELLOW);

        final int n = this.muscles.length;

        for (int i = 0; i < n; i += 2) {
          final int v0 = this.offset + 3 * this.muscles[i + 0];
          final int v1 = this.offset + 3 * this.muscles[i + 1];

          g.drawLine(
              iround(locations[v0 + 0]),
              bottom - iround(locations[v0 + 1]),
              iround(locations[v1 + 0]),
              bottom - iround(locations[v1 + 1]));
        }
      }

      for (int i = this.offset; i < this.nextOffset; i += 3) {
        final int r = 3;
        final int left = iround(locations[i + 0]) - r;
        final int top = bottom - iround(locations[i + 1]) - r;
        final int d = 2 * r;
        final int id = i / 3;

        g.setColor(id != idUnderMouse.get() ? RED : YELLOW);
        g.fillOval(left, top, d, d);

        ids.getGraphics().setColor(new Color(id + 1));
        ids.getGraphics().fillOval(left, top, d, d);
      }

      return this;
    }
示例#2
0
  public static final void drawAxes(final Canvas canvas, final OrbiterMouseHandler orbiter) {
    final int bottom = canvas.getHeight() - 1;
    final double s = 10.0;
    final double[] axes = {0.0, 0.0, 0.0, s, 0.0, 0.0, 0.0, s, 0.0, 0.0, 0.0, s};

    orbiter.transform(axes, 0.0, 0.0, 0.0);

    final Graphics2D g = canvas.getGraphics();

    g.setColor(RED);
    g.drawLine(
        (int) round(s + axes[0 + 0]),
        bottom - (int) round(s + axes[0 + 1]),
        (int) round(s + axes[3 + 0]),
        bottom - (int) round(s + axes[3 + 1]));
    g.setColor(GREEN);
    g.drawLine(
        (int) round(s + axes[0 + 0]),
        bottom - (int) round(s + axes[0 + 1]),
        (int) round(s + axes[6 + 0]),
        bottom - (int) round(s + axes[6 + 1]));
    g.setColor(BLUE);
    g.drawLine(
        (int) round(s + axes[0 + 0]),
        bottom - (int) round(s + axes[0 + 1]),
        (int) round(s + axes[9 + 0]),
        bottom - (int) round(s + axes[9 + 1]));
  }
示例#3
0
  public static final void drawGrid(final Canvas canvas, final OrbiterMouseHandler orbiter) {
    final double s = 500.0;
    final double minimumX = orbiter.getCenterX() - s;
    final double maximumX = orbiter.getCenterX() + s;
    final double minimumY = orbiter.getCenterY() - s;
    final double maximumY = orbiter.getCenterY() + s;
    final double z = 0.0;
    final int stripes = 10;
    final double amplitudeX = maximumX - minimumX;
    final double amplitudeY = maximumY - minimumY;
    final int n = 3 * 2 * (stripes + 1) * 2;
    final double[] segments = new double[n];

    for (int i = 0, j = 0; i <= stripes; ++i) {
      segments[j++] = minimumX;
      segments[j++] = minimumY + i * amplitudeY / stripes;
      segments[j++] = z;
      segments[j++] = maximumX;
      segments[j++] = minimumY + i * amplitudeY / stripes;
      segments[j++] = z;

      segments[j++] = minimumX + i * amplitudeX / stripes;
      segments[j++] = minimumY;
      segments[j++] = z;
      segments[j++] = minimumX + i * amplitudeY / stripes;
      segments[j++] = maximumY;
      segments[j++] = z;
    }

    orbiter.transform(segments);

    final Graphics2D g = canvas.getGraphics();
    final int bottom = canvas.getHeight() - 1;

    g.setColor(Color.GRAY);

    for (int i = 0; i < n; i += 6) {
      g.drawLine(
          iround(segments[i + 0]),
          iround(bottom - segments[i + 1]),
          iround(segments[i + 3]),
          iround(bottom - segments[i + 4]));
    }
  }