コード例 #1
0
ファイル: StdStats.cs プロジェクト: franklzt/DataStruct
 /**
   * Plots bars from (0, <em>a</em><sub><em>i</em></sub>) to
   * (<em>a</em><sub><em>i</em></sub>) for each <em>i</em>
   * to standard draw.
   *
   * @param a the array of values
   */
  public static void plotBars(double[] a) {
      validateNotNull(a);
      int n = a.length;
      StdDraw.setXscale(-1, n);
      for (int i = 0; i < n; i++) {
          StdDraw.filledRectangle(i, a[i]/2, 0.25, a[i]/2);
      }
  }
コード例 #2
0
ファイル: StdStats.cs プロジェクト: franklzt/DataStruct
 /**
   * Plots the line segments connecting 
   * (<em>i</em>, <em>a</em><sub><em>i</em></sub>) to
   * (<em>i</em>+1, <em>a</em><sub><em>i</em>+1</sub>) for 
   * each <em>i</em> to standard draw.
   *
   * @param a the array of values
   */
  public static void plotLines(double[] a) {
      validateNotNull(a);
      int n = a.length;
      StdDraw.setXscale(-1, n);
      StdDraw.setPenRadius();
      for (int i = 1; i < n; i++) {
          StdDraw.line(i-1, a[i-1], i, a[i]);
      }
  }
コード例 #3
0
ファイル: StdStats.cs プロジェクト: franklzt/DataStruct
 /**
   * Plots the points (0, <em>a</em><sub>0</sub>), (1, <em>a</em><sub>1</sub>), ...,
   * (<em>n</em>-1, <em>a</em><sub><em>n</em>-1</sub>) to standard draw.
   *
   * @param a the array of values
   */
  public static void plotPoints(double[] a) {
      validateNotNull(a);
      int n = a.length;
      StdDraw.setXscale(-1, n);
      StdDraw.setPenRadius(1.0 / (3.0 * n));
      for (int i = 0; i < n; i++) {
          StdDraw.point(i, a[i]);
      }
  }
コード例 #4
0
 // redraw all particles
 private void redraw(double limit) {
     StdDraw.clear();
     for (int i = 0; i < particles.length; i++) {
         particles[i].draw();
     }
     StdDraw.show();
     StdDraw.pause(20);
     if (t < limit) {
         pq.insert(new Event(t + 1.0 / HZ, null, null));
     }
 }
コード例 #5
0
 private void redraw(double num)
 {
     StdDraw.clear();
     for (int i = 0; i < this.particles.Length; i++)
     {
         this.particles[i].draw();
     }
     StdDraw.show(20);
     if (this.t < num)
     {
         this.pq.insert(new CollisionSystem.Event(this.t + (double)1f / this.hz, null, null));
     }
 }
コード例 #6
0
    /**
     * Unit tests the {@code CollisionSystem} data type.
     * Reads in the particle collision system from a standard input
     * (or generates {@code N} random particles if a command-line integer
     * is specified); simulates the system.
     *
     * @param args the command-line arguments
     */
    public static void main(String[] args) {

        StdDraw.setCanvasSize(600, 600);

        // enable double buffering
        StdDraw.enableDoubleBuffering();

        // the array of particles
        Particle[] particles;

        // create n random particles
        if (args.length == 1) {
            int n = Integer.parseInt(args[0]);
            particles = new Particle[n];
            for (int i = 0; i < n; i++)
                particles[i] = new Particle();
        }

        // or read from standard input
        else {
            int n = StdIn.readInt();
            particles = new Particle[n];
            for (int i = 0; i < n; i++) {
                double rx     = StdIn.readDouble();
                double ry     = StdIn.readDouble();
                double vx     = StdIn.readDouble();
                double vy     = StdIn.readDouble();
                double radius = StdIn.readDouble();
                double mass   = StdIn.readDouble();
                int r         = StdIn.readInt();
                int g         = StdIn.readInt();
                int b         = StdIn.readInt();
                Color color   = new Color(r, g, b);
                particles[i] = new Particle(rx, ry, vx, vy, radius, mass, color);
            }
        }

        // create collision system and simulate
        CollisionSystem system = new CollisionSystem(particles);
        system.simulate(10000);
    }
コード例 #7
0
    /**/ public static void main(string[] strarr)
    {
        StdDraw.setXscale(0.045454545454545456, 0.95454545454545459);
        StdDraw.setYscale(0.045454545454545456, 0.95454545454545459);
        StdDraw.show(0);
        Particle[] array;
        if (strarr.Length == 1)
        {
            int num = Integer.parseInt(strarr[0]);
            array = new Particle[num];
            for (int i = 0; i < num; i++)
            {
                array[i] = new Particle();
            }
        }
        else
        {
            int num = StdIn.readInt();
            array = new Particle[num];
            for (int i = 0; i < num; i++)
            {
                double d  = StdIn.readDouble();
                double d2 = StdIn.readDouble();
                double d3 = StdIn.readDouble();
                double d4 = StdIn.readDouble();
                double d5 = StdIn.readDouble();
                double d6 = StdIn.readDouble();
                int    r  = StdIn.readInt();
                int    g  = StdIn.readInt();
                int    b  = StdIn.readInt();
                Color  c  = new Color(r, g, b);
                array[i] = new Particle(d, d2, d3, d4, d5, d6, c);
            }
        }
        CollisionSystem collisionSystem = new CollisionSystem(array);

        collisionSystem.simulate(10000.0);
    }
コード例 #8
0
 /**
  * Draws this particle to standard draw.
  */
 public void draw() {
     StdDraw.setPenColor(color);
     StdDraw.filledCircle(rx, ry, radius);
 }
コード例 #9
0
ファイル: RectHV.cs プロジェクト: franklzt/DataStruct
 /**
  * Draws this rectangle to standard draw.
  */
 public void draw() {
     StdDraw.line(xmin, ymin, xmax, ymin);
     StdDraw.line(xmax, ymin, xmax, ymax);
     StdDraw.line(xmax, ymax, xmin, ymax);
     StdDraw.line(xmin, ymax, xmin, ymin);
 }
コード例 #10
0
 public virtual void draw()
 {
     StdDraw.setPenColor(this.color);
     StdDraw.filledCircle(this.rx, this.ry, this.radius);
 }
コード例 #11
0
ファイル: Interval2D.cs プロジェクト: franklzt/DataStruct
 /**
  * Draws this two-dimensional interval to standard draw.
  */
 public void draw() {
     double xc = (x.min() + x.max()) / 2.0;
     double yc = (y.min() + y.max()) / 2.0;
     StdDraw.rectangle(xc, yc, x.length() / 2.0, y.length() / 2.0);
 }