Here's a simple console-mode gizmo you might like to play with...

Comments gratefully recieved.

For the total novice:

Cut and paste the following code into a text application and save it as: DNA.java

Compile the program with: javac DNA.java

And run it with: java DNA

Try different values. Higher numbers make faster waves. Start with an 8.

This is programmed to 'improvise' around the wavelength you choose, so the picking same number twice will not achieve the same result twice.

import java.util.*;

publicclass DNA

{

publicstaticvoid main (String[] args)

{

Random random =new Random();

Scanner in =new Scanner(System.in);

System.out.println("On a scale of 0 to 12, what's your wavelength?:");

int factor = 10-in.nextInt();

int radius1 = random.nextInt(38);

int radius2 = (38-radius1);

double wavemultiplier = factor * 10.5 + 45;

double waveadder = factor * 14.5 + 5;

double wavelength1 = wavemultiplier * random.nextDouble() + waveadder;

double angle1 = random.nextDouble()*2;

angle1 = Math.PI*angle1;

double wavelength2 = wavemultiplier * random.nextDouble() + waveadder;

double angle2 = random.nextDouble()*2;

angle2 = Math.PI*angle2;

int spaces1;

double step1 = Math.PI/wavelength1;

int spaces2;

double step2 = Math.PI/wavelength2;

do

{

spaces1 = (int) Math.round((1+Math.sin(angle1))*radius1);

spaces2 = (int) Math.round((1+Math.sin(angle2))*radius2);

int diff = spaces2 - spaces1;

if (diff >= 0)

{

if (diff == 0)

plot (spaces1,"$$");

elseif (diff == 1)

{

plot (spaces1,"+$X");

}

else

{

plot (spaces1,"++");

plot (diff - 2,"XX");

}

}

else

{

diff = spaces1 - spaces2;

if (diff == 1)

{

plot (spaces2,"X$+");

}

else

{

plot (spaces2,"XX");

plot (diff - 2,"++");

}

spaces1 = spaces2;

}

plot (spaces1,"jon\n");

angle1 += step1;

angle2 -= step2;

for (int delayloop = 0; delayloop <=15000; delayloop++)

{

double fairy = 0;

for (int scale = 0; scale <= 3; scale++)

{

fairy = Math.sin(1);// waste some time.

}

}

}

while (true);

}

publicstaticvoid plot (int x, String y)

{

while (0 != x--)

{

System.out.print(" ");

}

System.out.print(y);

}

}

[4993 byte] By [vapourmilea] at [2007-10-3 4:09:20]
# 1

Do not do delays by using large loops. A good JIT will realise that your loop accomplishes nothing and remove it. Instead use System.currentTimeMillis (or the nano one if you're using 1.5 and precise timing is really important) and Thread.sleep. Note that there's a bug with Thread.sleep under Windows: IIRC the workaround is never to call it with a multiple of 10.

YAT_Archivista at 2007-7-14 22:09:22 > top of Java-index,Java Essentials,New To Java...
# 2
Here's a sample output from the program: http://www.geocities.com/hotchox/output.txt
vapourmilea at 2007-7-14 22:09:22 > top of Java-index,Java Essentials,New To Java...