import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;

public class RectWaveGuideCrossCanvas extends Canvas{
	private static final Color bgcolor = new Color(216,230,230);
	private Image im;
	private Image im_palette;
	private MemoryImageSource mis;
	private int rgbPixels[];
	private int rgb_palette_Pixels[];
	private int new_width;
        private double max, min;
	private Color colorArray[];
        
        private int mapxy[][];
        public  double myarray[][];
        private double myarray_x[][];
        private double myarray_y[][];
        private double lean[][];
        private double maximoE = 0.0;
	
        private Graphics buf;
    
        private int width;
	private int height;
	private int palette_width, palette_height;
        
	private int LeftMargin, TopMargin, BottomMargin;
	private int LeftImageIndent, LeftPaletteIndent;
        
        public int resolution, res1, res2;
        public boolean linecolor_ON = false;
        public boolean lineblack_ON = false;
        public boolean backcolor_ON = true;
        
        private RectWaveGuide_State state;
	private boolean DirtyFlag;
        
        public boolean IsX, IsY, IsTot, IsS, IsTE, IsTM;
        
	public RectWaveGuideCrossCanvas(RectWaveGuide_State state){
		super();
		this.state = state;
                setBackground(bgcolor);
                
                width = state.s400;
                height = state.s400;
                palette_width = state.s20; 
                palette_height = state.s300+state.s40;
                LeftMargin = state.s25; 
                TopMargin = state.s10;
                BottomMargin = state.s20;
                LeftImageIndent = state.s35;
                LeftPaletteIndent = state.s400+state.s60;
        
                IsTot = true;
                IsX = false;
                IsY = false;
                IsS = false;
                IsTE = true;
                IsTM = false;
                
		new_width = (int)(width/state.a_to_b_ratio);
		rgbPixels = new int[new_width * height];
		rgb_palette_Pixels = new int[palette_width * palette_height];
		colorArray = new Color[256];
                mapxy = new int[new_width][height];
                myarray = new double[new_width][height];
                myarray_x = new double[new_width][height];
                myarray_y = new double[new_width][height];
                lean = new double[new_width][height];
                
		DirtyFlag = true;
                // HighRes = calculate value at each pixel
                // Medium Res = value every four pixels (almost as good visually)
                // Low Res = value every sixteen pixels (a bit grainy)
                // The best compromise is to use Medium Res
                resolution = 1; //1 = HighestRes; 2 = Medium Res; 3 = Low Res
                res1 = state.s35;
                res2 = (state.s400+state.s70+height)/2-state.s15;
                
                //Initialize the color palette
		//new palette
                for(int i = 0; i < 128; i++) {
		    colorArray[i] = new Color((2550000/128*i)/10000,(2550000/128*i)/10000,255);
		}
		for(int i = 128; i < 256; i++) {
		    colorArray[i] = new Color(255,255-2*(i-128),255-2*(i-128));
		}
	}
	
        @Override
        public void paint(Graphics g){
            if(im == null){
                im = createImage(getSize().width,getSize().height);
                buf = im.getGraphics();
                drawGraph(buf);
            }
            else{
                drawGraph(buf);
            }
            g.drawImage(im,0,0,null);
        }
            
        public void drawGraph(Graphics g){
            //g.draw3DRect(0,0,getSize().width-1,getSize().height-1,false);
            updatePixels(buf);
            //drawLabels(buf);
	    
	    drawAxis(buf);
            if(!lineblack_ON || IsS){
                drawPalette(buf);
            }
            drawLabels2(buf);
        }
	@Override
	public void update(Graphics g){      
            paint(g);
	}
		
	private void updatePixels(Graphics g){
	    int i=0, j=0, map=0;
	    double x, y; // min, max;
	    min = 0;
	    max =  min;
	    myarray = new double[new_width][height];
            myarray_x = new double[new_width][height];
            myarray_y = new double[new_width][height];
            mapxy = new int[new_width][height];
            lean = new double[new_width][height];
            maximoE = 0.0;
            
	    for(i = 0; i < new_width; i++){
		y = (new_width-1-i) * state.b/(new_width-1.0);
		for(j = 0; j < height; j++){
		    x = (height-1-j) * state.a/(height-1.0);
		    if(state.cut_off_frequency_for_mode > state.frequency){
                        myarray[i][j] = 0.0;
                        myarray_x[i][j] = 0.0;
                        myarray_y[i][j] = 0.0;
                        lean[i][j] = 0.0;
                    }
                    else{
                        if(IsTE){
                            if(IsX){
                                myarray[i][j] = state.getEFieldX(x,y);
                                myarray_x[i][j] = myarray[i][j];
                                myarray_y[i][j] = 0.0;
                                lean[i][j] = Math.abs(myarray_x[i][j]);   
                            }
                            else if(IsY){
                                myarray[i][j] = state.getEFieldY(x,y);
                                myarray_x[i][j] = 0.0;
                                myarray_y[i][j] = myarray[i][j];
                                lean[i][j] = Math.abs(myarray_y[i][j]);
                            }
                            else if(IsTot){
                                myarray[i][j] = state.getEFieldMagnitude(x,y);
                                myarray_x[i][j] = state.getEFieldX(x,y);
                                myarray_y[i][j] = state.getEFieldY(x,y);
                                lean[i][j] = Math.sqrt(myarray_x[i][j] * myarray_x[i][j] +
                                                       myarray_y[i][j] * myarray_y[i][j]);
                            }
                            else if(IsS){
                                myarray[i][j] = state.getPoyntingMagnitude(x,y);
                                lean[i][j] = myarray[i][j];
                            }
                        }
                        else if(IsTM){
                            if(IsX){
                                myarray[i][j] = state.getHFieldX(x,y);
                                myarray_x[i][j] = state.getHFieldX(x,y);
                                myarray_y[i][j] = 0.0;
                                lean[i][j] = Math.sqrt(myarray_x[i][j]);
                            }
                            else if(IsY){
                                myarray[i][j] = state.getHFieldY(x,y);
                                myarray_x[i][j] = 0.0;
                                myarray_y[i][j] = state.getHFieldY(x,y);
                                lean[i][j] = Math.sqrt(myarray_x[i][j]);
                            }
                            else if(IsTot){
                                myarray[i][j] = state.getHFieldMagnitude(x,y);
                                myarray_x[i][j] = state.getHFieldX(x,y);
                                myarray_y[i][j] = state.getHFieldY(x,y);
                                lean[i][j] = Math.sqrt(myarray_x[i][j] * myarray_x[i][j] +
                                                       myarray_y[i][j] * myarray_y[i][j]);
                            }
                            else if(IsS){
                                myarray[i][j] = state.getPoyntingMagnitude(x,y);
                                lean[i][j] = myarray[i][j];
                            }
                        }
                    }
		}
	    }
            
            min = MaestroA.getMin(myarray, new_width, height);
            max = MaestroA.getMax(myarray, new_width, height);
            maximoE = MaestroA.getMax(myarray, new_width, height);
            
            if(min == max){
                min = -1.0;
                max = 1.0;
            }
            myarray = null;
	}
	
	private void drawImage(Graphics g){
	   g.drawImage(im,LeftImageIndent,res1,this);
	}
	
	public void drawPalette(Graphics g){
	    int i, j, map;
            
            g.setColor(Color.black);
            
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
	    FontMetrics fm = g.getFontMetrics();
	    for(i = 0; i < palette_width; i++){
		for(j = 0; j < palette_height; j++){
		    map = (palette_height-1-j)*255/(palette_height-1);
		    if(map < 0) { map = 0;}
		    if(map >255) { map = 255; }
		    rgb_palette_Pixels[j*palette_width+i] = colorArray[map].getRGB();
		}
	    }
	    im_palette = createImage(new MemoryImageSource(palette_width,palette_height,
				rgb_palette_Pixels,0,palette_width));
	    g.drawImage(im_palette,LeftPaletteIndent,res1+state.s13,this);
	    
            //g.setColor(bgcolor);
            //g.fillRect(LeftPaletteIndent+palette_width+3,getSize().height/2-height/2-17,25,205);
            g.setColor(Color.black);
            
            MaestroG.subscripter(" +","","",g,state.font18,LeftPaletteIndent+palette_width+state.s3,res1+state.s20);
	    if(IsTot){ // Color means magnitude of the Field
                //MaestroG.subscripter(" 0","","",g,12,LeftPaletteIndent+palette_width+8,getSize().height/2-7);
                //MaestroG.subscripterB("_","","",g,14,LeftPaletteIndent+palette_width+8,res2-37);
                MaestroG.subscripter("0","","",g,state.font14,LeftPaletteIndent+palette_width+state.s8,res2-state.s32);
                if(IsTE){
                    MaestroG.subscripter("| E |","","",g,state.font14,LeftPaletteIndent+palette_width-state.s21,res2-state.s10);
                }
                else if(IsTM){
                    MaestroG.subscripter("| H |","","",g,state.font14,LeftPaletteIndent+palette_width-state.s21,res2-state.s10);
                }
            }
            else if(IsS){
               MaestroG.subscripter("0","","",g,state.font12,LeftPaletteIndent+palette_width+state.s8,res2-state.s32); 
            }
            else{}
            
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
            
            // Black frame for palette 
            g.drawRect(LeftPaletteIndent,res1+state.s13,
			palette_width,palette_height);
            
	}
	
	private void drawLabels(Graphics g){ // UNUSED
	    g.clearRect(2,2,getSize().width-2,state.s50);
            Graphics2D g2d = (Graphics2D)g;
            g.setFont(new Font("SanSerif",Font.PLAIN,state.font12));
	    FontMetrics fm = g.getFontMetrics();
	    g.setColor(Color.black);
	    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
	}
	
	private void drawLabels2(Graphics g){
	    Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
            g.setFont(new Font("SanSerif",Font.BOLD,state.font12));
	    FontMetrics fm = g.getFontMetrics();
	    
            if(state.IsTEmode){
		g.setColor(Color.red.darker());
		MaestroG.subscripterB("TE",""+state.mode_number1+","+state.mode_number2,"",g,state.font14,(getSize().width-fm.stringWidth("TM"+state.mode_number1+" "+state.mode_number2))-state.s20,state.s25);
	    }
	    else{
		g.setColor(Color.blue.darker());
		MaestroG.subscripterB("TM",""+state.mode_number1+","+state.mode_number2,"",g,state.font14,(getSize().width-fm.stringWidth("TM"+state.mode_number1+" "+state.mode_number2))-state.s20,state.s25);
	    }
            
            g.setFont(new Font("SanSerif",Font.BOLD,state.font11));
            if(IsS){
                g.setColor(Color.magenta.darker());
                MaestroG.subscripterAlt("Power Density Magnitude - S ","z","",g,state.font11,(getSize().width-fm.stringWidth("Power Density Magnitude - S ( x, y )"))/2,getSize().height-state.s5);
            }
            else if(IsTot){
                if(IsTE){
                    g.setColor(Color.red.darker());
                    g.drawString("Transverse Electric Field - E ( x, y )",(getSize().width-fm.stringWidth("Transverse Electric Field - E ( x, y )"))/2,getSize().height-state.s5);
                }
                else if(IsTM){
                    g.setColor(Color.blue.darker());
                    g.drawString("Transverse Magnetic Field - H ( x, y )",(getSize().width-fm.stringWidth("Transverse Magnetic Field - H ( x, y )"))/2,getSize().height-state.s5);
                }
            }    
	}
	
	private void drawAxis(Graphics g){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
            Color linecolor;
            linecolor = Color.black;
	    int i, j, map;
            int begin, end, btest, brest, bnum1, bnum2, bcenter, istep, start1, start2, startmap1, startmap2;
            
            //  ORIGINAL SETTING------------------------------------------------
            //istep = state.s19; //15;
            //startmap1 = LeftImageIndent-state.s10 + istep/2;
            //startmap2 = res1-state.s30 + istep/2;
            //start1 = LeftImageIndent-state.s10 + istep/2;
            //start2 = res1-state.s30 + istep/2;
            //------------------------------------------------------------------ 
            //btest = (new_width/istep)*istep;
            //brest = (new_width - btest)/2;
            //bnum1 = btest/istep;
            //bnum2 = height/istep;
            //==================================================================
            bnum2 = 22; // cjooseeven
            bcenter = bnum2/2 - 1;
            istep = (int)Math.floor((height/bnum2));
            bnum1 = (int)(new_width/istep);
            brest = (new_width - (bnum1*istep))/2;
            
            startmap1 = LeftImageIndent-state.s10 + istep/2;
            startmap2 = res1-state.s30 + istep/2;
            
            start1 = LeftImageIndent-state.s10 + istep/2;
            start2 = res1-state.s30 + istep/2;
            //==================================================================
            //  BACKGROUND
            g.setColor(bgcolor);
            g.fillRect(0,0,getSize().width,getSize().height);
            
            // Black Background when E or H field lines are displayed - Not for Poynting vector        
            if(linecolor_ON && !backcolor_ON && !IsS){
                g.setColor(Color.black);
                g.fillRect(LeftImageIndent-state.s4,res1-state.s25,new_width+state.s8,height+state.s8);
            }
            else if (lineblack_ON && !backcolor_ON && !IsS){
                g.setColor(Color.white);
                g.fillRect(LeftImageIndent-state.s4,res1-state.s25,new_width+state.s8,height+state.s8);
            }
            //==================================================================
            // COMPUTE PIXEL VALUES AND DRAW COLOR CROSS_SECTION
            //
            if(resolution == 1){
                for(i = 0; i < (new_width); i++){
                    for(j = 0; j < (height); j++){
                      
                      map = (int)MaestroA.mapper(lean[i][j]/maximoE,255.0,0.0,1.0,0.0);
                          if(map < 128){
                              {
                                    g.setColor(new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255));                        
                              }
                          }
                          else{
                            g.setColor(new Color(255,255-2*(map-128),255-2*(map-128)));
                          }
                      // DRAW PIXEL AS TINT RECTANGLE
                      if(backcolor_ON || IsS){g.fillRect(LeftImageIndent+i,startmap2+j+1,1,1);}
                    }
                }
            }
            else if(resolution == 2){
                map = 0;
                for(i = 0; i < (new_width/2+1); i++){
                    for(j = 0; j < (height/2+1); j++){
                      
                      if(i>=new_width/2 && j>=height/2){
                          map = (int)MaestroA.mapper(lean[(i-1)*2+1][(j-1)*2+1]/maximoE,255.0,0.0,1.0,0.0);
                      }
                      else if(i>=new_width/2){
                          map = (int)MaestroA.mapper(lean[(i-1)*2+1][j*2]/maximoE,255.0,0.0,1.0,0.0);
                      }
                      else if(j>=height/2){
                          map = (int)MaestroA.mapper(lean[i*2][(j-1)*2+1]/maximoE,255.0,0.0,1.0,0.0);
                      }
                      else if(i<new_width/2 && j<height/2){
                          map = (int)MaestroA.mapper(lean[i*2][j*2]/maximoE,255.0,0.0,1.0,0.0);
                      }
                      
                          if(map < 128 && map>0){
                            g.setColor(new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255));                        
                          }
                          else if(map == 0){
                              g.setColor(Color.blue);
                          }
                          else{
                            if(map < 0){
                                g.setColor(Color.green);
                            }
                            if(map> 255){
                                g.setColor(Color.magenta);
                                System.out.println("Magenta OMG  !!!!! "+map);
                            }
                            else{
                                g.setColor(new Color(255,255-2*(map-128),255-2*(map-128)));
                            }
                          }
                      if(backcolor_ON || IsS){g.fillRect(LeftImageIndent-1+i*2,startmap2+j*2,2,2);}
                    }
                }
            }
            else if(resolution == 3){
                map = 0;
                for(i = 0; i < (new_width/4+1); i++){
                    for(j = 0; j < (height/4+1); j++){
                      
                      if(i>=new_width/4 && j>=height/4){
                          map = (int)MaestroA.mapper(lean[(i-1)*4+1][(j-1)*4+1]/maximoE,255.0,0.0,1.0,0.0);
                      }
                      else if(i>=new_width/4){
                          map = (int)MaestroA.mapper(lean[(i-1)*4+1][j*4]/maximoE,255.0,0.0,1.0,0.0);
                      }
                      else if(j>=height/4){
                          map = (int)MaestroA.mapper(lean[i*4][(j-1)*4+1]/maximoE,255.0,0.0,1.0,0.0);
                      }
                      else if(i<new_width/4 && j<height/4){
                          map = (int)MaestroA.mapper(lean[i*4][j*4]/maximoE,255.0,0.0,1.0,0.0);
                      }
                          if(map < 128){
                            g.setColor(new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255));                        
                          }
                          else{
                            g.setColor(new Color(255,255-2*(map-128),255-2*(map-128)));
                          }
                      if(backcolor_ON || IsS){g.fillRect(startmap1+i*4,startmap2+j*4,4,4);}
                    }
                }
            }
            //==================================================================
            // DRAW THE AXES
            //
            g.setColor(Color.black);
	    //Vertical axis
	    g.drawLine(LeftImageIndent/2,res2+state.s18,LeftImageIndent/2,res1-state.s15);
	    //Draw Arrow
	    MaestroG.drawArrow(LeftImageIndent/2,res1-state.s15,5,g);
	    
	    g.drawLine(state.s8,res2+state.s10,state.s400+state.s35,res2+state.s10);
	    //Draw Arrow
	    MaestroG.drawArrow(state.s400+state.s35,res2+state.s10,7,g);
	    
            //normal (z) axis --------------------------------------------------
            g.setColor(Color.white);
            MaestroG.fillCircle(LeftImageIndent/2,res2+state.s10, state.s10, g);
            g.setColor(Color.black);
            MaestroG.drawCircle(LeftImageIndent/2,res2+state.s10, state.s10, g);
            g.drawLine(LeftImageIndent/2-state.s3,res2+state.s7,LeftImageIndent/2+state.s3,res2+state.s13);
            g.drawLine(LeftImageIndent/2-state.s3,res2+state.s13,LeftImageIndent/2+state.s3,res2+state.s7);
            //------------------------------------------------------------------
            
	    g.setFont(new Font("Sanserif",Font.BOLD,state.font12));
	    FontMetrics fm = g.getFontMetrics();
	    g.drawString("x",state.s5,state.s15);
	    g.drawString("y",state.s400+state.s40,res2+state.s22);
            
            g.drawString("z",state.s5,res2+state.s24);
            //==================================================================
	    //draw plates
	    g.drawRect(LeftImageIndent-state.s5,res1-state.s25,new_width+state.s9,height+state.s9);
	    g.drawRect(LeftImageIndent-state.s2,res1-state.s22,new_width+state.s3,height+state.s3);
	    g.setColor(Color.cyan);
	    g.drawRect(LeftImageIndent-state.s3,res1-state.s23,new_width+state.s5,height+state.s5);
	    g.drawRect(LeftImageIndent-state.s4,res1-state.s24,new_width+state.s7,height+state.s7);
            //==================================================================
            // BELOW DRAWS FIELD VECTORS
            //==================================================================
            
            g.setColor(Color.black);
            double leano = 0.0;
            double arrow_angle = 18.0;
            int rad = state.s6; // scaling factor for x and y component of field to trace stem of vector
            double igo, jgo, igo2, jgo2;
	    int ii = 0; int jj = 0;
            double i1,i2,i3,i4;
            int linethick = 1;
            double Leng = (double)state.s6;// scaling factor for arrow
            double angolo = 0.0; double angolo2 = 0.0;
            double angus, angus2; double plus1, plus2, plus3, plus4; int iplus1, iplus2, iplus3, iplus4;
            
            if(!IsS){
            
            // DRAW FIELD VECTORS
            if(state.mode_number2 == 0) // first set of parallel waveguide modes
            {            
                for(i = 0; i < bnum1-1; i++){
                    for(j = 0; j < bnum2-1; j++){
                      // selected locations of vectors arranged in a rectangular grid
                      ii = (i+1)*istep;
                      jj = (j+1)*istep;

                      leano = lean[ii][jj];
                      // DETERMINE LENGTH AND THICKNESS OF VECTOR BASED ON INTENSITY (linethick is not scaled with sfactor not to make vectors too fat)
                      if(leano <= 0.05*maximoE){rad = state.s3; Leng = (double)state.s2; linethick = 1;}
                      else if(leano <= 0.25*maximoE && leano > 0.05*maximoE){rad = state.s4; Leng = (double)state.s3; linethick = 1;}
                      else if(leano <= 0.5*maximoE && leano > 0.25*maximoE){rad = state.s5; Leng = (double)state.s4; linethick = 1;}
                      else if(leano <= 0.75*maximoE && leano > 0.5*maximoE){rad = state.s6; Leng = (double)state.s5; linethick = 2;}
                      else if(leano > 0.75*maximoE){rad = state.s7; Leng = (double)state.s6; linethick = 2;}
                      
                      igo = (double)(start1 + brest + ii);
                      jgo = 0.0;
                      if(j == bcenter){jgo = (double)(startmap2+height/2);}
                      else if(j < bcenter){jgo = (double)(startmap2+height/2 - (bcenter-j)*istep);}
                      else if(j > bcenter){jgo = (double)(startmap2+height/2 + (j-bcenter)*istep);}
                      //jgo = (double)(start2new + jj);
                      igo2 = rad*myarray_y[ii][jj]/leano;
                      jgo2 = rad*myarray_x[ii][jj]/leano;
                      
                      map = (int)MaestroA.mapper(leano/maximoE,255.0,0.0,1.0,0.0);
                      
                      if(!backcolor_ON && linecolor_ON && !lineblack_ON && !IsS){
                          if(map < 128){
                            g.setColor(new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255));
                            linecolor = new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255);
                          }
                          else{
                            g.setColor(new Color(255,255-2*(map-128),255-2*(map-128)));
                            linecolor = new Color(255,255-2*(map-128),255-2*(map-128));
                          }
                      }
                      else if(!backcolor_ON && !linecolor_ON && lineblack_ON && !IsS){
                          linecolor = Color.black;
                      }
                      //--------------------------------------------------------
                      i1=igo-igo2; i2 = jgo-jgo2; i3 = igo+igo2; i4 = jgo+jgo2;
                      angus = Math.atan((i4-i2)/(i3-i1));
                      angus2 = arrow_angle*Math.PI/180.0;
                      //--------------------------------------------------------
                      plus1 = i4-Leng*Math.sin(angus + angus2);              
                      iplus1 = (int)plus1; 
                      if(Math.abs(plus1-iplus1)<0.5){
                          plus1 = Math.abs(iplus1)*Math.signum(plus1);
                      }
                      else{
                          plus1 = Math.abs(iplus1+1)*Math.signum(plus1);
                      }
                      //--------------------------------------------------------
                      plus2 = i4+Leng*Math.sin(angus + angus2);
                      iplus2 = (int)plus2; 
                      if(Math.abs(plus2-iplus2)<0.5){
                          plus2 = Math.abs(iplus2)*Math.signum(plus2);
                      }
                      else{
                          plus2 = Math.abs(iplus2+1)*Math.signum(plus2);
                      }
                      //--------------------------------------------------------
                      
                      drawLineThick(g,i1,i2,i3,i4,linethick,linecolor);
                      //--------------------------------------------------------
                      if(i1>i3)
                      {   
                        drawLineThick(g,i1,i2,i1-Leng*Math.cos(angus + angus2),plus1,linethick,linecolor);
                        drawLineThick(g,i1,i2,i1-Leng*Math.cos(angus + angus2),plus2,linethick,linecolor);
                      }
                      else{
                        drawLineThick(g,i1,i2,i1+Leng*Math.cos(angus+ angus2),plus2,linethick,linecolor);
                        drawLineThick(g,i1,i2,i1+Leng*Math.cos(angus+ angus2),plus1,linethick,linecolor);
                      }
                    }
                }
	    }
            
            else if(state.mode_number1 == 0){  // second set of parallel waveguide modes
                for(i = 0; i < bnum1-1; i++){
                    for(j = 0; j < bnum2-1; j++){
                      ii = (i+1)*istep;
                      jj = (j+1)*istep;

                      leano = lean[ii][jj];
                      
                      // DETERMINE LENGTH AND THICKNESS OF VECTOR BASED ON INTENSITY (linethick is not scaled with sfactor not to make vectors too fat)
                      if(leano <= 0.05*maximoE){rad = state.s3; Leng = (double)state.s2; linethick = 1;}
                      else if(leano <= 0.25*maximoE && leano > 0.05*maximoE){rad = state.s4; Leng = (double)state.s3; linethick = 1;}
                      else if(leano <= 0.5*maximoE && leano > 0.25*maximoE){rad = state.s5; Leng = (double)state.s4; linethick = 1;}
                      else if(leano <= 0.75*maximoE && leano > 0.5*maximoE){rad = state.s6; Leng = (double)state.s5; linethick = 2;}
                      else if(leano > 0.75*maximoE){rad = state.s7; Leng = (double)state.s6; linethick = 2;}
                      
                      igo = (double)(start1 + brest + ii);
                      jgo = 0.0;
                      if(j == bcenter){jgo = (double)(startmap2+height/2);}
                      else if(j < bcenter){jgo = (double)(startmap2+height/2 - (bcenter-j)*istep);}
                      else if(j > bcenter){jgo = (double)(startmap2+height/2 + (j-bcenter)*istep);}
                      
                      //jgo = (double)(start2 + jj);
                      igo2 = rad*myarray_y[ii][jj]/leano;
                      jgo2 = rad*myarray_x[ii][jj]/leano;

                      map = (int)MaestroA.mapper(leano/maximoE,255.0,0.0,1.0,0.0);
                      
                      if(!backcolor_ON && linecolor_ON && !lineblack_ON && !IsS){
                          if(map < 128){
                            g.setColor(new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255));
                            linecolor = new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255);
                          }
                          else{
                            g.setColor(new Color(255,255-2*(map-128),255-2*(map-128)));
                            linecolor = new Color(255,255-2*(map-128),255-2*(map-128));
                          }
                      }
                      else if(!backcolor_ON && !linecolor_ON && lineblack_ON && !IsS){
                          linecolor = Color.black;
                      }
                      
                      //--------------------------------------------------------
                      i1=igo-igo2; i2 = jgo-jgo2; i3 = igo+igo2; i4 = jgo+jgo2;
                      angus = Math.PI; //Math.atan((i4-i2)/(i3-i1));
                      angus2 = arrow_angle*Math.PI/180.0;
                      //--------------------------------------------------------
                      plus1 = i1-Leng*Math.sin(angus - angus2);              
                      iplus1 = (int)plus1; 
                      if(Math.abs(plus1-iplus1)<0.5){
                          plus1 = Math.abs(iplus1)*Math.signum(plus1);
                      }
                      else{
                          plus1 = Math.abs(iplus1+1)*Math.signum(plus1);
                      }
                      //--------------------------------------------------------
                      plus2 = i1+Leng*Math.sin(angus - angus2);
                      iplus2 = (int)plus2; 
                      if(Math.abs(plus2-iplus2)<0.5){
                          plus2 = Math.abs(iplus2)*Math.signum(plus2);
                      }
                      else{
                          plus2 = Math.abs(iplus2+1)*Math.signum(plus2);
                      }
                      //--------------------------------------------------------
                      
                      drawLineThick(g,i1,i2,i3,i4,linethick,linecolor);
                      //--------------------------------------------------------
                      if(i2>i4)
                      {   
                        drawLineThick(g,i1,i2,plus1,i2+Leng*Math.cos(angus- angus2),linethick,linecolor);
                        drawLineThick(g,i1,i2,plus2,i2+Leng*Math.cos(angus- angus2),linethick,linecolor);
                      }
                      else{
                        drawLineThick(g,i1,i2,plus2,i2-Leng*Math.cos(angus- angus2),linethick,linecolor);
                        drawLineThick(g,i1,i2,plus1,i2-Leng*Math.cos(angus- angus2),linethick,linecolor);
                      }     
                    }
                }
            }
            else // rectangular modes
            
            {    
                if (bnum1/2 == ((bnum1-1)/2) ){// bnum1 == odd ---> even number of field lines
                    for(i = 0; i < (bnum1-1)/2; i++){
                    for(j = 0; j < bnum2-1; j++){
                          ii = new_width/2+1 -istep/2 - (i)*istep;
                          jj = (j+1)*istep;

                          leano = lean[ii][jj];

                        // DETERMINE LENGTH AND THICKNESS OF VECTOR BASED ON INTENSITY (linethick is not scaled with sfactor not to make vectors too fat)
                        if(leano <= 0.05*maximoE){rad = state.s3; Leng = (double)state.s2; linethick = 1;}
                        else if(leano <= 0.25*maximoE && leano > 0.05*maximoE){rad = state.s4; Leng = (double)state.s3; linethick = 1;}
                        else if(leano <= 0.5*maximoE && leano > 0.25*maximoE){rad = state.s5; Leng = (double)state.s4; linethick = 1;}
                        else if(leano <= 0.75*maximoE && leano > 0.5*maximoE){rad = state.s6; Leng = (double)state.s5; linethick = 2;}
                        else if(leano > 0.75*maximoE){rad = state.s7; Leng = (double)state.s6; linethick = 2;}
                          
                        igo = (double)(start1 + ii);
                        jgo = 0.0;
                        if(j == bcenter){jgo = (double)(startmap2+height/2);}
                        else if(j < bcenter){jgo = (double)(startmap2+height/2 - (bcenter-j)*istep);}
                        else if(j > bcenter){jgo = (double)(startmap2+height/2 + (j-bcenter)*istep);}
                        //jgo = (double)(start2 + jj);
                        igo2 = rad*myarray_y[ii][jj]/leano;
                        jgo2 = rad*myarray_x[ii][jj]/leano;

                          map = (int)MaestroA.mapper(leano/maximoE,255.0,0.0,1.0,0.0);
                          
                          if(!backcolor_ON && linecolor_ON && !lineblack_ON && !IsS){
                              if(map < 128){
                                g.setColor(new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255));
                                linecolor = new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255);
                              }
                              else{
                                g.setColor(new Color(255,255-2*(map-128),255-2*(map-128)));
                                linecolor = new Color(255,255-2*(map-128),255-2*(map-128));
                              }
                          }
                          else if(!backcolor_ON && !linecolor_ON && lineblack_ON && !IsS){
                            linecolor = Color.black;
                          }
                          //--------------------------------------------------------
                          i1=igo-igo2; i2 = jgo-jgo2; i3 = igo+igo2; i4 = jgo+jgo2;
                          angus = Math.atan((i4-i2)/(i3-i1));
                          angus2 = arrow_angle*Math.PI/180.0;
                          drawLineThick(g,i1,i2,i3,i4,linethick,linecolor);

                          if(i1>i3)
                          {   
                            drawLineThick(g,i1,i2,i1-Leng*Math.cos(angus+ angus2),i2-Leng*Math.sin(angus+ angus2),linethick,linecolor);
                            drawLineThick(g,i1,i2,i1-Leng*Math.cos(angus- angus2),i2-Leng*Math.sin(angus- angus2),linethick,linecolor);
                          }
                          else{
                            drawLineThick(g,i1,i2,i1+Leng*Math.cos(angus+ angus2),i2+Leng*Math.sin(angus+ angus2),linethick,linecolor);
                            drawLineThick(g,i1,i2,i1+Leng*Math.cos(angus- angus2),i2+Leng*Math.sin(angus- angus2),linethick,linecolor);
                          }     
                        }
                    }
                    
                    for(i = 0; i < (bnum1-1)/2; i++){
                    for(j = 0; j < bnum2-1; j++){
                        
                          ii = new_width/2+1 + istep/2 + (i)*istep;
                          jj = (j+1)*istep;

                          leano = lean[ii][jj];

                            // DETERMINE LENGTH AND THICKNESS OF VECTOR BASED ON INTENSITY (linethick is not scaled with sfactor not to make vectors too fat)
                      if(leano <= 0.05*maximoE){rad = state.s3; Leng = (double)state.s2; linethick = 1;}
                      else if(leano <= 0.25*maximoE && leano > 0.05*maximoE){rad = state.s4; Leng = (double)state.s3; linethick = 1;}
                      else if(leano <= 0.5*maximoE && leano > 0.25*maximoE){rad = state.s5; Leng = (double)state.s4; linethick = 1;}
                      else if(leano <= 0.75*maximoE && leano > 0.5*maximoE){rad = state.s6; Leng = (double)state.s5; linethick = 2;}
                      else if(leano > 0.75*maximoE){rad = state.s7; Leng = (double)state.s6; linethick = 2;}
                      
                      //if(leano <= 0.05*maximoE){rad = 3; Leng = 1.0; linethick = 1;}
                      //else if(leano <= 0.25*maximoE && leano > 0.05*maximoE){rad = 3; Leng = 2.0; linethick = 1;}
                      //else if(leano <= 0.5*maximoE && leano > 0.25*maximoE){rad = 4; Leng = 3.0; linethick = 1;}
                      //else if(leano <= 0.75*maximoE && leano > 0.5*maximoE){rad = 5; Leng = 3.0; linethick = 2;}
                      //else if(leano > 0.75*maximoE){rad = 5; Leng = 4.0; linethick = 2;}
                      
                        igo = (double)(start1 + ii);
                        jgo = 0.0;
                        if(j == bcenter){jgo = (double)(startmap2+height/2);}
                        else if(j < bcenter){jgo = (double)(startmap2+height/2 - (bcenter-j)*istep);}
                        else if(j > bcenter){jgo = (double)(startmap2+height/2 + (j-bcenter)*istep);}
                        //jgo = (double)(start2 + jj);
                        igo2 = rad*myarray_y[ii][jj]/leano;
                        jgo2 = rad*myarray_x[ii][jj]/leano;

                          map = (int)MaestroA.mapper(leano/maximoE,255.0,0.0,1.0,0.0);
                          
                          if(!backcolor_ON && linecolor_ON && !lineblack_ON && !IsS){
                              if(map < 128){
                                g.setColor(new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255));
                                linecolor = new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255);
                              }
                              else{
                                g.setColor(new Color(255,255-2*(map-128),255-2*(map-128)));
                                linecolor = new Color(255,255-2*(map-128),255-2*(map-128));
                              }
                          }
                          else if(!backcolor_ON && !linecolor_ON && lineblack_ON && !IsS){
                                linecolor = Color.black;
                          }
                          //--------------------------------------------------------
                          i1=igo-igo2; i2 = jgo-jgo2; i3 = igo+igo2; i4 = jgo+jgo2;
                          angus = Math.atan((i4-i2)/(i3-i1));
                          angus2 = arrow_angle*Math.PI/180.0;
                          drawLineThick(g,i1,i2,i3,i4,linethick,linecolor);

                          if(i1>i3)
                          {   
                            drawLineThick(g,i1,i2,i1-Leng*Math.cos(angus+ angus2),i2-Leng*Math.sin(angus+ angus2),linethick,linecolor);
                            drawLineThick(g,i1,i2,i1-Leng*Math.cos(angus- angus2),i2-Leng*Math.sin(angus- angus2),linethick,linecolor);
                          }
                          else{
                            drawLineThick(g,i1,i2,i1+Leng*Math.cos(angus+ angus2),i2+Leng*Math.sin(angus+ angus2),linethick,linecolor);
                            drawLineThick(g,i1,i2,i1+Leng*Math.cos(angus- angus2),i2+Leng*Math.sin(angus- angus2),linethick,linecolor);
                          }     
                        }
                    }
                    
            }
            else{ // bnum1 == even ---> odd number of field lines
                  // The code below tries to symmetrize field lines as much as possible
                    for(i = 0; i < (bnum1-1)/2; i++){
                    for(j = 0; j < bnum2-1; j++){
                          ii = new_width/2+1 - (i+1)*istep;
                          jj = (j+1)*istep;

                          leano = lean[ii][jj];

                          // DETERMINE LENGTH AND THICKNESS OF VECTOR BASED ON INTENSITY (linethick is not scaled with sfactor not to make vectors too fat)
                      if(leano <= 0.05*maximoE){rad = state.s3; Leng = (double)state.s2; linethick = 1;}
                      else if(leano <= 0.25*maximoE && leano > 0.05*maximoE){rad = state.s4; Leng = (double)state.s3; linethick = 1;}
                      else if(leano <= 0.5*maximoE && leano > 0.25*maximoE){rad = state.s5; Leng = (double)state.s4; linethick = 1;}
                      else if(leano <= 0.75*maximoE && leano > 0.5*maximoE){rad = state.s6; Leng = (double)state.s5; linethick = 2;}
                      else if(leano > 0.75*maximoE){rad = state.s7; Leng = (double)state.s6; linethick = 2;}
                      
                      //if(leano <= 0.05*maximoE){rad = 3; Leng = 1.0; linethick = 1;}
                      //else if(leano <= 0.25*maximoE && leano > 0.05*maximoE){rad = 3; Leng = 2.0; linethick = 1;}
                      //else if(leano <= 0.5*maximoE && leano > 0.25*maximoE){rad = 4; Leng = 3.0; linethick = 1;}
                      //else if(leano <= 0.75*maximoE && leano > 0.5*maximoE){rad = 5; Leng = 3.0; linethick = 2;}
                      //else if(leano > 0.75*maximoE){rad = 5; Leng = 4.0; linethick = 2;}
                      
                        igo = (double)(start1 + ii);
                        jgo = 0.0;
                        if(j == bcenter){jgo = (double)(startmap2+height/2);}
                        else if(j < bcenter){jgo = (double)(startmap2+height/2 - (bcenter-j)*istep);}
                        else if(j > bcenter){jgo = (double)(startmap2+height/2 + (j-bcenter)*istep);}
                        //jgo = (double)(start2 + jj);
                        igo2 = rad*myarray_y[ii][jj]/leano;
                        jgo2 = rad*myarray_x[ii][jj]/leano;

                          map = (int)MaestroA.mapper(leano/maximoE,255.0,0.0,1.0,0.0);

                            if(!backcolor_ON && linecolor_ON && !lineblack_ON && !IsS){
                                if(map < 128){
                                    g.setColor(new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255));
                                    linecolor = new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255);
                                }
                                else{
                                    g.setColor(new Color(255,255-2*(map-128),255-2*(map-128)));
                                    linecolor = new Color(255,255-2*(map-128),255-2*(map-128));
                                }
                            }
                            else if(!backcolor_ON && !linecolor_ON && lineblack_ON && !IsS){
                                    linecolor = Color.black;
                            }
                      
                          //--------------------------------------------------------
                          i1=igo-igo2; i2 = jgo-jgo2; i3 = igo+igo2; i4 = jgo+jgo2;
                          angus = Math.atan((i4-i2)/(i3-i1));
                          angus2 = arrow_angle*Math.PI/180.0;
                          drawLineThick(g,i1,i2,i3,i4,linethick,linecolor);

                          if(i1>i3)
                          {   
                            drawLineThick(g,i1,i2,i1-Leng*Math.cos(angus+ angus2),i2-Leng*Math.sin(angus+ angus2),linethick,linecolor);
                            drawLineThick(g,i1,i2,i1-Leng*Math.cos(angus- angus2),i2-Leng*Math.sin(angus- angus2),linethick,linecolor);
                          }
                          else{
                            drawLineThick(g,i1,i2,i1+Leng*Math.cos(angus+ angus2),i2+Leng*Math.sin(angus+ angus2),linethick,linecolor);
                            drawLineThick(g,i1,i2,i1+Leng*Math.cos(angus- angus2),i2+Leng*Math.sin(angus- angus2),linethick,linecolor);
                          }     
                        }
                    }
                    
                    for(i = 0; i < (bnum1-1)/2; i++){
                    for(j = 0; j < bnum2-1; j++){
                          
                          ii = new_width/2+1 + (i+1)*istep;
                          jj = (j+1)*istep;

                          leano = lean[ii][jj];

                            // DETERMINE LENGTH AND THICKNESS OF VECTOR BASED ON INTENSITY (linethick is not scaled with sfactor not to make vectors too fat)
                      if(leano <= 0.05*maximoE){rad = state.s3; Leng = (double)state.s2; linethick = 1;}
                      else if(leano <= 0.25*maximoE && leano > 0.05*maximoE){rad = state.s4; Leng = (double)state.s3; linethick = 1;}
                      else if(leano <= 0.5*maximoE && leano > 0.25*maximoE){rad = state.s5; Leng = (double)state.s4; linethick = 1;}
                      else if(leano <= 0.75*maximoE && leano > 0.5*maximoE){rad = state.s6; Leng = (double)state.s5; linethick = 2;}
                      else if(leano > 0.75*maximoE){rad = state.s7; Leng = (double)state.s6; linethick = 2;}
                      
                      //if(leano <= 0.05*maximoE){rad = 3; Leng = 1.0; linethick = 1;}
                      //else if(leano <= 0.25*maximoE && leano > 0.05*maximoE){rad = 3; Leng = 2.0; linethick = 1;}
                      //else if(leano <= 0.5*maximoE && leano > 0.25*maximoE){rad = 4; Leng = 3.0; linethick = 1;}
                      //else if(leano <= 0.75*maximoE && leano > 0.5*maximoE){rad = 5; Leng = 3.0; linethick = 2;}
                      //else if(leano > 0.75*maximoE){rad = 5; Leng = 4.0; linethick = 2;}
                      
                        igo = (double)(start1 + ii);
                        jgo = 0.0;
                        if(j == bcenter){jgo = (double)(startmap2+height/2);}
                        else if(j < bcenter){jgo = (double)(startmap2+height/2 - (bcenter-j)*istep);}
                        else if(j > bcenter){jgo = (double)(startmap2+height/2 + (j-bcenter)*istep);}
                        //jgo = (double)(start2 + jj);
                        igo2 = rad*myarray_y[ii][jj]/leano;
                        jgo2 = rad*myarray_x[ii][jj]/leano;

                          map = (int)MaestroA.mapper(leano/maximoE,255.0,0.0,1.0,0.0);

                            if(!backcolor_ON && linecolor_ON && !lineblack_ON && !IsS){
                                if(map < 128){
                                    g.setColor(new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255));
                                    linecolor = new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255);
                                }
                                else{
                                    g.setColor(new Color(255,255-2*(map-128),255-2*(map-128)));
                                    linecolor = new Color(255,255-2*(map-128),255-2*(map-128));
                                }
                            }
                            else if(!backcolor_ON && !linecolor_ON && lineblack_ON && !IsS){
                                    linecolor = Color.black;
                            }
                      
                          //--------------------------------------------------------
                          i1=igo-igo2; i2 = jgo-jgo2; i3 = igo+igo2; i4 = jgo+jgo2;
                          angus = Math.atan((i4-i2)/(i3-i1));
                          angus2 = arrow_angle*Math.PI/180.0;
                          drawLineThick(g,i1,i2,i3,i4,linethick,linecolor);

                          if(i1>i3)
                          {   
                            drawLineThick(g,i1,i2,i1-Leng*Math.cos(angus+ angus2),i2-Leng*Math.sin(angus+ angus2),linethick,linecolor);
                            drawLineThick(g,i1,i2,i1-Leng*Math.cos(angus- angus2),i2-Leng*Math.sin(angus- angus2),linethick,linecolor);
                          }
                          else{
                            drawLineThick(g,i1,i2,i1+Leng*Math.cos(angus+ angus2),i2+Leng*Math.sin(angus+ angus2),linethick,linecolor);
                            drawLineThick(g,i1,i2,i1+Leng*Math.cos(angus- angus2),i2+Leng*Math.sin(angus- angus2),linethick,linecolor);
                          }     
                        }
                    } 
                    
                    for(j = 0; j < bnum2-1; j++){
                          //ii = (i+1)*istep;
                          ii = new_width/2+1;
                          jj = (j+1)*istep;

                          leano = lean[ii][jj];

                            // DETERMINE LENGTH AND THICKNESS OF VECTOR BASED ON INTENSITY (linethick is not scaled with sfactor not to make vectors too fat)
                      if(leano <= 0.05*maximoE){rad = state.s3; Leng = (double)state.s2; linethick = 1;}
                      else if(leano <= 0.25*maximoE && leano > 0.05*maximoE){rad = state.s4; Leng = (double)state.s3; linethick = 1;}
                      else if(leano <= 0.5*maximoE && leano > 0.25*maximoE){rad = state.s5; Leng = (double)state.s4; linethick = 1;}
                      else if(leano <= 0.75*maximoE && leano > 0.5*maximoE){rad = state.s6; Leng = (double)state.s5; linethick = 2;}
                      else if(leano > 0.75*maximoE){rad = state.s7; Leng = (double)state.s6; linethick = 2;}
                      
                        igo = (double)(start1 + ii);
                        jgo = 0.0;
                        if(j == bcenter){jgo = (double)(startmap2+height/2);}
                        else if(j < bcenter){jgo = (double)(startmap2+height/2 - (bcenter-j)*istep);}
                        else if(j > bcenter){jgo = (double)(startmap2+height/2 + (j-bcenter)*istep);}
                        //jgo = (double)(start2 + jj);
                        igo2 = rad*myarray_y[ii][jj]/leano;
                        jgo2 = rad*myarray_x[ii][jj]/leano;

                          map = (int)MaestroA.mapper(leano/maximoE,255.0,0.0,1.0,0.0);

                            if(!backcolor_ON && linecolor_ON && !lineblack_ON && !IsS){
                                if(map < 128){
                                    g.setColor(new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255));
                                    linecolor = new Color((2550000/128*map)/10000,(2550000/128*map)/10000,255);
                                }
                                else{
                                    g.setColor(new Color(255,255-2*(map-128),255-2*(map-128)));
                                    linecolor = new Color(255,255-2*(map-128),255-2*(map-128));
                                }
                            }
                            else if(!backcolor_ON && !linecolor_ON && lineblack_ON && !IsS){
                                    linecolor = Color.black;
                            }
                      
                          //--------------------------------------------------------
                          i1=igo-igo2; i2 = jgo-jgo2; i3 = igo+igo2; i4 = jgo+jgo2;
                          angus = Math.atan((i4-i2)/(i3-i1));
                          angus2 = arrow_angle*Math.PI/180.0;
                          drawLineThick(g,i1,i2,i3,i4,linethick,linecolor);

                          if(i1>i3)
                          {   
                            drawLineThick(g,i1,i2,i1-Leng*Math.cos(angus+ angus2),i2-Leng*Math.sin(angus+ angus2),linethick,linecolor);
                            drawLineThick(g,i1,i2,i1-Leng*Math.cos(angus- angus2),i2-Leng*Math.sin(angus- angus2),linethick,linecolor);
                          }
                          else{
                            drawLineThick(g,i1,i2,i1+Leng*Math.cos(angus+ angus2),i2+Leng*Math.sin(angus+ angus2),linethick,linecolor);
                            drawLineThick(g,i1,i2,i1+Leng*Math.cos(angus- angus2),i2+Leng*Math.sin(angus- angus2),linethick,linecolor);
                          }     
                        }
                }  
              }
     
            }

	}
        
        private void drawLineThick(Graphics g, double x1, double y1, double x2, double y2, int thick, Color color){
	
            Graphics2D g2d = (Graphics2D)g;
            g2d.setPaint(color);
            g2d.setStroke(new BasicStroke(thick,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));

            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

            Line2D.Double line = new Line2D.Double(x1,y1,x2,y2);
            g2d.draw(line);

            g2d.setStroke(new BasicStroke(1));
            //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        }
	
	public void setDirtyFlag(boolean DirtyFlag){
	    this.DirtyFlag = DirtyFlag;
	}
	
	public void setWidth(double ratio){
	    this.new_width=(int)(width/ratio);
	    this.rgbPixels=new int[(int)(width/ratio*height)];
	}
        
}	

