楊小哥的話

「各位讀者，各位先進大家好，我是Arturo楊，不是阿齪楊，還

import java.awt.*; import java.applet.*; public class HexOct extends Applet { int NewH (double a, double b, int h) { a = Math.PI / 180.0 * a; b = Math.PI / 180.0 * b; return((int) (Math.round(Math.sin(a)*h/Math.sin(b)))+1); } void SetHexagon (Polygon hexa, int x, int y, int h) { double a; for (int i=0; i < 7; i++) { a = Math.PI / 3.0 * i; hexa.addPoint((int)(Math.round(x + Math.sin(a) * h)), (int)(Math.round(y + Math.cos(a) * h))); } } void DrawHexagon (Graphics g, int x, int y, int h) { Polygon hexagon = new Polygon(); SetHexagon(hexagon,x,y,h); g.drawPolygon(hexagon); } void DrawOctangle (Graphics g, int x, int y, int h) { double a; int x0,x1, y0,y1; x0 = x + h; y0 = y ; for (int i=1; i < 10; i++) { a = Math.PI / 4.0 * i; x1 = (int)( Math.round(x + Math.sin(a) * h)); y1 = (int)( Math.round(y + Math.cos(a) * h)); g.drawLine(x0,y0,x1,y1); x0= x1; y0 = y1; } } public void paint(Graphics g) { int h = 10; for (int i=0; i < 10; i++) { DrawHexagon(g,180,180,h); h = NewH(97.5,67.5, h); DrawOctangle (g, 180, 180, h); h = NewH(90.0,60.0, h); } } }

import java.awt.*; import java.applet.*; public class HexOct extends Applet { int NewH (double a, double b, int h) { a = Math.PI / 180.0 * a; b = Math.PI / 180.0 * b; return((int)(Math.floor(Math.sin(a) * h / Math.sin(b)))); } void SetHexagon (Polygon hexa, int x, int y, int h) { double a; for (int i=0; i < 7; i++) { a = Math.PI / 3.0 * i; hexa.addPoint((int)(Math.round(x + Math.sin(a) * h)), (int)(Math.round(y + Math.cos(a) * h))); } } void DrawOctangle (Graphics g, int x, int y, int h) { double a; int x0,x1, y0,y1; x0 = x + h; y0 = y ; for (int i=1; i < 10; i++) { a = Math.PI / 4.0 * i; x1 = (int)( Math.round(x + Math.sin(a) * h)); y1 = (int)( Math.round(y + Math.cos(a) * h)); g.drawLine(x0,y0,x1,y1); x0= x1; y0 = y1; } } public void paint(Graphics g) { Polygon hexagon = new Polygon(); int h = 10; for (int i=0; i < 10; i++) { SetHexagon(hexagon,180,180,h); g.drawPolygon(hexagon); h = NewH(97.5,67.5, h); DrawOctangle (g, 180, 180, h); h = NewH(90.0,60.0, h); } } }

《網路劇坊─小台哥笑談網路實作與管理》 台北市維科出版社出版

[ 回首頁 Back to Home | 上一頁 Previous Page | 下一頁 Next Page | 任一頁 Any Page ]
Symon Chang 小台哥 Symon & Associates, CA. U.S.A symonchang@earthlink.net