Myview.java//就是给坐标在屏幕上画圆的代码,不知道哪里错了555555
public class MyView extends View {
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
}
private int a;
public MyView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
zuobiao t = new zuobiao();
t.getnumber(10, 0.5);
t.amath();
t.showmath();
t.setax();
for (int i = 0; i < t.a; i++) {
for (int j = 0; j < t.a; j++) {
canvas.drawCircle(Float.valueOf(t.x1.get(i).toString()), Float.valueOf(t.y1.get(j).toString()), 50, paint);
paint.setStyle(Style.STROKE);
}
}
}
}
zuobiao.java
public class zuobiao {
private double length,round;
public double result;
public static double agle=(Math.asin(Math.sqrt(3)/3))-Math.PI/6;
double a;
public ArrayList x1=new ArrayList();
public ArrayList x2=new ArrayList();
public ArrayList y1=new ArrayList();
public ArrayList y2=new ArrayList();
public double c;
public void getnumber(double i,double j)
{this.length=i;
this.round=j;
}
public void amath()
{c=(length-2*round)/(4*round*Math.cos(agle));
}
public double showmath()
{
this.a=Math.floor(c);
System.out.println(a);
this.result=((length/4*round)*(2*a-1));
return this.result;
}
public void setax()
{
double[] x1 = new double [(int) this.a];
double[] y1 = new double[(int) a];
double[] x2 = new double[(int) a];
double[] y2 = new double[(int) a];
double magle=Math.PI/3+agle;
double xieb=2*round/Math.sin(magle);
x1[0]=0;
x2[0]=2*round*Math.cos(magle)-(xieb-2*round)*Math.cos(magle);
y1[0]=0;
y2[0]=2*round-(xieb-2*round)*Math.sin(magle);
for(int i=1;(i<a);i++)
{
x1[i] = x1[i-1]+(4*round*Math.cos(agle));
y1[i] = y1[i-1]+2*round;
x2[i] = x2[i-1]+(4*round*Math.cos(agle));
y2[i] = y2[i-1]+2*round;
}
for(int j=1;(j<a);j++)
{
this.x1.add(x1[j]);
this.x2.add(x1[j]);
this.y1.add(x1[j]);
this.y2.add(x1[j]);
}
}
}