ArrayList<PImage> ImageArrayList_ball = new ArrayList<PImage>();
ArrayList<VertexNode> nodeArrayList = new ArrayList<VertexNode>();
pGraphics = createGraphics(200, 100);
pGraphics.background(#FAEE05);
pGraphics.textAlign(CENTER);
pGraphics.ellipse(pGraphics.height / 5.0, pGraphics.height / 2.0, pGraphics.height / 5.0, pGraphics.height / 5.0);
pGraphics.textSize(pGraphics.height / 7.0);
pGraphics.text("1", pGraphics.height / 5.0, pGraphics.height / 2.0 + (pGraphics.height / 5.0 / 4.0));
ImageArrayList_ball.add(pGraphics.get());
pGraphics.background(#001BFF);
pGraphics.ellipse(pGraphics.height / 5.0, pGraphics.height / 2.0, pGraphics.height / 5.0, pGraphics.height / 5.0);
pGraphics.text("2", pGraphics.height / 5.0, pGraphics.height / 2.0 + (pGraphics.height / 5.0 / 4.0));
ImageArrayList_ball.add(pGraphics.get());
pGraphics.background(#CF00FF);
pGraphics.ellipse(pGraphics.height / 5.0, pGraphics.height / 2.0, pGraphics.height / 5.0, pGraphics.height / 5.0);
pGraphics.text("3", pGraphics.height / 5.0, pGraphics.height / 2.0 + (pGraphics.height / 5.0 / 4.0));
ImageArrayList_ball.add(pGraphics.get());
pGraphics.ellipse(pGraphics.height / 5.0, pGraphics.height / 2.0, pGraphics.height / 5.0, pGraphics.height / 5.0);
pGraphics.text("8", pGraphics.height / 5.0, pGraphics.height / 2.0 + (pGraphics.height / 5.0 / 4.0));
ax += (pmouseX - mouseX) /float(width) * 2.0 * PI;
ay += (pmouseY - mouseY) /float(height) * 2.0 * PI;
mysphere(50, ImageArrayList_ball.get(0));
mysphere(50, ImageArrayList_ball.get(1));
mysphere(50, ImageArrayList_ball.get(2));
void mysphere(float mag, PImage tex) {
if (nodeArrayList.size() < 1)
beginShape(TRIANGLE_STRIP);
for (int i = 0; i < nodeArrayList.size() - 1; i++) {
vertex(nodeArrayList.get(i).x, nodeArrayList.get(i).y, nodeArrayList.get(i).z, nodeArrayList.get(i).u, nodeArrayList.get(i).v);
void initSphere(float mag, PImage tex) {
nodeArrayList = new ArrayList<VertexNode>();
float x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4, offset, inverseoff;
for (int i = 0; i < (vd); i++) {
for (int j = 0; j < hd ; j++) {
offset = cos(j%2/(vd /2.0)*PI)* (mag * sin(j / hd * PI))/2.0;
x1 = cos((i+(j%2)/2.0) / (vd / 2.0) * PI ) * (mag * sin(j / hd * PI));
x2 = cos((i+((j+1)%2)/2.0) /(vd / 2.0) * PI * 1.0) * (mag * sin((j + 1) / hd * PI));
x3 = cos(((i-1+((j+1)%2)/2.0) ) / (vd / 2.0) * PI ) * (mag * sin((j + 1) / hd * PI));
x4 = cos(((i-1+(j%2)/2.0)) / (vd / 2.0) * PI ) * (mag * sin(j / hd * PI));
y1 = cos(j / hd * PI) * mag;
y2 = cos((j + 1) / hd * PI) * mag;
y3 = cos((j + 1) / hd * PI) * mag;
y4 = cos(j / hd * PI) * mag;
z1 = sin((i+(j%2)/2.0) / (vd / 2.0) * PI ) * (mag * sin(j / hd * PI));
z2 = sin((i+((j+1)%2)/2.0) / (vd / 2.0) * PI ) * (mag * sin((j + 1) / hd * PI));
z3 = sin(((i-1+((j+1)%2)/2.0)) / (vd / 2.0) * PI ) * (mag * sin((j + 1) / hd * PI));
z4 = sin(((i-1+(j%2)/2.0)) / (vd / 2.0) * PI ) * (mag * sin(j / hd * PI));
nodeArrayList.add(new VertexNode(x1, y1, z1, ((i+(j%2)/2.0) / (vd / 2.0) * tex.height), (j / (hd * 2.0) * tex.width)));
nodeArrayList.add(new VertexNode(x4, y4, z4, (((i-1+(j%2)/2.0)) / (vd / 2.0) * tex.height), (j / (hd * 2.0) * tex.width)));
nodeArrayList.add(new VertexNode(x2, y2, z2, ((i+((j+1)%2)/2.0) / (vd / 2.0) * tex.height), ((j + 1) / (hd * 2.0) * tex.width)));
nodeArrayList.add(new VertexNode(x2, y2, z2, ((i+((j+1)%2)/2.0) / (vd / 2.0) * tex.height), ((j + 1) / (hd * 2.0) * tex.width)));
nodeArrayList.add(new VertexNode(x4, y4, z4, (((i-1+(j%2)/2.0)) / (vd / 2.0) * tex.height), (j / (hd * 2.0) * tex.width)));
nodeArrayList.add(new VertexNode(x3, y3, z3, (((i-1+((j+1)%2)/2.0)) / (vd / 2.0) * tex.height), ((j + 1) / (hd * 2.0) * tex.width)));
initSphereTessellater(mag);
void initSphereTessellater(float mag)
VertexNode p1, p2, p3, np12, np23, np31;
ArrayList<VertexNode> tempnodeArrayList = new ArrayList<VertexNode>();
for (int i = 0 ;i<nodeArrayList.size()-1;i+=3)
p1 = nodeArrayList.get(i);
p2 = nodeArrayList.get(i+1);
p3 = nodeArrayList.get(i+2);
np12 = new VertexNode((p1.x+p2.x)/2.0, (p1.y+p2.y)/2.0, (p1.z+p2.z)/2.0, (p1.u+p2.u)/2.0, (p1.v+p2.v)/2.0);
np23 = new VertexNode((p2.x+p3.x)/2.0, (p3.y+p2.y)/2.0, (p3.z+p2.z)/2.0, (p3.u+p2.u)/2.0, (p3.v+p2.v)/2.0);
np31 = new VertexNode((p1.x+p3.x)/2.0, (p1.y+p3.y)/2.0, (p1.z+p3.z)/2.0, (p1.u+p3.u)/2.0, (p1.v+p3.v)/2.0);
tempnodeArrayList.add(p1);
tempnodeArrayList.add(np12);
tempnodeArrayList.add(np31);
tempnodeArrayList.add(p2);
tempnodeArrayList.add(np12);
tempnodeArrayList.add(np23);
tempnodeArrayList.add(p3);
tempnodeArrayList.add(np23);
tempnodeArrayList.add(np31);
tempnodeArrayList.add(np23);
tempnodeArrayList.add(np31);
tempnodeArrayList.add(np12);
nodeArrayList.addAll(tempnodeArrayList.toArray());
VertexNode(float x, float y, float z, float u, float v) {
a = abs(sqrt(sq(x)+sq(y)+sq(z)));