<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">// Illustration of a loop: the logarithmic spiral

import java.io.*;
import java.awt.*;

// Logarithmic spiral example
public class Drawing extends Frame
{// The spiral consists of n line segments. Line segment 1
// has starting point (hc, vc). Line segment k, for 1&lt;=k&lt;=n,
// has length k*d. Each line segment makes an angle of turn
// degrees with the previous line segment. The colors of the
// lines alternate between red, blue, and green.

final static int hc= 300; 	// Center of spiral is (hc,vc)
final static int vc= 250;
final static int n= 10000;    // Number of sides to draw
// Try 30,45,75, 85, 89, 90, 91, 95, , 120,135
final static int turn= 45; 	// The turn factor
final static double d= .2;	// Length of leg k is k*d

public void paint(Graphics g)
	{int h= hc;
	int v= vc;
	int k= 1;
	//Invariant: legs 1..k-1 have been drawn, and leg k is
	//           to be drawn with start point (hc,vc)
	while (k&lt;=n)
		{//Draw line k
			if (k%3==0) g.setColor(Color.red);
			if (k%3==1) g.setColor(Color.blue);
			if (k%3==2) g.setColor(Color.green);
		
			int theta= k*turn %360;
			double L= k*d;
			// Calculate the end point (h_next,v_next) of
			// the line
				int h_next= (int) Math.round(
						h+L*Math.cos(theta*Math.PI/180));
				int v_next= (int) Math.round(
						v+L*Math.sin(theta*Math.PI/180));
			g.drawLine(h,v,h_next, v_next);
		
		h= h_next; v= v_next;
		k= k+1;
		}
	}
	
}


// Main program for logarithmic spiral. Declare and show
// a Drawing window.
public class CUCSGraphicsApplication
{public static void main(String args[])
	{Drawing d = new Drawing();
	d.resize(600,500);
	d.move(0,75);
	d.setTitle("Logarithmic spiral");
	d.show();
	d.toFront();
	}
}
</pre></body></html>