Visualizzazione dei risultati da 1 a 10 su 69

Discussione: Inserimento Scroll

Visualizzazione discussione

  1. #1

    Inserimento Scroll

    questo è un progetto per disegnare il frattale di mandelbrot soltanto che quando provo ad inserire lo scroll non va, o meglio non mi compaiono le scrollbar ma il disegno me lo fa
    codice:
    import java.awt.Canvas;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.util.Random;
    import java.awt.Color;
    import java.io.*;
    import java.util.*;
    import javax.swing.JFrame;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    public class PixelCanvas extends Canvas {
    	
    	
    	public static Color colore(int c){
    	Color f;
        int i = c % 16;
       if(i==0)
      return f=new Color(66, 30, 15);
        if(i==1)
        return f=new Color(25, 7, 26);
        if(i==2)
        return f=new Color(9, 1, 47);
         if(i==3)
       return f=new Color(4, 4, 73);
         if(i==4)
        return f=new Color(0, 7, 100);
         if(i==5)
       return f=new Color(12, 44, 138);
         if(i==6)
        return f=new Color(24, 82, 177);
         if(i==7)
       return f=new Color(57, 125, 209);
         if(i==8)
       return f=new Color(134, 181, 229);
         if(i==9)
        return f=new Color(211, 236, 248);
         if(i==10)
        return f=new Color(241, 233, 191);
         if(i==11)
       return f=new Color(248, 201, 95);
         if(i==12)
       return f=new Color(255, 170, 0);
         if(i==13)
       return f=new Color(204, 128, 0);
         if(i==14)
        return f=new Color(153, 87, 0);
         if(i==15)
        return f=new Color(106, 52, 3);
       return f=new Color(106, 52, 3);
    	}
    	   
        public static Color colore2(int c){
        	Color f;
    if (c < 64) {
      return f=new Color(c * 2, 0, 0);    
    } else if (c < 128) {
      return f=new Color  ((((c - 64) * 128) / 126) + 128, 0, 0);    /* 0x0080 to 0x00C0 */
    } else if (c < 256) {
      return f=new Color  ((((c - 128) * 62) / 127) + 193, 0, 0);    /* 0x00C1 to 0x00FF */
    } else if (c < 512) {
      return f=new Color  (255, (((c - 256) * 62) / 255) + 1, 0);    /* 0x01FF to 0x3FFF */
    } else if (c < 1024) {
      return f=new Color (255, (((c - 512) * 63) / 511) + 64, 0);   /* 0x40FF to 0x7FFF */
    } else if (c < 2048) {
      return f=new Color (255, (((c - 1024) * 63) / 1023) + 128, 0);   /* 0x80FF to 0xBFFF */
    } else if (c < 4096) {
      return f=new Color (255, (((c - 2048) * 63) / 2047) + 192, 0);   /* 0xC0FF to 0xFFFF */
    } 
     return f=new Color (255, 255, 0);
     }
    	
    	 
            public static double[] quad(double a,double b){
            	
            double z=Math.pow(a,2) -Math.pow(b,2);
            double z1=2*a*b;
            
           	double z2[]={z,z1};
           	return z2;
            }
       	
       		public  int funz(double a,double b){
       		double re=a,co=b;
       			a=0;
       			b=0;
       	 int c=0;
       	 while(Math.sqrt(Math.pow(a,2)+Math.pow(b,2))<2 && c<ite){
       	 
       		
       		double v[]=quad(a,b);	
    		double z1=(v[0]+re);
       		double z2=(v[1]+co);
       	
       		
       		a=z1;
       		b=z2;
       		c++;
       	   }
       		return c;
      	}
      	Scanner in = new Scanner(System.in);
      	
    	public  final int ite=Integer.parseInt(in.next());
        public static final int WIDTH = 1200;
        public static final int HEIGHT= 1200;
        int w=WIDTH/2;
        
        int h=HEIGHT/2;
        
        public void paint(Graphics g) {
            super.paint(g);
            
    Color bo;
    
    
    
    
          for(int i=-h;i<h;i++){
    	for(int y=-w;y<w;y++){
    	double a=(double)i/(h/2);
    	double b=(double)y/(w/2);
    		int c=funz(a,b);
    		if(c==ite){
    		
    			g.drawLine(i+h,y+w,i+h,y+w);
    	        g.setColor(Color.black);
    	    }
            else{
            		g.setColor(colore(c));
            		g.drawLine(i+h,y+w,i+h,y+w);
    	           
            }
    
    
           }
          }
    
    
        
        }
        
        
        
         
     
        public static void main(String[] args) {
            System.out.println("Inserire numero di iterzioni");
            
            JPanel jp=new JPanel();
            JScrollPane pane=new JScrollPane(jp,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);    
            JFrame frame = new JFrame();
            
            frame.add(pane);
           
           
            frame.add(new PixelCanvas() );
           
            
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            frame.setSize(WIDTH, HEIGHT);
       
            
            frame.setVisible(true);
            
            //frame.setContentPane(pane);
           
           
        }
    }
    Ultima modifica di MItaly; 25-05-2016 a 09:08

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.