Sierpinski triangle

Here is one piece of code.

It is about Sierpinski triangle. It is written in  Java and runs in Emptycanvas framework:

__SERID_0__frame1000001

package triangles;

import java.util.ArrayList;
import java.util.Iterator;

import be.ibiiztera.md.pmatrix.pushmatrix.Point3D;
import be.ibiiztera.md.pmatrix.pushmatrix.Position;
import be.ibiiztera.md.pmatrix.pushmatrix.Representable;
import be.ibiiztera.md.pmatrix.pushmatrix.TColor;
import be.ibiiztera.md.pmatrix.pushmatrix.TRI;
import be.ibiiztera.pmatrix.extras.RepresentableConteneur;

public class SiPiKi3D extends RepresentableConteneur
{
/**
*
*/
private static final long serialVersionUID = 1L;

public SiPiKi3D()
{
super();
}
public void add(TRI t0, int nRecursions) {

ArrayList<TRI> [] t = new ArrayList[2];

t[0] = new ArrayList<TRI>();

t[0].add(t0);

for(int i=0; i<nRecursions; i++)
{
t[1] = new ArrayList<TRI>();

for(int j=0; j<t[0].size(); j++)
{
TRI tt = t[0].get(j);
for(int k=0; k<3; k++)
{
Point3D p0 = tt.getSommet()[k];
Point3D p1 = tt.getSommet()[(3+k-1)%3].plus(tt.getSommet()[k]).mult(0.5);
Point3D p2 = tt.getSommet()[(3+k+1)%3].plus(tt.getSommet()[k]).mult(0.5);
t[1].add(new TRI(p0, p1, p2, tt.getCouleur()));
}
}

t[0] = t[1];
}

Iterator<TRI> it = t[0].iterator();
while(it.hasNext())
{
TRI tt = (TRI) it.next();
add(tt);
}
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

}

@Override
public String id() {
// TODO Auto-generated method stub
return null;
}

@Override
public void setId(String id) {
// TODO Auto-generated method stub

}

@Override
public void texture(TColor tc) {
// TODO Auto-generated method stub

}

@Override
public boolean supporteTexture() {
// TODO Auto-generated method stub
return false;
}

@Override
public TColor texture() {
// TODO Auto-generated method stub
return null;
}

@Override
public void position(Position p) {
// TODO Auto-generated method stub

}

@Override
public Position position() {
// TODO Auto-generated method stub
return null;
}

}

 

 

 


Comments

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *