I am trying to create 10.000 hexagon connected each other like bee combs.I want to create all of this as a element that after I can import some thing to inside them.But for connecting hexagons together my algorithms stuck after connecting first 6 elements. Here is my algorithm in java. I made in java for testing . And inaddition I want to make them size smaller from before connected.
angle= 2*Math.PI/6;
for (int i=0 ;i<6;i++){
double v = i*angle-(15);
pentagon pent = new pentagon(6, 60, a);
a.x=a.x+(int)Math.round(105*Math.cos(v));
a.y=a.y+(int)Math.round(105*Math.sin(v));
pentagonList.add(pent);
and this is my pentagon class
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author Meko
*/
public class pentagon extends JPanel {
private int n, r;
private double angle;
public int[] x, y;
Point c;
int posX, posY;
public pentagon(int pieces, int radie, Point center) {
c = center;
n = pieces;
r = radie;
x = new int[n];
y = new int[n];
angle = 2 * Math.PI / n;
posX = c.x + 1024 / 2;
posY = c.y + 1024 / 2;
}
public void drawMe(Graphics g) {
g.drawString("CENTER", posX, posY);
//System.out.print(" xO: "+x0);
for (int i = 0; i < n; i++) {
double v = i * angle - (6 * 2 * Math.PI / 360) + 15;
x[i] = posX + (int) Math.round(r * Math.cos(v));
// System.out.print(" x: "+x[i]);
y[i] = posY + (int) Math.round(r * Math.sin(v));
g.drawString("" + i, x[i], y[i]);
}
g.drawPolygon(x, y, n);
}
}
See Question&Answers more detail:os