VS 2501. CODING FORM . MULTI-AGENT ALGORITHMS
FALL 2011. V DUYGUN INAL

A_logic of child # percentage# of childint childNum=0if (IRandom.percent(80)) then # of child=1
else if (IRandom.percent(60) then # of child = 2
if else then # of child=0

80%

60%

else

B_types of directions(1,1,1)zzaxis

yaxis

xaxis

(0,0,0)cross productdouble dir = IRandom.getInt(0, 7);
dir==0nextPos(axis,len(nextSize)

dir==2cross(IVec.zaxis).len(nextSize)

dir==4cross(IVec.yaxis).len(nextSize)

dir==6cross(IVec.xaxis).len(nextSize)

dir==3cross(IVec.zaxis).len(-nextSize)

dir==5cross(IVec.yaxis).len(-nextSize)

dir==7cross(IVec.xaxis).len(-nextSize)axis

dir==1nextPos(axis,len(-nextSize)# of childint childNum=0;
if (IRandom.percent(80))
childNum=1;
else if (IRandom.percent(60))
childNum = 2;
else
childNum=0;# of childint childNum=0;
if (IRandom.percent(60))
childNum=1;
else if (IRandom.percent(50))
childNum = 2;
else
childNum=0;# of childint childNum=0;
if (IRandom.percent(80))
childNum=1;
else if (IRandom.percent(60))
childNum = 2;
else
childNum=0;

nextSize
double nextSize =IRandom.getDouble(.9, 1.1)*size;

nextSize
double nextSize =IRandom.getDouble(.95, 1)*size;

nextSize
double nextSize =IRandom.getDouble(.95, 1)*size;

nextAxis
IVec nextAxis = axis.dup().rot(IVec.xaxis, PI/20);

nextAxis
IVec nextAxis = axis.dup().rot(IVec.xaxis, PI/10);

nextAxis
IVec nextAxis = axis.dup().rot(IVec.xaxis, PI/20);

nextAxis

9’

IVec nextAxis = axis.dup().rot(IVec.xaxis, PI/20);

C_geometry definition
ISurface[] createTetrahedron(IVec pt, double size, double height)

PARAMETER CHANGES

v4
v2
PI*2/3
v1

v3

v5

v2
v3

v1

TOP VIEWS

v4
v6
ISurface[] createOctahedron(IVec pt, double size, double height)

AXONOMETRICS_B_CIGEO.CODE DEFINITION
import processing.opengl.*;import igeo.*;void setup() {size(600, 600, IG.GL);
IRandom.init(1);IG.duration(100);
int num = 1;
for (int i=0; i < num; i++) {new MyAgent(IRandom.pt(30, 30, 0), 10, 5, 5, new IVec(1, 1,1)).clr(1.25);_Aif (polyhedronSrfs!=null) {for (ISurface srf:polyhedronSrfs) {srf.del();}}//polyhedronSrfs = createTetrahedron(pos, size, size);if (IRandom.percent(20)) {polyhedronSrfs = createTetrahedron(pos, size, size);}}
IG.transparent(); //transparent graphic modeelse {
polyhedronSrfs = createOctahedron(pos, size, size*sqrt(2));}

static class MyAgent extends IAgent {IVec pos;
IVec axis;

for (ISurface srf:polyhedronSrfs) {srf.clr(clr());
srf.rot(pos, axis, PI/6);}}

double size, width1, height1;
ISurface[] polyhedronSrfs;
boolean changed=true;
MyAgent(IVec pt, double w, double h, double sz, IVec axs) {pos = pt;
size =sz;
width1=w;
height1=h;axis = axs;}
void update() {super.update();if (changed) {changed=false;//child number
int childNum=0;
if (IRandom.percent(80)) {childNum=1;}
else if (IRandom.percent(60)) {childNum = 2;}
else {
childNum=0;}
for (int i=0; i<childNum; i++) {vertexDir.rot(IVec.zaxis, PI*2/3);
IVec v3 = pt.cp(vertexDir);
IVec v4 = pt.cp(0, 0, height);//next unit size = child sizes
double nextSize = IRandom.getDouble(.95, 1)*size;
IVec nextPos= pos.dup();double dir = IRandom.getInt(0, 7);
if (time==0) { //delayed to create the next agent til time==0
if (dir==0) nextPos.add(axis.dup().len(nextSize));else if (dir ==1) nextPos.add (axis.dup().len(-nextSize));else if (dir ==2) nextPos.add (axis.cross(IVec.zaxis).len(nextSize));else if (dir ==3) nextPos.add (axis.cross(IVec.zaxis).len(-nextSize));else if (dir ==4) nextPos.add (axis.cross(IVec.yaxis).len(-nextSize));else if (dir ==5) nextPos.add (axis.cross(IVec.yaxis).len(nextSize));else if (dir ==6) nextPos.add (axis.cross(IVec.xaxis).len(-nextSize));else {
nextPos.add (axis.cross(IVec.xaxis).len(nextSize));}
IVec nextAxis = axis.dup().rot(IVec.xaxis, PI/20);
int r = clr().getRed() + IRandom.getInt(-100, 100);
int g = clr().getGreen() + IRandom.getInt(-100, 100);
int b = clr().getBlue() + IRandom.getInt(50, 100);
new MyAgent(nextPos, nextSize, nextSize, nextSize,nextAxis).clr(r, g, b);}}}}
ISurface[] createTetrahedron(IVec pt, double size, double height) {// tetrahedron
IVec vertexDir = new IVec(size, 0, 0);
IVec v1 = pt.cp(vertexDir);vertexDir.rot(IVec.zaxis, PI*2/3);
IVec v2 = pt.cp(vertexDir);

ISurface[] triangles = new ISurface[4];triangles[0] = new ISurface(v1.dup(), v2.dup(), v3.dup());
triangles[1] = new ISurface(v1.dup(), v2.dup(), v4.dup());
triangles[2] = new ISurface(v1.dup(), v3.dup(), v4.dup());
triangles[3] = new ISurface(v2.dup(), v3.dup(), v4.dup());
return triangles;}
ISurface[] createOctahedron(IVec pt, double size, double height) {// tetrahedron
IVec v1 = pt.cp(size/2, size/2, 0);
IVec v2 = pt.cp(-size/2, size/2, 0);
IVec v3 = pt.cp(-size/2, -size/2, 0);
IVec v4 = pt.cp(size/2, -size/2, 0);
IVec v5 = pt.cp(0, 0, height/2);
IVec v6 = pt.cp(0, 0, -height/2);
ISurface[] triangles = new ISurface[8];triangles[0] = new ISurface(v1.dup(), v2.dup(), v5.dup());
triangles[1] = new ISurface(v2.dup(), v3.dup(), v5.dup());
triangles[2] = new ISurface(v3.dup(), v4.dup(), v5.dup());
triangles[3] = new ISurface(v4.dup(), v1.dup(), v5.dup());
triangles[4] = new ISurface(v4.dup(), v3.dup(), v6.dup());
triangles[5] = new ISurface(v3.dup(), v2.dup(), v6.dup());
triangles[6] = new ISurface(v2.dup(), v1.dup(), v6.dup());
triangles[7] = new ISurface(v1.dup(), v4.dup(), v6.dup());
return triangles;}}