Srecno in uspesno leto 0x7D6 tudi tebi Dane
in ostalim

PS:nice work(kartica) ;)

LP Blaž

On 12/24/05, Matjaž Horvat <[EMAIL PROTECTED]> wrote:
>
> 5r3cn0 tudi tebi in ostalim 1337 h4x0rjem!
>
> LP,
> Matjaž
>
> On Dec 24, 2005, at 1:08 PM, Dane Šoba wrote:
>
> > Naj bo leto 2006 uspesno in veselo.
> > Zelim vam veliko programerskih dosezkov.
> >
> > lp
> > Dane
> >
> > [Priponka: Kartica.java]
> >
> > /****************************************************
> >
> > KARTICA
> >
> > Uporaba kode je prosta za izobrazevalne namene.
> >
> > Dane Šoba,
> > [EMAIL PROTECTED]
> >
> > December 2005
> >
> > Powered by Scintilla Text Editor
> >
> > *****************************************************/
> >
> > import java.awt.*;
> > import java.awt.event.*;
> > import java.awt.image.*;
> > import javax.swing.*;
> >
> > public class Kartica extends JPanel implements ActionListener
> > {
> >     /**************************************
> >     *
> >     *  Konstantne je zabavno spreminjat ;)
> >     *
> >     ***************************************/
> >
> >     public static final int FPS=20; //Stevilo izrisanih slicic na
> > sekundo (def: 20)
> >
> >     public static final int SIRINA=500;   //Sirina platna (def: 500)
> >     public static final int VISINA=580;   //Visina platna (def: 580)
> >
> >     public static final int N_SNEZINK=15;  //Stevilo snezink (def: 15)
> >     public static final int SNEZINKA_VELIKOST_MIN=25;  //Min.
> > velikost snezinke (def: 15)
> >     public static final int SNEZINKA_VELIKOST_MAX=40;  //Max.
> > velikost snezinke (def: 40)
> >     public static final int SNEZINKA_VEJ_MIN=3;  //Min. stevilo vej
> > sneznike (def: 3)
> >     public static final int SNEZINKA_VEJ_MAX=10; //Max. stevilo vej
> > sneznike (def: 10)
> >     public static final int SNEZINKA_NIVO_MIN=3; //Min. nivo
> > rekurzije (def: 3)
> >     public static final int SNEZINKA_NIVO_MAX=5; //Max. nivo
> > rekurzije (def: 5)
> >
> >     public static final int N_FRAMES_KAMERA=100;  // Po koliko
> > frameih se kamera zacne premikati navzdol (def: 100)
> >     public static final int V_KAMERE=1;           // Hitrost kamere
> > v pikslih (def: 1)
> >
> >     public static final int N_FRAMES_LUCKE=10;   // Stevilo
> > frameov, po katerem lucka spremeni barvo (def: 10)
> >     public static final int N_FRAMES_NAPIS=N_FRAMES_KAMERA+ VISINA/
> > V_KAMERE + 10;  // Stevilo frameov, po katerem se prikaze napis
> >     public static final int N_FRAMES_PODPIS=N_FRAMES_NAPIS+40;  //
> > Stevilo frameov, po katerem se prikaze podpis
> >
> >     public static final int N_LUCK=20;  //Stevilo luck
> >     public static final int R_LUCKE=10; //Radij lucke v pikslih
> >     public static final double N_VIJUG=2.1; //Stevilo vijug, ki jih
> > lucke orisejo
> >     public static final Color[] barveLuci={Color.red, Color.blue,
> > Color.yellow}; // Tabela razlicnih barv luci, lahko jih je poljubno
> > mnogo
> >
> >     public static final int VISINA_DREVESA=VISINA-200;  // Visina
> > drevesa v pikslih
> >     public static final int N_VEJ=VISINA_DREVESA/50;    // Stevilo
> > vej na drevesu
> >     public static final double KOT_VEJE=Math.PI/2.5;   // Kot veje
> > (v rad)
> >     public static final double RANDOM_KOT=Math.PI/30;  // Nakljucen
> > kot veje (dodano za bolj naraven izgled)
> >     public static final double RANDOM_DOLZINA=0.1;     // Nakljucna
> > dolzina veje (dodano za bolj naraven izgled)
> >
> >     public static final Color BARVA_DREVESA1=Color.green.darker
> > (); // Prva barva drevesa
> >     public static final Color
> > BARVA_DREVESA2=Color.white;          // Druga barva drevesa
> >
> >     public static final Color
> > BARVA_NEBA1=Color.black;             // Prva barva neba
> >     public static final Color BARVA_NEBA2=Color.blue.darker
> > ();    // Druga barva drevesa
> >
> >     public static final Color
> > BARVA_NAPISA1=Color.white;          // Barva napisa
> >     public static final Color
> > BARVA_NAPISA2=Color.gray;           // Barva sence napisa
> >
> >     public static final String BESEDILO = "Srecno 0x7D6!";
> >
> >
> >     Snezinka[] snezinke;
> >     Lucka[] lucke;
> >     BufferedImage ozadje, napis, podpis;
> >     BufferedImage[] slikeLuci;
> >
> >     int nFrames;
> >     int ozadjey;
> >     int nBarveLuci;
> >
> >     Kartica()
> >     {
> >         super(new BorderLayout());
> >         add(Box.createRigidArea(new Dimension(SIRINA,VISINA)));
> >
> >         snezinke=new Snezinka[N_SNEZINK];
> >
> >         for (int i=0;i<snezinke.length;i++)
> >             snezinke[i]=narediSnezinko();
> >
> >
> >         // *********  OZADJE  **********
> >
> >         ozadje=new BufferedImage(SIRINA,VISINA*2,
> > BufferedImage.TYPE_INT_RGB);
> >         Graphics g=ozadje.getGraphics();
> >
> >         narisiGradient(0,0,SIRINA,VISINA*2,BARVA_NEBA1,
> > BARVA_NEBA2, g);
> >
> >         lucke=new Lucka[N_LUCK];
> >         narediJelko(SIRINA/2,2*VISINA-80, VISINA_DREVESA, lucke ,g);
> >
> >         napis=narediNapis(BESEDILO, 40, BARVA_NAPISA1,
> > BARVA_NAPISA2, 3);
> >         podpis=narediNapis("Dane", 20, BARVA_NAPISA1,
> > BARVA_NAPISA2, 1);
> >         slikeLuci=narediLuci(barveLuci);
> >
> >         nFrames=0;
> >         ozadjey=0;
> >         nBarveLuci=0;
> >
> >         Timer t=new Timer(1000/FPS, this);
> >         t.start();
> >     }
> >
> >
> >     public void actionPerformed(ActionEvent e)
> >     {
> >         final double PI2=Math.PI*2;
> >
> >         nFrames++;
> >
> >         if (nFrames % N_FRAMES_LUCKE == 0)
> >         {
> >             nBarveLuci++;
> >             if (nBarveLuci>=barveLuci.length)
> >                 nBarveLuci=0;
> >         }
> >
> >         if (ozadjey<=-VISINA)
> >         {
> >             ozadjey=-VISINA;
> >         }
> >         else
> >         {
> >             if (nFrames>N_FRAMES_KAMERA)
> >                 ozadjey-=V_KAMERE;
> >         }
> >
> >         for (int i=0;i<snezinke.length;i++)
> >         {
> >             snezinke[i].y+=snezinke[i].vy;
> >             snezinke[i].t+=snezinke[i].dt;
> >
> >             if (snezinke[i].t>PI2)
> >                 snezinke[i].t-=PI2;
> >
> >             if (snezinke[i].y-snezinke[i].velikost>VISINA)
> >                 snezinke[i]=narediSnezinko();
> >         }
> >
> >         repaint();
> >     }
> >
> >
> >     public int nakljucno(int min, int max)
> >     {
> >         return (int)(Math.random()*(max-min+1)+min);
> >     }
> >
> >     public Snezinka narediSnezinko()
> >     {
> >         return new Snezinka(nakljucno
> > (SNEZINKA_VELIKOST_MIN,SNEZINKA_VELIKOST_MAX), nakljucno(0,SIRINA),
> > nakljucno(-VISINA-SNEZINKA_VELIKOST_MAX*2,-
> > SNEZINKA_VELIKOST_MAX*2), Math.random()*6+1, Math.random()*90+5,
> > Math.random()*Math.PI/50);
> >     }
> >
> >     class Snezinka
> >     {
> >         BufferedImage slika;
> >         int velikost;
> >         double x,y,vy;
> >         double amp, perioda, t, dt;
> >
> >         Snezinka(int velikost, double x, double y, double vy,
> > double amp, double dt)
> >         {
> >             this.velikost=velikost;
> >             this.x=x;
> >             this.y=y;
> >             this.vy=vy;
> >             this.amp=amp;
> >             this.t=Math.random()*2*Math.PI;
> >             this.dt=dt;
> >
> >             slika=new BufferedImage(velikost, velikost,
> > BufferedImage.TYPE_INT_ARGB);
> >
> >             narisiSnezinko(velikost/2, velikost/2, Math.random()
> > *2*Math.PI, velikost*0.7, nakljucno
> > (SNEZINKA_VEJ_MIN,SNEZINKA_VEJ_MAX), nakljucno
> > (SNEZINKA_NIVO_MIN,SNEZINKA_NIVO_MAX), slika.getGraphics());
> >         }
> >
> >         public void narisi(Graphics g)
> >         {
> >             int risix=(int) (x-velikost/2+amp*Math.sin(t));
> >             int risiy=(int) (y-velikost/2);
> >
> >             g.drawImage(slika, risix, risiy ,null);
> >         }
> >
> >         public void narisiVejoSnezinke(double x, double y, double
> > kot, double deltaKot, double dolzina, int nivo, Graphics g)
> >         {
> >             if (nivo>0)
> >             {
> >                 if (kot<0)
> >                     kot+=2*Math.PI;
> >
> >                 if (kot>2*Math.PI)
> >                     kot-=2*Math.PI;
> >
> >                 double x2=(x+Math.cos(kot)*dolzina/3);
> >                 double y2=(y+Math.sin(kot)*dolzina/3);
> >
> >                 g.drawLine((int)x, (int)y, (int)x2, (int)y2);
> >
> >                 narisiVejoSnezinke(x2,y2,kot-deltaKot, deltaKot,
> > dolzina/2, nivo-1, g);
> >                 narisiVejoSnezinke(x2,y2,kot+deltaKot, deltaKot,
> > dolzina/2, nivo-1, g);
> >             }
> >             else
> >             {
> >                 double x2=(x+Math.cos(kot)*dolzina);
> >                 double y2=(y+Math.sin(kot)*dolzina);
> >
> >                 g.drawLine((int)x, (int)y, (int)x2, (int)y2);
> >             }
> >         }
> >
> >         public void narisiSnezinko(double x, double y, double kot,
> > double dolzina, int n, int nivo, Graphics g)
> >         {
> >
> >             double korak=Math.PI*2/n;
> >
> >             g.setColor(Color.white);
> >
> >             for (int i=0;i<n;i++)
> >                 narisiVejoSnezinke(x,y,kot + i*korak,korak/
> > 2,dolzina,nivo,g);
> >         }
> >
> >
> >     }
> >
> >     class Lucka
> >     {
> >         int x, y;
> >
> >         Lucka (int x, int y)
> >         {
> >             this.x=x;
> >             this.y=y;
> >         }
> >     }
> >
> >     public void narisiVejo(double x0, double y0, double kot, double
> > dolzina, double kotIglic, double dolzinaIglic, double
> > razdaljaIglic, Color c1, Color c2, Graphics g)
> >     {
> >         int nIglic=(int) (dolzina/razdaljaIglic);
> >
> >         double x=x0;
> >         double y=y0;
> >
> >         double dx=Math.cos(kot)*razdaljaIglic;
> >         double dy=Math.sin(kot)*razdaljaIglic;
> >
> >         double desnox=Math.cos(kot+kotIglic)*dolzinaIglic;
> >         double desnoy=Math.sin(kot+kotIglic)*dolzinaIglic;
> >
> >         double levox=Math.cos(kot-kotIglic)*dolzinaIglic;
> >         double levoy=Math.sin(kot-kotIglic)*dolzinaIglic;
> >
> >         double rx=c1.getRed();
> >         double gx=c1.getGreen();
> >         double bx=c1.getBlue();
> >
> >         double dr=(c2.getRed()-rx)/nIglic;
> >         double dg=(c2.getGreen()-gx)/nIglic;
> >         double db=(c2.getBlue()-bx)/nIglic;
> >
> >         //g.setColor(new Color ((int)r, (int)g, (int)b));
> >
> >         dolzina=nIglic*razdaljaIglic+dolzinaIglic;
> >
> >         //g.drawLine((int)x,(int)y,(int)(x+Math.cos(kot)*dolzina),
> > (int)(y+Math.sin(kot)*dolzina));
> >
> >         for (int i=0;i<nIglic;i++)
> >         {
> >             g.setColor(new Color((int)rx, (int)gx, (int)bx));
> >             g.drawLine((int)x,(int)y,(int)(x+desnox),(int)(y+desnoy));
> >             g.drawLine((int)x,(int)y,(int)(x+levox),(int)(y+levoy));
> >
> >             g.drawLine((int)x,(int)y,(int)(x+dx),(int)(y+dy));
> >
> >             x+=dx;
> >             y+=dy;
> >
> >             rx+=dr;
> >             gx+=dg;
> >             bx+=db;
> >         }
> >
> >         x-=dx;
> >         y-=dy;
> >
> >         g.drawLine((int)x,(int)y,(int)(x+Math.cos(kot)
> > *dolzinaIglic), (int)(y+Math.sin(kot)*dolzinaIglic));
> >     }
> >
> >     public void narisiDrevo(double x0, double y0, double kot,
> > double dolzina, int nVej, int nivo, Graphics g)
> >     {
> >         narisiVejo(x0, y0, kot, dolzina, Math.PI/5, 10, 8,
> > BARVA_DREVESA1, BARVA_DREVESA2, g);
> >
> >         if (nivo>0)
> >         {
> >             double dx=Math.cos(kot)*dolzina/(nVej+1);
> >             double dy=Math.sin(kot)*dolzina/(nVej+1);
> >
> >             double x=x0+dx;
> >             double y=y0+dy;
> >
> >             double dolzina2=dolzina*0.35;
> >             double ddolzina2=dolzina2/(nVej+1);
> >
> >
> >             for (int i=0;i<nVej;i++)
> >             {
> >                 int nVej2=(int)((double)nVej*0.6*(nVej-i)/nVej);
> >
> >                 narisiDrevo(x,y,kot-KOT_VEJE+Math.random()
> > *RANDOM_KOT-RANDOM_KOT/2,dolzina2*(1+Math.random()*RANDOM_DOLZINA-
> > RANDOM_DOLZINA/2), nVej2, nivo-1, g);
> >                 narisiDrevo(x,y,kot+KOT_VEJE+Math.random()
> > *RANDOM_KOT-RANDOM_KOT/2,dolzina2*(1+Math.random()*RANDOM_DOLZINA-
> > RANDOM_DOLZINA/2), nVej2, nivo-1, g);
> >
> >                 x+=dx;
> >                 y+=dy;
> >                 dolzina2-=ddolzina2;
> >             }
> >         }
> >     }
> >
> >
> >     public void narediJelko(int x, int y, int visinaDrevesa, Lucka
> > [] lucke, Graphics g0)
> >     {
> >         Graphics2D g=(Graphics2D)g0;
> >         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
> > RenderingHints.VALUE_ANTIALIAS_ON);
> >
> >         narisiDarila(x-80,y-20,g);
> >         narisiDrevo(x, y, -Math.PI/2, visinaDrevesa, N_VEJ, 2, g);
> >
> >
> >         double sirina=visinaDrevesa*0.2;
> >         double visina=visinaDrevesa*0.9;
> >
> >
> >         for (int i=0;i<lucke.length;i++)
> >         {
> >             double procent=i/(double)lucke.length;
> >
> >             int xl=(int) (x+(0.8*procent+0.2) * sirina * Math.sin
> > (procent*Math.PI*2*N_VIJUG));
> >             int yl=(int) (y-visinaDrevesa+30+procent * visina);
> >
> >             lucke[i]=new Lucka(xl,yl);
> >         }
> >
> >         Polygon zvezda=narediZvezdo(x,y-visinaDrevesa-10,10,20,5);
> >         narisiZvezdo(zvezda, Color.yellow, g);
> >     }
> >
> >     public void narisiDarilo(int x, int y, int w, int h, int wTrak,
> > Color c1, Color c2, Graphics g)
> >     {
> >         //g.setColor(c1);
> >         //g.fillRect(x,y,w,h);
> >
> >         narisiGradient(x,y,w,h,c1,c1.darker().darker(),g);
> >
> >         g.setColor(c2);
> >
> >         g.fillRect(x,y+(h-wTrak)/2,w,wTrak);
> >         g.fillRect(x+(w-wTrak)/2,y,wTrak,h);
> >     }
> >
> >     public void narisiDarila(int x, int y, Graphics g)
> >     {
> >         narisiDarilo(x,y,60,50,10,Color.blue, Color.white, g);
> >         narisiDarilo(x+100,y+10,80,40,10,Color.magenta,
> > Color.white, g);
> >         narisiDarilo(x+50,y+35,60,50,10,Color.red, Color.yellow, g);
> >     }
> >
> >     public Polygon narediZvezdo(int x0, int y0, int rin, int rout,
> > int n)
> >     {
> >         int x[] = new int[n*2];
> >         int y[] = new int[n*2];
> >         double dth = Math.PI/n;
> >         double th = -Math.PI/2;
> >
> >         int i;
> >         for(i=0;i<n*2;i++)
> >         {
> >             th = th+dth;
> >             x[i] = x0 + (int)(((i%2==0)?rin:rout) * Math.cos(th));
> >             y[i] = y0 + (int)(((i%2==0)?rin:rout) * Math.sin(th));
> >         }
> >
> >         return new Polygon(x,y,n*2);
> >     }
> >
> >     public void narisiZvezdo(Polygon zvezda, Color c, Graphics g)
> >     {
> >         g.setColor(c);
> >         g.fillPolygon(zvezda);
> >     }
> >
> >     public void narisiGradient(int x, int y, int w, int h, Color
> > c1, Color c2, Graphics g)
> >     {
> >         int r1=c1.getRed();
> >         int g1=c1.getGreen();
> >         int b1=c1.getBlue();
> >
> >         int r2=c2.getRed();
> >         int g2=c2.getGreen();
> >         int b2=c2.getBlue();
> >
> >         double rx=r1;
> >         double gx=g1;
> >         double bx=b1;
> >
> >         double rd=(r2-r1)/(double)h;
> >         double gd=(g2-g1)/(double)h;
> >         double bd=(b2-b1)/(double)h;
> >
> >         for (int i=0;i<h;i++)
> >         {
> >             g.setColor(new Color((int)Math.round(rx), (int)
> > Math.round(gx), (int)Math.round(bx)));
> >             g.drawLine(x,y+i,x+w,y+i);
> >
> >             rx+=rd;
> >             gx+=gd;
> >             bx+=bd;
> >         }
> >     }
> >
> >     public BufferedImage[] narediLuci(Color[] barve)
> >     {
> >         BufferedImage[] slikeLuci=new BufferedImage[barve.length];
> >
> >         for (int i=0;i<slikeLuci.length;i++)
> >         {
> >             slikeLuci[i]=new BufferedImage(R_LUCKE*2, R_LUCKE*2,
> > BufferedImage.TYPE_INT_ARGB);
> >
> >             narisiLucko(new Lucka(R_LUCKE, R_LUCKE), barve[i],
> > Color.white, slikeLuci[i].getGraphics());
> >         }
> >
> >         return slikeLuci;
> >> <DEFANGED.1     }
> >
> >
> >     public void narisiLucko(Lucka l, Color c1, Color c2, Graphics g0)
> >     {
> >         Graphics2D g=(Graphics2D)g0;
> >         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
> > RenderingHints.VALUE_ANTIALIAS_ON);
> >
> >         double rx=c1.getRed();
> >         double gx=c1.getGreen();
> >         double bx=c1.getBlue();
> >
> >         int n=(int)(R_LUCKE*0.7);
> >
> >         double rd=(c2.getRed()-rx)/n;
> >         double gd=(c2.getGreen()-gx)/n;
> >         double bd=(c2.getBlue()-bx)/n;
> >
> >         for (int i=0;i<=n;i++)
> >         {
> >             g.setColor(new Color ((int)rx,(int)gx,(int)bx));
> >             g.fillOval(i/4+l.x-R_LUCKE, i/4+l.y-R_LUCKE+ozadjey,
> > 2*R_LUCKE-i, 2*R_LUCKE-i);
> >
> >             rx+=rd;
> >             gx+=gd;
> >             bx+=bd;
> >
> >         }
> >     }
> >
> >     public void narisiLucko(Lucka l, BufferedImage slika, Graphics g)
> >     {
> >         g.drawImage(slika, l.x-R_LUCKE, l.y-R_LUCKE+ozadjey, null);
> >     }
> >
> >     public BufferedImage narediNapis(String s, int size, Color c,
> > Color cs, int sencaOffset)
> >     {
> >
> >         BufferedImage dummy=new BufferedImage
> > (1,1,BufferedImage.TYPE_INT_ARGB);
> >
> >         Graphics gd = dummy.getGraphics();
> >
> >         Font f = new Font ("Monospace", Font.BOLD, size);
> >         gd.setFont(f);
> >
> >         FontMetrics fm=gd.getFontMetrics();
> >
> >         int w=fm.stringWidth(s);
> >         int h=fm.getHeight();
> >         int hbase=fm.getAscent();
> >
> >         BufferedImage slika=new BufferedImage(w+sencaOffset, h
> > +sencaOffset, BufferedImage.TYPE_INT_ARGB);
> >
> >         Graphics2D g=(Graphics2D)(slika.getGraphics());
> >         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
> > RenderingHints.VALUE_ANTIALIAS_ON);
> >
> >         g.setFont(f);
> >
> >         g.setColor(cs);
> >         g.drawString (s,sencaOffset,hbase+sencaOffset);
> >
> >         g.setColor(c);
> >         g.drawString (s,0,hbase);
> >
> >         //g.drawRect(0,0,slika.getWidth()-1, slika.getHeight()-1);
> >
> >         return slika;
> >     }
> >
> >     public void narisiSliko(BufferedImage slika, int x0, int y0,
> > int halign, int valign, Graphics g)
> >     {
> >         int w=slika.getWidth();
> >         int h=slika.getHeight();
> >
> >         int x,y;
> >
> >         if (halign==0)  //LEVO
> >             x=x0;
> >         else if (halign==1)  //SREDINA
> >             x=x0-w/2;
> >         else
> >             x=x0-w;  //DESNO
> >
> >
> >         if (halign==0)  //ZGORAJ
> >             y=y0;
> >         else if (halign==1)  //SREDINA
> >             y=y0-h/2;
> >         else
> >             y=y0-h;  //SPODAJ
> >
> >         g.drawImage(slika, x,y, null);
> >     }
> >
> >     public void paintComponent(Graphics g)
> >     {
> >         g.drawImage(ozadje,0,ozadjey,null);
> >
> >         int temp=nBarveLuci;
> >         for (int i=0;i<lucke.length;i++)
> >         {
> >             narisiLucko(lucke[i], slikeLuci[temp], g);
> >
> >             temp++;
> >             if (temp>=barveLuci.length)
> >                 temp=0;
> >         }
> >
> >         for (int i=0;i<snezinke.length;i++)
> >             snezinke[i].narisi(g);
> >
> >         if (nFrames>N_FRAMES_NAPIS)
> >         {
> >             narisiSliko(napis, SIRINA/2, 50, 1, 0, g);
> >
> >             if (nFrames>N_FRAMES_PODPIS)
> >                 narisiSliko(podpis, SIRINA-10, VISINA-10, 2, 2, g);
> >         }
> >
> >     }
> >
> >     public static void narediGUI()
> >     {
> >         JFrame frame=new JFrame("K4r7ic4");
> >
> >         frame.addWindowListener(new WindowAdapter()
> >         {
> >             public void windowClosing(WindowEvent e)
> >             {
> >                 System.exit(0);
> >             }
> >         });
> >
> >         Container c=frame.getContentPane();
> >         c.add(new Kartica());
> >
> >         frame.setResizable(false);
> >         //frame.setUndecorated(true);
> >         frame.pack();
> >         frame.setLocationRelativeTo(null);
> >         frame.setVisible(true);
> >     }
> >
> >     public static void main(String[] args)
> >     {
> >         narediGUI();
> >         System.out.println("Srecno " + 0x7D6);
> >     }
> > }
>
>
>

Reply via email to