Advertisement
calcpage

LACS07a_Butterfly.java

Jun 12th, 2012
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.93 KB | None | 0 0
  1. /*************************************************************************
  2.  *  Compilation:  javac Butterfly.java
  3.  *  Execution:    java Butterfly
  4.  *  Dependencies: StdDraw.java
  5.  *  
  6.  *  Plots a butterfly-like curve.
  7.  *
  8.  *  Reference: A. K. Dewdney's The Magic Machine. Credited to
  9.  *  Temple H. Fay of the University of Southern Mississippi.
  10.  *
  11.  *************************************************************************/
  12.  
  13.  
  14. public class Butterfly {
  15.  
  16.    public static void main(String[] args) {
  17.       StdDraw.setXscale(-4, 4);
  18.       StdDraw.setYscale(-4, 4);
  19.       double x0 = 0, y0 = 0;
  20.       for (double theta = 0.0; theta < 72; theta += 0.01) {
  21.           double r = Math.exp(Math.cos(theta)) - 2*Math.cos(4*theta) + Math.pow(Math.sin(theta/12), 5);
  22.           double x1 = r * Math.cos(theta);
  23.           double y1 = r * Math.sin(theta);
  24.           StdDraw.line(x0, y0, x1, y1);
  25.           x0 = x1;
  26.           y0 = y1;
  27.       }
  28.    }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement