首页
论坛
图书
开发资料
在线文档
网址
下载
联系我们
 新闻│Java│JavaScript│Eclipse│Eclipse 英文│J2EE│J2ME│J2SE│JSP│Netbeans│Hibernate│JBuilder│Spring│Struts
站内搜索: 请输入搜索关键词

当前页面: 开发资料首页 → Java 专题 → 用JAVA画个星条旗

用JAVA画个星条旗

摘要: 用JAVA画个星条旗

</td> </tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="259" height="86" align="center" valign="top"> </td> <td width="425" valign="top">
用JAVA画个星条旗


</td></tr> </table>
public class DrawFlag

{

    public static void main(java.lang.String[] args) throws java.io.IOException

    {

        DrawFlag.drawFlag();

    }

    public static void drawFlag() throws java.io.IOException

    {

        java.awt.image.BufferedImage bufferedImage = 
new java.awt.image.BufferedImage(420, 221, java.awt.image.BufferedImage.TYPE_INT_RGB); java.awt.Graphics gp = bufferedImage.getGraphics(); java.awt.Color color = new java.awt.Color(0); for (int i = 0; i < 13; i++) { if (i % 2 == 0) { color = new java.awt.Color(204, 0, 0); } else { color = new java.awt.Color(255, 255, 255); } gp.setColor(color); gp.fillRect(0, 17 * i, 420, 17); } color = new java.awt.Color(0, 0, 102); gp.setColor(color); gp.fillRect(0, 0, 168, 119); color = new java.awt.Color(255, 255, 255); gp.setColor(color); int left = 0; int top = 0; for (int i = 0; i < 9; i++) { top = (i + 1) * 12; if (i % 2 == 0) { left = -15; for (int j = 0; j < 6; j++) { left = left + 28; DrawFlag.DrawPentacle(gp, (double) left, (double) top, (double) 8, 0); } } else { left = -2; for (int j = 0; j < 5; j++) { left = left + 28; DrawFlag.DrawPentacle(gp, (double) left, (double) top, (double) 8, 0); } } } color = new java.awt.Color(0, 0, 0); gp.setColor(color); java.awt.Font font = new java.awt.Font("宋体", java.awt.Font.CENTER_BASELINE, 12); gp.setFont(font); gp.drawString("这些星好像有点怪", 300, 200); javax.imageio.ImageIO.write(bufferedImage, "jpg", new java.io.File("flag.jpg")); } public static void DrawPentacle(java.awt.Graphics gp, double x, double y, double r, int a) { int A; double R, X, Y; double[] _X = new double[11]; double[] _Y = new double[11]; int[] _x = new int[3]; int[] _y = new int[3]; a = a + 90; R =Math.sin(Math.toRadians((double) 18)) * r / Math.sin(Math.toRadians((double) 126)); for (int i = 0; i < 5; i++) { A = a + 72 * i; X = R * java.lang.Math.cos(java.lang.Math.toRadians((double) A)) + x; Y = R * java.lang.Math.sin(java.lang.Math.toRadians((double) A)) + y; _X[i * 2] = X; _Y[i * 2] = Y; A = a + 72 * i + 36; X = r * java.lang.Math.cos(java.lang.Math.toRadians((double) A)) + x; Y = r * java.lang.Math.sin(java.lang.Math.toRadians((double) A)) + y; _X[i * 2 + 1] = X; _Y[i * 2 + 1] = Y; } _X[10] = x; _Y[10] = y; for (int i = 0; i < 5; i++) { _x[0] = DrawFlag.round(_X[i * 2], 0); _x[1] = DrawFlag.round(_X[i * 2 + 1], 0); _x[2] = DrawFlag.round(_X[10], 0); _y[0] = DrawFlag.round(_Y[i * 2], 0); _y[1] = DrawFlag.round(_Y[i * 2 + 1], 0); _y[2] = DrawFlag.round(_Y [10], 0); gp.fillPolygon(_x, _y, 3); _x[0] = DrawFlag.round(_X[i * 2 + 1], 0); _x[1] = DrawFlag.round(_X[(i == 4) ? (0) : (i * 2 + 2)], 0); _x[2] = DrawFlag.round(_X[10], 0); _y[0] = DrawFlag.round(_Y[i * 2 + 1], 0); _y[1] = DrawFlag.round(_Y[(i == 4) ? (0) : (i * 2 + 2)], 0); _y[2] = DrawFlag.round(_Y[10], 0); gp.fillPolygon(_x, _y, 3); } } public static int round(double d, int scale) { if (scale < 0) { scale = 0; } java.math.BigDecimal b = new java.math.BigDecimal(java.lang.Double.toString(d)); java.math.BigDecimal one = new java.math.BigDecimal("1"); return b.divide(one, scale, java.math.BigDecimal.ROUND_HALF_UP).intValue(); } }


</td> </tr> <tr>


↑返回目录
前一篇: DAO 设计模式经典实例
后一篇: 模拟约索夫问题

首页 | 全站 Sitemap | 联系我们 | 设为首页 | 收藏本站
版权所有 Copyright © 2006-2007, Java 编程资料牛鼻站, All rights reserved