Tuesday, February 24, 2015

Plasma Cloud java in a pgm



PlasmaCloud.java

import java.awt.Color;

public class PlasmaCloud
{

              public static void plasma(double x,  double y,  double size, double stddev,double c1, double c2, double c3,   double c4)
{

       
        if (size <= 0.001) return;

        double displacement = StdRandom.gaussian(0, stddev);
        double cM = (c1 + c2 + c3 + c4) / 4.0 + displacement;

        Color color = Color.getHSBColor((float) cM, .8f, .8f);
        StdDraw.setPenColor(color);
        StdDraw.filledSquare(x, y, size);

        double cT = (c1 + c2) / 2.0;   
        double cB = (c3 + c4) / 2.0;   
        double cL = (c1 + c3) / 2.0;   
        double cR = (c2 + c4) / 2.0;   

        plasma(x - size/2, y - size/2, size/2, stddev/2, cL, cM, c3, cB);
        plasma(x + size/2, y - size/2, size/2, stddev/2, cM, cR, cB, c4);
        plasma(x - size/2, y + size/2, size/2, stddev/2, c1, cT, cL, cM);
        plasma(x + size/2, y + size/2, size/2, stddev/2, cT, c2, cM, cR);
    }
                public static void main(String[] args)
   {
        int SIZE = Integer.parseInt(args[0]);

        double c1 = Math.random();
        double c2 = Math.random();
        double c3 = Math.random();
        double c4 = Math.random();
        double stddev = 1.0;
                    plasma(.5, .5, .5, stddev, c1, c2, c3, c4);
    }
}

No comments:

Post a Comment