summaryrefslogtreecommitdiff
path: root/trunk/users/ed/GeometricProgression.java
blob: 3fa43293da306563f443cb57c30661cb5dbaa883 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.applet.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.lang.Math;
import java.util.*;
import java.awt.geom.Ellipse2D;
import java.awt.*;

/*
 * Program to express the power of self replication
 * No death here ;-)
 */

public class GeometricProgression extends Applet
{
	   int cycles = 16;
	   int width, height;
	
	   Color[] spectrum;    // an array of elements, each of type Color
	
	   public void init() {
	
		  resize(1000,700);
		  
		  width = getSize().width;
	      height = getSize().height;
	      setBackground( Color.black );

	      // Allocate the arrays; make them "N" elements long
	      spectrum = new Color[ cycles ];
	
	      for ( int i = 0; i < cycles; ++i ) {
	          // Here we specify colors by Hue, Saturation, and Brightness,
	          // each of which is a number in the range [0,1], and use
	          // a utility routine to convert it to an RGB value before
	          // passing it to the Color() constructor.
	          spectrum[i] = new Color( Color.HSBtoRGB(i/(float)cycles,1,1) );
	      }
	   }
	
	public void paint(Graphics g)
	{
		final Graphics2D g2 = (Graphics2D)g;
		
		final int FONT_SIZE = 20;
		Font key = new Font("Courier", Font.BOLD, FONT_SIZE);
		g2.setFont(key);
		
		for (int n = 0; n < 4; n++)
		{
			for (int click = 0; click < cycles; click++)
			{
				g2.setColor( spectrum[ click ] );
				
				g2.drawString("(R)ep cycles", 5, FONT_SIZE);
				g2.drawString("(T)otal orgs", 5, FONT_SIZE*2);
				
				for (int i=0; i< (Math.pow(2,click)-Math.pow(2,(click-1))); i++)
				{
					Random rand = new Random();
					double x = (width-160) * Math.abs(rand.nextDouble());
					double y = height * Math.abs(rand.nextDouble());
				
					Ellipse2D.Double dot = new Ellipse2D.Double(x+160,y,10,10);
	
					g2.fill(dot);
				}
					
				g2.drawString("R = " + click, 5, ((height/(cycles+2))*click+2*(height/(cycles+2))));
				g2.drawString("T = " + (int)Math.pow(2,click), 5, (height/(cycles+2))*click+FONT_SIZE+2*(height/(cycles+2)));
							
				System.out.println(Math.pow(2,click));
		
				try{
					Thread.sleep(1000);
				}
				catch(InterruptedException e){
					System.out.println("Error:" + e); 
				}
		
			}
			repaint();
		}
	}
	
	
	
}