/package LedDreamKit; import java.awt.*; import java.applet.*; import java.io.*; import java.net.*; import java.lang.*; import java.util.*; /* This program is designed in prior to the work Geo-Sphere. Please enjoy!! Designed by Hiroyuki Moriwaki Coded by Hiroshi Kanechiku */ public class LedDreamKit extends Applet implements Runnable { Thread dreamkit; LedUnit lu; LedUnitParam lup; Param_editor pe; // init companion routine public void getattribute() { int b; try { // get parameter here width,height,lu size,num of atoms lup.width = new Integer( getParameter("WIDTH") ).intValue(); lup.height = new Integer( getParameter("HEIGHT") ).intValue(); lup.pe_height = new Integer(getParameter("PE_HEIGHT")).intValue(); lup.x_atoms = new Integer( getParameter("X_ATOMS") ).intValue(); lup.y_atoms = new Integer( getParameter("Y_ATOMS") ).intValue(); lup.atom_max_energy= new Integer( getParameter("ATOM_MAX_ENERGY")).intValue(); lup.atom_hatch_main= new Integer( getParameter("ATOM_HATCH_MAIN")).intValue(); lup.atom_hatch_sub= new Integer( getParameter("ATOM_HATCH_SUB")).intValue(); lup.atom_decline= new Integer( getParameter("ATOM_DECLINE")).intValue(); lup.atom_decline_sub= new Integer( getParameter("ATOM_DECLINE_SUB")).intValue(); lup.atom_inc_energy= new Integer( getParameter("ATOM_INC_ENERGY")).intValue(); lup.atom_min_energy= new Integer( getParameter("ATOM_MIN_ENERGY")).intValue(); lup.atom_average= new Integer( getParameter("ATOM_AVERAGE")).intValue(); lup.atom_collision= new Integer( getParameter("ATOM_COLLISION")).intValue(); lup.ptn_power_level= new Integer( getParameter("PTN_POWER_LEVEL")).intValue(); //TEST TEST lup.atom_test_id= new Integer( getParameter("ATOM_TEST_ID")).intValue(); lup.interval = new Integer( getParameter("INTERVAL") ).intValue(); b = new Integer( getParameter("BOARD_COLOR") ).intValue(); }catch(Exception e) { System.out.println("Parameter Error, check HTML file"); lup.init(); b = 10; } lup.num_atoms = (lup.x_atoms * lup.y_atoms); if(b>255||b<1)b=1; lup.led_on_color = new Color( 255,0,0 ); // r,g,b lup.button_color = new Color( 0,0,255); lup.bcolor = new Color(b,b,b); lup.height=lup.height-lup.pe_height; set_led_orientation( lup.width, lup.height ); /* lup.led_spacing = new Integer(getParameter("LED_SPACING")).intValue(); lup.led_size = new Integer( getParameter("LED_SIZE") ).intValue(); */ /* int t =new Integer( getParameter("PAT_CTL") ).intValue(); pat_ctl=(byte)(0x00ff&t); */ /* lup.unit_stx= (lup.width-3*lup.led_spacing*(lup.x_atoms-1))/2-lup.led_spacing/2; lup.unit_sty=(lup.height-3*lup.led_spacing*(lup.y_atoms-1))/2; */ } // set led spacing & size according to the applet size // & set Atom Unit start x,y position private void set_led_orientation( int wid, int hi ) { float ra, rs; ra=(float)(lup.x_atoms+1)/(float)lup.y_atoms; rs=(float)wid/(float)hi; if(raSLEEP) { current_i=-1; return false; } current_i=i; /* // for scroll bar if(evt.id != evt.MOUSE_UP) { System.out.println("event id = "+(new Integer(evt.id)).toString()); System.out.println("event arg = "+((Integer)(evt.arg)).toString()); return false; } set_newparam(i,(t=(Integer)evt.arg).intValue()); tfld[i].setText(t.toString()); System.out.println("sbar = "+t.toString()); */ if(evt.key!=10)return false;//return key=10 try { j=Integer.parseInt(tfld[i].getText()); System.out.println("j = " + j); set_newparam(i,j); System.out.println("key = "+(new Integer(evt.key)).toString()); System.out.println("TextField = " + tfld[i].getText()); System.out.println(""); }catch(Exception e) { setback_TextField(i); } current_i=-1; return true; } public void set_newparam( int id, int val ) { try { if(val<0)val=0; if(idLEDSZ)return; if(id==HMAIN){ if(val>100)val=100;lup.atom_hatch_main=val;} if(id==HSUB){ if(val>100)val=100;lup.atom_hatch_sub=val;} if(id==DEC){ if(val>255)val=255;lup.atom_decline=val;} if(id==DECSUB){ if(val>255)val=255;lup.atom_decline_sub=val;} if(id==EMIN){ if(val>255)val=255;lup.atom_min_energy=val;} if(id==SLEEP){ if(val>10000)val=10000;lup.interval=val;} if(val<2) // set minimum size { setback_TextField(id); return; } if(id==LEDSP){ if(val>100)val=100;lup.led_spacing=val;} if(id==LEDSZ){ if(val>100)val=100;lup.led_size=val;} set_TextField(id,val); }catch(Exception e) { setback_TextField(id); } } public void setback_TextField( int id ) { if(idLEDSZ)return; if(id==HMAIN) tfld[id].setText((new Integer(lup.atom_hatch_main)).toString()); if(id==HSUB) tfld[id].setText((new Integer(lup.atom_hatch_sub)).toString()); if(id==DEC) tfld[id].setText((new Integer(lup.atom_decline)).toString()); if(id==DECSUB) tfld[id].setText((new Integer(lup.atom_decline_sub)).toString()); if(id==EMIN) tfld[id].setText((new Integer(lup.atom_min_energy)).toString()); if(id==SLEEP) tfld[id].setText((new Integer(lup.interval)).toString()); if(id==LEDSP) tfld[id].setText((new Integer(lup.led_spacing)).toString()); if(id==LEDSZ) tfld[id].setText((new Integer(lup.led_size)).toString()); if(id==LEDSP||id==LEDSZ)lu.set_newparam(lup,true); else lu.set_newparam(lup,false); kit.set_newparam(lup); } public void set_TextField( int id, int val ) { if(idLEDSZ)return; tfld[id].setText((new Integer(val)).toString()); if(id==LEDSP||id==LEDSZ)lu.set_newparam(lup,true); else lu.set_newparam(lup,false); kit.set_newparam(lup); } } /////////////////////////////////////////////////////////////////////////// class LedUnitParam { int num_atoms =0; // from the attribute int x_atoms =0; int y_atoms =0; int interval =500; int led_spacing =6; int led_size =4; int width =320; int height =320; int pe_height =200; int atom_max_energy =255; int atom_min_energy =20; int atom_inc_energy =20; int atom_hatch_main =100; int atom_hatch_sub =100; int atom_decline =50; int atom_decline_sub =5; int atom_average =1; int atom_collision =1; int random_on = 100; //pattern random on rate int ptn_power_level = 120; //pattern led power level long ptn_t_default = 30; //pattern change time int pattern_ctl = -1; //pattern ctl parameter // pattern constant public static final int PTN_STOP=-1; public static final int PTN_RUP=0; public static final int PTN_UP=1; public static final int PTN_LUP=2; public static final int PTN_LDOWN=3; public static final int PTN_DOWN=4; public static final int PTN_RDOWN=5; public static final int PTN_LCIRC=6; public static final int PTN_RCIRC=7; public static final int PTN_LAST=8; public static final int PTN_RAND=9; //TEST TEST int atom_test_id =50; int unit_stx =0; // atom start x position int unit_sty =0; // atom start y position Color led_on_color; Color button_color; Color bcolor; public void LedUnitParam(Applet app) { led_on_color = new Color( 255,0,0 ); // r,g,b button_color = new Color( 0,0,255); bcolor = new Color(10,10,10); } public void init() { num_atoms =0; // from the attribute x_atoms =10; y_atoms =10; interval =300; led_spacing =0; led_size =0; width =320; height =420; pe_height =100; atom_max_energy =255; atom_min_energy =100; atom_inc_energy =50; atom_hatch_main =90; atom_hatch_sub =80; atom_decline =10; atom_decline_sub=2; atom_average =1; atom_collision =1; random_on = 100; //pattern random on rate ptn_power_level = 100; //pattern led power level ptn_t_default = 30; //pattern change time pattern_ctl = -1; //pattern ctl parameter } } ////////////////////////////////////////////////////////////////////// class LedUnit extends Canvas { //TEST TEST private AtomUnit atom[]=new AtomUnit[200]; private LedUnitParam lup; private LedDreamKit kit; Image backimg; // for back buffered drawing Graphics backg; private boolean randomC=false; private boolean stopSim=false; private boolean initLed=false; private long ptn_t; // pattern timing private long ptn_t_default; int press_id=-1; public LedUnit(LedUnitParam lp) { this.lup=lp; for(int i=0;i0&&x<10&&y>0&&y<10)randomC=!randomC; // if(x>(lup.width-10)&&x0&&y<10)stopSim=!stopSim; bid = chk_butt_press(x,y); System.out.println("mouseDown id ;"+bid); System.out.println("button xpos ;"+x); System.out.println("button ypos ;"+y); System.out.println(" "); // start timer if(bid>=0) { // atom id now pressing press_id = bid; // notify press this.atom[press_id].start_press(); if(stopSim) this.atom[press_id].show_status(); //TEST TEST // this.atom[press_id].set_buttstate(lup.atom_max_energy); } return true; } public boolean mouseDrag( Event e, int x, int y) { int bid; bid = chk_butt_press(x,y); if(!stopSim) { System.out.println("mouseDrag id ;"+bid); System.out.println("button xpos ;"+x); System.out.println("button ypos ;"+y); System.out.println(" "); } // MOUSE is still inside? if(bid==-1) { if(press_id>=0) this.atom[press_id].butt_release(); press_id = -1; }else { press_id = bid; this.atom[press_id].start_press(); } return true; } public boolean mouseUp( Event e, int x, int y) { int bid; bid = chk_butt_press(x,y); if(!stopSim) { System.out.println("mouseUp id ;"+bid); System.out.println("button xpos ;"+x); System.out.println("button ypos ;"+y); System.out.println(" "); } // release button if(bid==-1) { if(press_id>=0) this.atom[press_id].butt_release(); }else this.atom[bid].butt_release(); press_id=-1; return true; } // return atom id if pressed public int chk_butt_press(int x, int y) { int i,j,k,row,col; row=(i=y-lup.unit_sty+(lup.led_size+2)/2)/(j=3*lup.led_spacing); j=i%j; if(j<=(lup.led_size+2) && j>=0) { System.out.println("row ;"+row); } else return(-1); if((row%2)==1)k=(lup.led_spacing*3)/2;else k=0; col=(i=x-lup.unit_stx-k+(lup.led_size+2)/2)/(j=3*lup.led_spacing); j=i%j; if(j<=( lup.led_size+2) && j>=0) { System.out.println("col ;"+col); return( row*lup.x_atoms+col ); }else return(-1); } /* // test button down public void press_button(int bid ) { this.atom[bid].set_buttstate(255); } */ public void paint(Graphics g) { paintUnit(backg,true); g.drawImage(backimg,0,0, this); } public void update(Graphics g) { paintUnit(backg,false); g.drawImage(backimg,0,0, this); } // paint unit public void paintUnit(Graphics g,boolean whole_unit) { //for testing int x=0; int y=lup.unit_sty; int sp,spf; int id=0; sp=lup.led_spacing*3; spf=lup.led_spacing*3/2; //draw frame if(whole_unit) { g.setColor(lup.bcolor); g.fill3DRect(2,2,lup.width-4,lup.height-4,true); } //draw each atoms if(!randomC) for(int i=0;i0){ System.out.println("atom comm : "+i ); System.out.println("atom comm : "+lt.power );} */ } } } // set new parameters public void set_newparam(LedUnitParam lp, boolean whole_unit ) { this.lup=lp; for(int i=0;i 100)this.power=0; else this.power=(led.power*percent)/100; this.gen = led.gen; } public void init( Led led ) { this.power=led.power; this.gen = led.gen; } public void init( Led led, int percent ) { if(percent<0 || percent > 100)this.power=0; else this.power=(led.power*percent)/100; this.gen = led.gen; } public void init( int power, int gen ) { this.power= power; this.gen = gen; } public void init() { this.power=0; this.gen=0; } } ////////////////////////////////////////////////////////////////// class AtomUnit { private LedUnitParam lup; // unit states which are seen from outside // by communication routine // led state // generation private static final int GEN_MAX=8; // led in_port & out_port private Led led_in[] = new Led[6]; public Led led_out[] = new Led[6]; // buffer for led private Led led_cue[] = new Led[6]; private int cue_average[] = {0,0,0,0,0,0}; private int cue_num[] = {0,0,0,0,0,0}; // actual led power private int led_state[]={0,0,0,0,0,0}; // pattern constant public static final int PTN_STOP=-1; public static final int PTN_RUP=0; public static final int PTN_UP=1; public static final int PTN_LUP=2; public static final int PTN_LDOWN=3; public static final int PTN_DOWN=4; public static final int PTN_RDOWN=5; public static final int PTN_LCIRC=6; public static final int PTN_RCIRC=7; public static final int PTN_LAST=8; public static final int PTN_RAND=9; // unit state used inner workings // pattern holder private int pattern; private int ptn_nth; private int random_on; private int ptn_power_level; // for user interaction private int butt_state; private boolean butt_t_start; private int butt_t; // inner working states // simulation parameters public int out_t[] ={-1,-1,-1,-1,-1,-1}; private int id; private int inc_energy; private int min_energy; private int max_energy; private int hatch_main; private int hatch_sub; private int decline; private int decline_sub; private int interval; private boolean average; private boolean collision; public AtomUnit() { this.id = -1;// id number of each AtomUnit this.butt_t_start =false; this.butt_state =0; this.butt_t =0; // simulation parameters // these are set with set_newparam(LedUnitParam) this.min_energy = 50; this.max_energy = 255; this.hatch_main = 100; this.hatch_sub = 100; this.decline = 50; this.decline_sub = 5; this.interval = 300; this.inc_energy = 50; average = true; collision = true; // init Led for(int i=0;i<6;i++) { led_out[i]= new Led(); led_in[i]= new Led(); led_cue[i]= new Led(); led_out[i].init(); led_in[i].init(); led_cue[i].init( 0,GEN_MAX ); } } public void init(LedUnitParam lp) { this.lup=lp; // get from attributes set_newparam(lp); init_pattern(); } public void init_led() { // init Led for(int i=0;i<6;i++) { led_out[i].init(); led_in[i].init(); led_cue[i].init( 0,GEN_MAX ); } } ////// simulation cycle public void atom_cycle() { // communication between Atoms is done here // using set_inport() // init_outport(); if(collision)calc_collision_inout(); set_buttstate(); hatch_three(); if(collision)calc_collision(); hatch_six(); set_led(average); set_led_out(average); proc_pattern(); init_led_cue(); //TEST TEST // chk_led_out(); } //// TESTING ROUTINE public void show_status() { for(int i=0;i<6;i++){ System.out.println(" _in["+i+"]: "+led_in[i].power+ ", "+led_in[i].gen+ " _out["+i+"]: "+led_out[i].power+ ", "+led_out[i].gen+ " _state["+i+"]: "+led_state[i]+ " cue["+i+"] : "+led_cue[i].power+ ", "+led_cue[i].gen); } } private void chk_led_out() { for(int i=0;i<6;i++) if(led_out[i].power>0) { System.out.println("chk_led_out id : "+id ); System.out.println("chk_led_out dir : "+i ); System.out.println("chk_led_out power : "+led_out[i].power ); } } //////// running pattern when idle routine // set pattern public void init_pattern() { pattern=lup.pattern_ctl; random_on=lup.random_on; ptn_power_level=lup.ptn_power_level; ptn_nth=0; } // change pattern power & pattern time private void proc_pattern() { boolean skip=false; if( pattern == PTN_STOP )return; for(int i=0;i<6;i++) if(led_state[i]>0){skip=true;break;} ptn_nth=set_ptn_power(pattern,ptn_nth,random_on,ptn_power_level,skip ); } // set pattern_power according to the value pattern private int set_ptn_power( int ptn,int nth,int rand,int pow,boolean skip ) { try { // change pattern power if(ptn<0||ptn>PTN_RCIRC)return(0); else if(ptnrand?0:pow; return((nth+1)%6); }else { if(!skip)led_state[5-nth%6]=Math.random()*100>rand?0:pow; return((nth+1)%6); } }catch(Exception e) { System.out.println("pattern exception ptn : "+ptn ); System.out.println("pattern exception nth : "+nth ); } return(0); } // companion routine above private void set_power_pair( int ptn, int nth, int rand, int pow ) { switch( nth%3 ) { case 0: led_state[ptn] =Math.random()*100>rand?0:pow; led_state[(ptn+1)%6] =Math.random()*100>rand?0:pow; break; case 1: led_state[(ptn+5)%6] =Math.random()*100>rand?0:pow; led_state[(ptn+2)%6] =Math.random()*100>rand?0:pow; break; case 2: led_state[(ptn+3)%6] =Math.random()*100>rand?0:pow; led_state[(ptn+4)%6] =Math.random()*100>rand?0:pow; break; } } //////// called from the outside // inport and advance generation public void set_inport(int dir, Led led ) { led_in[dir].init(led); if(led.power>0) { led_in[dir].gen+=1; /* System.out.println("inport1 id : "+id ); System.out.println("inport1 dir : "+dir ); System.out.println("inport1 pow : "+led_in[dir].power ); System.out.println("inport1 gen : "+led_in[dir].gen ); System.out.println(""); */ // decliment power if(led_in[dir].gen>0) led_in[dir].power-=decline; if(led_in[dir].gen>1) led_in[dir].power-=decline_sub; if(led_in[dir].power0) { /* System.out.println("inport2 id : "+id ); System.out.println("inport2 dir : "+dir ); System.out.println("inport2 pow : "+led_in[dir].power ); System.out.println("inport2 gen : "+led_in[dir].gen ); System.out.println(""); */ } } } //////// inner sim routines // hatch on button pressed private void hatch_six() { if(butt_state>0) //if button pushed hatch new electron { System.out.println("butt_state : "+butt_state ); System.out.println("max_energy : "+max_energy ); for(int i=0;i<6;i++) add_queue( i,new Led(butt_state,0) ); butt_state=0; } } // hatch three on collision with an electron private void hatch_three() { Led tled; for(int i=0;i<6;i++) { if(led_in[i].power>0) { tled=new Led( led_in[i],hatch_main ); if(tled.power>min_energy) add_queue( (i+3)%6, tled ); tled=new Led( led_in[i],hatch_sub ); if(tled.power>min_energy) { add_queue( (i+2)%6, tled ); add_queue( (i+4)%6, tled ); } /* if(Math.random()*4>3.5){ System.out.println("hatch 3 p: "+tled.power ); System.out.println("hatch 3 t: "+tled.timer ); System.out.println("hatch 3 g: "+tled.gen ); System.out.println(""); } */ led_in[i].init(); } } } // calc in & out port collision private void calc_collision_inout() { for(int i=0;i<6;i++) if(led_in[i].power>0) if((led_in[i].power-=led_out[i].power)<0) led_in[i].init(); else; } // calc collision for three-hatched private void calc_collision() { int j; // calc collision for the opposite direction for(int i=0;i<3;i++) { if(led_cue[i].power>0) { if((led_cue[i].power-=led_cue[i+3].power)<0) { led_cue[i+3].power=-1*led_cue[i].power; led_cue[i].init(0,GEN_MAX); j=i+3; }else { led_cue[i+3].init(0,GEN_MAX); j=i; } if(led_cue[j].power>cue_average[j]) { cue_num[j]=led_cue[j].power/cue_average[j]+1; }else { cue_average[j]=led_cue[j].power; cue_num[j]=1; } } } } // set led state private void set_led(boolean average) { int k=0; for(int i=0;i<6;i++,k=0) { led_state[i]=0; if(average) { if(cue_average[i]>0) led_state[i]=cue_average[i]; }else{ // accumulate led_state[i]=led_cue[i].power; } if(led_state[i]>max_energy)led_state[i]=max_energy; } } // set led_out private void set_led_out(boolean average) { for(int i=0;i<6;i++) { if(led_cue[i].power>0) { if(average) led_out[i].init(cue_average[i],led_cue[i].gen); else { led_out[i].init(led_cue[i]); if(led_out[i].power>max_energy) led_out[i].power=max_energy; } }else led_out[i].init(); } } // init led_cue private void init_led_cue() { for(int i=0;i<6;i++) { led_cue[i].init(0,GEN_MAX); cue_num[i]=0; cue_average[i]=0; } } /////////queue utililty proc // queue onto led_cue private void add_queue( int dir,Led led ) { led_cue[dir].power+=led.power; cue_num[dir]++; // generation will be over written if young if(led.gen==0) //just six-hatched { led_cue[dir].power=led.power; cue_num[dir]=1; }else if(led_cue[dir].gen>led.gen) led_cue[dir].gen = led.gen; cue_average[dir]=led_cue[dir].power/cue_num[dir]; } ///////////procedure for buttons // button start pressed public void start_press() { butt_t_start = true; System.out.println("atom "+id+" pressed"); } // button released public void butt_release() { butt_t_start = false; System.out.println("atom "+id+" releaseded" ); } // set butt_state according to the button pressed or not private void set_buttstate() { // if start press if( butt_t_start ) { butt_t+=inc_energy; if(butt_t>255)butt_t=255; }else { if(butt_t>min_energy) { butt_state=butt_t; butt_t=min_energy-1; } } } //TEST TEST public void set_buttstate(int energy ) { butt_state=energy; } // minimum changes from here //////////////init prcedure public void set_newparam(LedUnitParam lp) { this.lup=lp; //main hatching rate(0-100%) hatch_main=lup.atom_hatch_main; //sub hatching rate(0-100%) hatch_sub=lup.atom_hatch_sub; //decline rate decline=lup.atom_decline; //decline sub rate decline_sub=lup.atom_decline_sub; //electron energy incliments on button press inc_energy=lup.atom_inc_energy; //minimum electron energy min_energy=lup.atom_min_energy; //maximum electron energy max_energy=lup.atom_max_energy; //simulation interval interval=lup.interval; //button parameter butt_t = min_energy-1; //set led by average or largest if(lup.atom_average==1)average=true;else average=false; //collision on if(lup.atom_collision==1)collision=true;else collision=false; } public void setid(int num) { id=num; } public void connect(int dir, int id_num ) { out_t[dir]=id_num; } /////////////////Atom drawing procedure // draw Atom unit public void drawAtom(Graphics g,int cx, int cy,int s, int sp) { // cx,cy->center x,y, s size, sp spacing int cs=s/2; g.setColor(new Color((byte)butt_t,0,127)); g.fillRect( cx-cs, cy-cs, s, s);//button g.setColor(new Color((byte)(led_state[0]),0,0)); g.fillRect( cx-cs-sp, cy-cs, s, s);//LED 0 W g.setColor(new Color((byte)(led_state[1]),0,0)); g.fillRect( cx-cs-sp/2, cy-cs+sp, s, s);//LED 1 SW g.setColor(new Color((byte)(led_state[2]),0,0)); g.fillRect( cx-cs+sp/2, cy-cs+sp, s, s);//LED 2 SE g.setColor(new Color((byte)(led_state[3]),0,0)); g.fillRect( cx-cs+sp, cy-cs, s, s);//LED 3 E g.setColor(new Color((byte)(led_state[4]),0,0)); g.fillRect( cx-cs+sp/2, cy-cs-sp, s, s);//LED 4 NE g.setColor(new Color((byte)(led_state[5]),0,0)); g.fillRect( cx-cs-sp/2, cy-cs-sp, s, s);//LED 5 NW } /* // draw Atom unit public void drawAtom(Graphics g,int cx, int cy,int s, int sp) { // cx,cy->center x,y, s size, sp spacing int cs=s/2; g.setColor(new Color((byte)butt_t,0,127)); g.fillRect( cx-cs, cy-cs, s, s);//button g.setColor(new Color((byte)(led_state[0]),0,0)); g.fillRect( cx-cs-sp, cy-cs+(sp*6/10), s, s);//LED 0 W g.setColor(new Color((byte)(led_state[1]),0,0)); g.fillRect( cx-cs-sp, cy-cs-(sp*6/10), s, s);//LED 1 SW g.setColor(new Color((byte)(led_state[2]),0,0)); g.fillRect( cx-cs, cy-cs-(sp*12/10), s, s);//LED 2 SE g.setColor(new Color((byte)(led_state[3]),0,0)); g.fillRect( cx-cs+sp, cy-cs-(sp*6/10), s, s);//LED 3 E g.setColor(new Color((byte)(led_state[4]),0,0)); g.fillRect( cx-cs+sp, cy-cs+(sp*6/10), s, s);//LED 4 NE g.setColor(new Color((byte)(led_state[5]),0,0)); g.fillRect( cx-cs, cy-cs+(sp*12/10), s, s);//LED 5 NW } */ // Atom random color drawing public void drawAtom(Graphics g,int cx, int cy,int s, int sp,boolean rand) { // cx,cy->center x,y, s size, sp spacing int cs=s/2; int t=0; if(!rand){drawAtom(g,cx,cy,s,sp);return;} g.setColor(set_randColor(butt_t,127)); g.fillRect( cx-cs, cy-cs, s, s);//button g.setColor(set_randColor(led_state[0])); g.fillRect( cx-cs-sp, cy-cs, s, s);//LED 0 W g.setColor(set_randColor(led_state[1])); g.fillRect( cx-cs-sp/2, cy-cs+sp, s, s);//LED 1 SW g.setColor(set_randColor(led_state[2])); g.fillRect( cx-cs+sp/2, cy-cs+sp, s, s);//LED 2 SE g.setColor(set_randColor(led_state[3])); g.fillRect( cx-cs+sp, cy-cs, s, s);//LED 3 E g.setColor(set_randColor(led_state[4])); g.fillRect( cx-cs+sp/2, cy-cs-sp, s, s);//LED 4 NE g.setColor(set_randColor(led_state[5])); g.fillRect( cx-cs-sp/2, cy-cs-sp, s, s);//LED 5 NW } private Color set_randColor(int r) { int i=(int)(Math.random()*r)%256; int j=(int)(Math.random()*r)%256; return(new Color((byte)r,(byte)i,(byte)j )); } private Color set_randColor(int r,int b) { return(new Color((byte)r,(byte)(int)(Math.random()*r)%256,(byte)b )); } }