Java Learning: A simple Saturn pattern using the Graphics2D class

Source: Internet
Author: User

Well-painted pattern: saturn.png

Drawing code: Saturn_20150215.java (Java version: 1.8.0_25)

Import java.awt.image.bufferedimage;import java.awt.basicstroke;import java.awt.color;import  java.awt.Font;import java.awt.Graphics2D;import java.awt.RenderingHints;import  Java.io.file;import java.io.ioexception;import javax.imageio.imageio;public class saturn_ 20150215 {    public static void main (String[] args)      {        int width = 900;         int height = 500;         string savepath =  "D:\\saturn.png";                 bufferedimage bi = new bufferedimage (width,  HEIGHT,&NBSP;BUFFEREDIMAGE.TYPE_INT_ARGB);         graphics2d g2d  = bi.creategraphics ();                 G2d.setrenderinghint (                 RenderingHints.KEY_ANTIALIASING,            &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;RENDERINGHINTS.VALUE_ANTIALIAS_ON);         //painting Background         g2d.setpaint (Color.Black);         g2d.fillrect (0, 0, width, height);                 //Picture Title          g2d.setpaint (Color.White);         g2d.setfont (new  Font ("monospaced",  font.bold, 36));         g2d.drawstring (" saturn by tsybius 2015/02/25 ",  50, 50);                 g2d.rotate ( -1 * math.pi / 10);         The upper ring of the         //Halo         for ( int i = 0; i < 10; i++)         {             g2d.setstroke (New BasicStroke (5 &NBSP;-&NBSP;I&NBSP;/&NBSP;2));             G2d.setpaint (New color (255, 97 + i * 5, 0));             g2d.drawarc (80 + i * 9, 250 + i  * 2, 530 - i * 18, 200 - i * 4, 0, 180) ;              g2d.drawarc (80 - i * 9, 250 -  i * 2, 530 + i * 18, 200 + i * 4, 0,  180);        }              //Planet         g2d.setpaint (New Color ( 205, 113, 0));         g2d.filloval (190, 210, 300,  300)         //halo of the lower half of the ring          for (int i = 0; i < 10; i++)          {            g2d.setstroke (new  Basicstroke (5 - i / 2));             g2d.setpaint (NEW&NBsp Color (255, 97 + i * 5, 0));             g2d.drawarc (80 + i * 9, 250 + i * 2,  530 - i * 18, 200 - i * 4, 180, 180);             g2d.drawarc (80 - i * 9,  250 - i * 2, 530 + i * 18, 200 + i * 4,  180, 180);        }         g2d.rotate (math.pi / 10);         //draw each satellite          g2d.setstroke (New basicstroke (5));         g2d.setpaint (Color.White);               &nbsP; //g2d.drawline (0, height / 2, width, height / 2);         //g2d.drawline (width / 2, 0, width / 2,  Height);                 G2d.setfont (New font ("monospaced",  font.bold, 16));                 g2d.filloval (700, 270, 10, 10);         g2d.filloval (720, 260, 10, 10);         g2d.drawstring ("Janus & epimetheus",  700, 255);                 g2d.filloval (600, &NBSP;370,&NBSP;10,&NBSP;10);         g2d.drawstring ("Mimas",  600, &NBSP;360);     &nBsp;           g2d.filloval (300,&NBSP;450,&NBSP;10, &NBSP;10);         g2d.drawstring ("Enceladus",  300, 440);         g2d.filloval (100, 170, 10, 10);         g2d.drawstring ("Tethy",  100, 160);         g2d.filloval (80, 155, 10, 10);         g2d.drawstring ("Dione",  80, 145);         g2d.filloval ( 30,&NBSP;460,&NBSP;10,&NBSP;10);         g2d.drawstring ("Rhea",  30 ,  450);         g2d.filloval (830,&NBSP;470,&NBSP;10,&NBSP;10);         g2d.drawstring ("Titan",  830, 460);         &Nbsp;       g2d.filloval (880, 10, 10, 10);         g2d.drawstring ("Hyperon",  820, 35);         g2d.dispose ();                 //Save Pictures         try          {            imageio.write (bi,  "PNG",  new file (Savepath));        }          catch  (ioexception e)           {            e.printstacktrace () ;         }    }}

END

Java Learning: A simple Saturn pattern using the Graphics2D class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.