Hi!
I am really new to Java. As an exercise I'm trying to make an applet that draws "Cantor Dust" (L-system - Wikipedia, the free encyclopedia - third example. I filled an array with integers named A and B
and used g.drawLine to try to draw a line at a spot proportional to the position in the array for every element that was "A".
It compiles, but in Firefox I just get a blank screen
Any help or pointers greatly appreciated!
Code:
import java.awt.*; import java.lang.*; import java.util.*; public class CantorDust extends java.applet.Applet { static int A; //A and B are what the arrays are filled with. A = draw forward. B= move forward static int B; static int i; //i,j,k,l are "counters" in the for-loops. static int j; static int k; static int l; static int m; //m is just l+1. static double iterations = 5.0; //#iterations static double sizeArray = Math.pow(3.0, iterations); //Size of array is 3^#iter. static int NsizeArray = (int)sizeArray; //convert double to int static int[] VDust = new int[NsizeArray]; static int[] NDust = new int[NsizeArray]; //Declare two identical arrays static double lineSize; //Size of line to draw static int NlineSize; //same for int public void paint(Graphics g) { double lineSize = 600/NsizeArray; //Line size - (for 5 iter should be 2.4) int NlineSize = (int)lineSize; //convert to int. for(i=0; i<iterations; i++) for (j=1; j<NsizeArray;j++) if (VDust[j]==A) NDust[1+3*(j-1)]=A; //Fill NDust from VDust NDust[2+3*(j-1)]=B; //according to the rule A -> ABA NDust[3+3*(j-1)]=A; if (VDust[j]==B) NDust[1+3*(j-1)]=B; NDust[2+3*(j-1)]=B; //Fill NDust from VDust according NDust[3+3*(j-1)]=B; //to the rule B -> BBB for (k=0;k<sizeArray;k++) //Form a new NDust by copying VDust VDust[k] = NDust[k]; for(l=0; l<sizeArray; l++) m = l++; if(NDust[l]==A) g.drawLine(l*NlineSize,20,(m)*NlineSize,20); //For every A element in NDust // if(NDust[l]==B) do nothing.("move forward") //draw a line of length Nlinesize } }