package polygon;
public class pro {
int th;
double[] cirx=new double[36];
double[] ciry=new double[36];
int[] polx=new int[36];
int[] poly=new int[36];
int[][] group=new int[500][500];
int cx,cy,len;
int mx,nx;
int w,h;
public static void main(String[] args) {
pro test=new pro();
}
pro(){
w=500;
h=500;
for(mx=100;mx<300;mx++){
for(nx=100;nx<300;nx++){
group[mx][nx]=100;
}
}
circle();
cx=200;
cy=200;
polygon();
graph sub2=new graph();
sub2.polx=polx;
sub2.poly=poly;
sub2.makedata();
}
void polygon(){
int x1,y1;
int len,z,ch;
for(th=0;th<36;th++){
ch=0;
polx[th]=cx;
poly[th]=cy;
for(len=1;len<500;len++){
x1=cx+(int)(len*cirx[th]);
y1=cy+(int)(len*ciry[th]);
if(x1>w-1)x1=w-1;
if(x1<0)x1=0;
if(y1>h-1)y1=h-1;
if(y1<0)y1=w-1;
z=0;
if(group[y1][x1]>50)z=z+1;
if(ch<50)z=z+1;
if(z<2)ch=100;
if(z==2)polx[th]=x1;
if(z==2)poly[th]=y1;
}
}
}
void circle(){
double pi;
double c;
int th1;
pi=3.1415;
for(th=0;th<19;th++){
c=Math.sin(th*pi/18);
ciry[th]=c;
c=Math.cos(th*pi/18);
cirx[th]=c;
}
for(th=19;th<36;th++){
th1=th-18;
c=Math.sin(th1*pi/18);
ciry[th]=-c;
c=Math.cos(th1*pi/18);
cirx[th]=-c;
}
}
}
package polygon;
import java.awt.*;
import java.awt.Color;
import java.awt.image.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
class graph{
int h=500;
int w=500;
int p1;
int s,sx;
String a1,a2;
int[] polx=new int[36];
int[] poly=new int[36];
int mx,nx;
int w1,h1;
int boadernumber;
void makedata(){
w1=w;
h1=h;
BufferedImage off = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_BGR);
Graphics offsc = off.getGraphics();
int s1;
offsc.setColor(Color.white);
offsc.fillRect(0,0,500,500);
for(s=0;s<36;s++){
offsc.setColor(Color.red);
s1=s+1;
if(s1==36)s1=0;
offsc.drawLine(polx[s],poly[s],polx[s1],poly[s1]);
}
offsc.dispose();
try {
ImageIO.write(off, "jpeg", new File("resize.jpg"));
} catch (IOException exception) { exception.printStackTrace(); }
}
}
最終更新:2013年11月10日 06:02