import processing.opengl.*;import igeo.p.*;
import igeo.io.*;import igeo.geo.*;import igeo.util.*;import igeo.core.*;import igeo.gui.*;

import processing.opengl.*;import igeo.core.*;import igeo.geo.*;import igeo.util.*;size(480, 360, IG.GL);

IG.open("newsphere.3dm");
ISurface[] surfs = IG.surfaces();
ISurface surf = surfs[0];size(700, 500, IG.GL);

IG.open("newsphere1.3dm");
ISurface[] surfaces = IG.surfaces();for (ISurface surf:surfaces) {int unum=1, vnum=1;
double uinc=1.0/unum, vinc=1.0/vnum;for (int i=0; i<unum; i++) {for (int j=0; j<vnum; j++) {int unum = 17;
int vnum = 11;
double uinc = 1./unum;
double vinc = 1./vnum;
double depth1 = -2;
double depth2 = -5;
double depth3 = -20;

IVec pt1 = surf.pt(i*uinc, j*vinc);
IVec pt2 = surf.pt((i+1)*uinc, j*vinc);
IVec pt3 = surf.pt((i+1)*uinc, (j+1)*vinc);
IVec pt4 = surf.pt(i*uinc, (j+1)*vinc);for (int i=0; i < unum; i++) {for (int j=0; j < vnum; j++) {if(IRandom.percent(50)){//folding in U
double ratio1 = IRandom.get(0.5,0.7);
double ratio1a = IRandom.get(0,0.2);
double ratio2 = IRandom.get(0.8,1.0);
double ratio2a = IRandom.get(0.2,0.4);

double u1 = i*uinc;double u2 = (i+1)*uinc;double v1 = j*vinc;
double v2 = (j+1)*vinc;

if (IRandom.percent(50)) {IVec pt1 = surf.pt( u1, v1 );IVec pt2 = surf.pt( u2, v1 );IVec pt3 = surf.pt( u2, v2 );IVec pt4 = surf.pt( u1, v2 );//new ISurface(pt1, pt2, pt3, pt4).clr(1.0, 0.1, 0);// getting point on U edge
IVec pt5 = surf.pt( (i+ratio1)*uinc, j*vinc);
IVec pt6 = surf.pt( (i+ratio2)*uinc, j*vinc);
IVec pt7 = surf.pt( (i+ratio1a)*uinc, (j+1)*vinc);
IVec pt8 = surf.pt( (i+ratio2a)*uinc, (j+1)*vinc);

IVec pt1d = surf.pt( u1, v1, depth1 );IVec pt2d = surf.pt( u2, v1, depth1 );IVec pt3d = surf.pt( u2, v2, depth1 );IVec pt4d = surf.pt( u1, v2, depth1);

IVec rotCenter = pt1;
double rotAngle = IRandom.get(-0.2, -0.4);

IVec ptCenter = surf.pt( (u1+u2)/2, (v1+v2)/2, depth2);
IVec ptCenter2 = surf.pt( (u1+u2)/2, (v1+v2)/2, depth3);

pt5.rot(rotCenter, rotAxis, rotAngle);
pt7.rot(rotCenter, rotAxis, rotAngle);
pt6.rot(rotCenter, rotAxis, rotAngle);
pt8.rot(rotCenter, rotAxis, rotAngle);
pt2.rot(rotCenter, rotAxis, rotAngle);
pt3.rot(rotCenter, rotAxis, rotAngle);

IVec rotCenter2 = pt7;
double rotAngle2 = IRandom.get(-0.8,-0.6);
pt6.rot(rotCenter2, rotAxis2, rotAngle2);
pt8.rot(rotCenter2, rotAxis2, rotAngle2);
pt2.rot(rotCenter2, rotAxis2, rotAngle2);
pt3.rot(rotCenter2, rotAxis2, rotAngle2);double size = 0.5;
IG.pipe (new IVec[]{pt1d, pt2d},1,true,size).clr(0, 1., 0);IG.pipe (new IVec[]{pt2d, pt3d},1,true,size).clr(0, 1., 0);IG.pipe (new IVec[]{pt3d, pt4d},1,true,size).clr(0, 1., 0);IG.pipe (new IVec[]{pt4d, pt1d},1,true,size).clr(0, 1., 0);/*
new ICurve(pt1, pt1d).clr(0, 0, 1.);
new ICurve(pt2, pt2d).clr(0, 0, 1.);
new ICurve(pt3, pt3d).clr(0, 0, 1.);
new ICurve(pt4, pt4d).clr(0, 0, 1.);
new IPoint (ptCenter).clr(0, 0, 0.2);
new IPoint (ptCenter2).clr(0, 0, 0.2);

IVec rotCenter3 = pt6;
double rotAngle3 = IRandom.get(0.3,0.6);

pt2.rot(rotCenter3, rotAxis3, rotAngle3);
pt3.rot(rotCenter3, rotAxis3, rotAngle3);

IVec[][] cpts = new IVec[2][4];cpts[0][0] = pt2;
cpts[0][1] = pt6;
cpts[0][2] = pt5;
cpts[0][3] = pt1;
cpts[1][0] = pt3;
cpts[1][1] = pt8;
cpts[1][2] = pt7;
cpts[1][3] = pt4;

new ICurve(pt1, ptCenter).clr(1, 0.5, 0.9);
new ICurve(pt2, ptCenter).clr(1, 0.5, 0.9);
new ICurve(pt3, ptCenter).clr(1, 0.5, 0.9);
new ICurve(pt4, ptCenter).clr(1, 0.5, 0.9); */// new ICurve(ptCenter2, ptCenter).clr(1, 0.5, 0.9);}
else {
int unum2 = 2;
int vnum2 = 2;
double uinc2 = 1.0/unum2;
double vinc2 = 1.0/vnum2;for (int k=0; k < unum2; k++) {for (int l=0; l < vnum2; l++) {if (IRandom.percent(50)) {double u1 = ( i + k * uinc2 ) * uinc;double u2 = ( i + (k+1) * uinc2 ) * uinc;double v1 = ( j + l * vinc2 ) * vinc;
double v2 = ( j + (l+1) * vinc2) * vinc;

int udeg4 = 1, vdeg4 = 1;
new ISurface(cpts, udeg4, vdeg4).clr(0.7,ratio2*IRandom.get(0.1,0.8),0.2);
surf.del();}else{// folding in V
double ratio1 = IRandom.get(0,0.2);
double ratio1a = IRandom.get(0.6,0.8);
double ratio2 = IRandom.get(0.2,0.4);
double ratio2a = IRandom.get(0.8,1);// getting point on V edge
IVec pt5 = surf.pt( i*uinc, (j+ratio1)*vinc);
IVec pt6 = surf.pt( i*uinc, (j+ratio2)*vinc);
IVec pt7 = surf.pt( (i+1)*uinc, (j+ratio1a)*vinc);
IVec pt8 = surf.pt( (i+1)*uinc, (j+ratio2a)*vinc);

IVec pt1 = surf.pt( u1, v1 );IVec pt2 = surf.pt( u2, v1 );IVec pt3 = surf.pt( u2, v2 );IVec pt4 = surf.pt( u1, v2 );// new ISurface(pt1, pt2, pt3, pt4).clr(0.1, 1.0, 0);
IVec pt1d = surf.pt( u1, v1, depth1 );IVec pt2d = surf.pt( u2, v1, depth1 );IVec pt3d = surf.pt( u2, v2, depth1 );IVec pt4d = surf.pt( u1, v2, depth1);
IVec ptCenter = surf.pt( (u1+u2)/2, (v1+v2)/2, depth2);
IVec ptCenter2 = surf.pt( (u1+u2)/2, (v1+v2)/2, depth3);
double size = 0.5;
IG.squarePipe (new IVec[]{pt1d, pt2d},1,true,size).clr(0, 1., 0);
IG.squarePipe (new IVec[]{pt2d, pt3d},1,true,size).clr(0, 1., 0);IG.squarePipe (new IVec[]{pt3d, pt4d},1,true,size).clr(0, 1., 0);
IG.squarePipe (new IVec[]{pt4d, pt1d},1,true,size).clr(0, 1., 0);

IVec rotCenter = pt1;
double rotAngle = IRandom.get(-0.3,-0.4);
pt5.rot(rotCenter, rotAxis, rotAngle);
pt7.rot(rotCenter, rotAxis, rotAngle);
pt6.rot(rotCenter, rotAxis, rotAngle);
pt8.rot(rotCenter, rotAxis, rotAngle);//pt2.rot(rotCenter, rotAxis, rotAngle);// pt3.rot(rotCenter, rotAxis, rotAngle);/*new ICurve(pt1d, pt2d).clr(0, 1., 0);
new ICurve(pt2d, pt3d).clr(0, 1., 0);
new ICurve(pt3d, pt4d).clr(0, 1., 0);
new ICurve(pt4d, pt1d).clr(0, 1., 0);
new ICurve(pt1, pt1d).clr(0, 0, 1.);
new ICurve(pt2, pt2d).clr(0, 0, 1.);
new ICurve(pt3, pt3d).clr(0, 0, 1.);

IVec rotCenter2 = pt5;
double rotAngle2 = IRandom.get(-0.8,0);
pt6.rot(rotCenter2, rotAxis2, rotAngle2);
pt8.rot(rotCenter2, rotAxis2, rotAngle2);
pt2.rot(rotCenter2, rotAxis2, rotAngle2);
pt3.rot(rotCenter2, rotAxis2, rotAngle2);

IVec rotCenter3 = pt8;
double rotAngle3 = IRandom.get(0.7,1.0);

pt2.rot(rotCenter3, rotAxis3, rotAngle3);
pt3.rot(rotCenter3, rotAxis3, rotAngle3);
IVec[][] cpts = new IVec[2][4];cpts[0][0] = pt1;
cpts[0][1] = pt5;
cpts[0][2] = pt6;
cpts[0][3] = pt4;
cpts[1][0] = pt2;
cpts[1][1] = pt7;
cpts[1][2] = pt8;
cpts[1][3] = pt3;
int udeg4 = 1, vdeg4 = 1;
new ISurface(cpts, udeg4, vdeg4).clr(IRandom.get(0.1,0.8),IRandom.get(0.1,0.8),0.4);
surf.del();}}}}//IG.save("newsphere1outcolour.3dm");

SAMUEL LIEW | CODING FORM |INSTRUCTOR: SATORU SUGIHARA