Computer Science Canada

spiral thingy

Author:  Homer_simpson [ Sun Mar 14, 2004 2:55 pm ]
Post subject:  spiral thingy

mess around with
double modes=10;
double zoom = 3;
to get different effects


code:

import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.Dimension;

public class spiralthingy extends JApplet
{
    public static Color colors [] = new Color [510];
    private Image bImage;
    private Graphics bg;
    private Graphics2D g2d;
    private int width, height;
    private boolean drawnonce = false;

    public void init ()
    {
 setBackground (Color.black);
 width = 800;
 height = 600;
 resize (width, height);
 for (int i = 0 ; i < 255 ; i++)
 {
     colors [i] = new Color (i, i, i);
 }
 for (int i = 255 ; i < 255 * 2 ; i++)
 {
     colors [i] = new Color (255 - (i - 255), 255 - (i - 255), 255 - (i - 255));
 }

    }


    private void drawonce (Graphics bg)
    {
      double modes=10;
      double zoom = 3;
      double xx = 0, yy = 0, lx, ly;
 if (drawnonce == false)
 {
     drawnonce = true;
     ///////////////////////////////////////////Drawn Code Here\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
     for (double j = 1 ; j < 1000 ; j += 1)
     {
  for (double i = 0 ; i < modes ; i += .01)
  {
      //bg.setColor (colors [(int) ((i * 100) % 510)]);
      bg.setColor (Color.white);
      lx = xx;
      ly = yy;
      xx += Math.cos ((i * j) * (i * j));
      yy += Math.sin ((i * j) * (i * j));
      bg.drawLine ((int) (lx / zoom) + 10, (int) (ly / zoom) + 10, (int) (xx / zoom) + 10, (int) (yy / zoom) + 10);
  }
  updateScreen ();
     }
     ///////////////////////////////////////////Drawn Code Ends Here\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
 }
    }


    public void paint (Graphics g)
    {
 g2d = (Graphics2D) g;
 bImage = createImage (width, height);
 bg = bImage.getGraphics ();
 drawonce (bg);
 bg.dispose ();
 bImage.flush ();
    }


    private void updateScreen ()
    {
 g2d.drawImage (bImage, 0, 0, this);
    }
}

Author:  Paul [ Thu Mar 25, 2004 6:19 pm ]
Post subject: 

It looks nice, but at the start its a nice spiral, then it goes into something like grapes clumped together, is that suppose to happen? Im a noob so I don't understand your code, since you used cos and sin like you always do, i wouldn't understand anyway.
I compiled it
put it into html with
code:

<html>
<applet code= "Applet.class" width=300 height=30>
</applet>
</html>

then
code:

appletviewer spiralthingy.html

Author:  Homer_simpson [ Mon Mar 29, 2004 3:04 am ]
Post subject: 

yes it is... that's what makes it wierd...


: