cLista lista = new cLista();
while((t++ < 50) && (el0 < lista.nr)) {
lista.agg(0, (int)random(rag, width-rag), (int)random(0.3*height, 0.5*height-rag));
p1 = proietta(new PVector(-10, 0, 240));
p2 = proietta(new PVector(-10, 0, -60));
p1 = proietta(new PVector(-20, 0, 240));
p2 = proietta(new PVector(-20, 0, -60));
p1 = proietta(new PVector(-40, 0, -5));
p2 = proietta(new PVector(240, 0, -5));
p1 = proietta(new PVector(-40, 0, -15));
p2 = proietta(new PVector(240, 0, -15));
palazzo(new PVector(40, 0, 80));
palazzo(new PVector(40, 0, 40));
palazzo(new PVector(0, 0, z*40));
for(int x=6; x>=0; x--) {
palazzo(new PVector(x*40, 0, 0));
for(int x=220; x>=0; x-=40) {
albero(new PVector(x, 0, -2));
albero(new PVector(-2, 0, x));
semaforox(new PVector( 0, 0, 162));
semaforox(new PVector( 0, 0, 82));
semaforox(new PVector( 0, 0, 2));
semaforoz(new PVector(82, 0, 0));
semaforoz(new PVector( 2, 0, 0));
palazzo(new PVector(0, 0, -53));
PVector proietta(PVector pt) {
float alfa = radians(30);
float a = pt.x * sin(alfa) - pt.z * cos(alfa);
float b = pt.x * cos(alfa) + pt.z * sin(alfa);
float x = d * a / (b + d);
float y = d * (pt.y - h) / (b + d);
return new PVector(0.63*width + sc*x, 0.95*height - sc*y);
void palazzo(PVector pt) {
int tipo = int(random(10));
int h = int(random(50, 100));
box3d(new PVector(pt.x+20, h, pt.z+10), new PVector(pt.x+21, h+random(20, 40), pt.z+11));
box3d(new PVector(pt.x+10, h, pt.z+10), new PVector(pt.x+11, h+random(20, 40), pt.z+11));
rettangolo_bianco(new PVector(pt.x, h, pt.z), new PVector(pt.x+30, h, pt.z), new PVector(pt.x+30, h, pt.z+30), new PVector(pt.x, h, pt.z+30));
box3d(new PVector(pt.x, 20, pt.z), new PVector(pt.x+30, h-4, pt.z+30));
for (int fi=30-3; fi>0; fi-=3) {
linea(proietta(new PVector(pt.x, 20, pt.z+fi)), proietta(new PVector(pt.x, h-4, pt.z+fi)));
linea(proietta(new PVector(pt.x+fi, 20, pt.z)), proietta(new PVector(pt.x+fi, h-4, pt.z)));
box3d(pt, new PVector(pt.x+30, 19, pt.z+30));
int nr = int(random(5, 20));
for (int i=nr-1; i>=0; i--) {
box3d(new PVector(pt.x, i*4+4, pt.z), new PVector(pt.x+30, i*4+6, pt.z+30));
box3d(new PVector(pt.x+1, h-10, pt.z+1), new PVector(pt.x+29, h, pt.z+29));
box3d(new PVector(pt.x+ 2, 10, pt.z+22), new PVector(pt.x+ 4, h-10, pt.z+28));
box3d(new PVector(pt.x+22, 10, pt.z+ 2), new PVector(pt.x+28, h-10, pt.z+ 4));
box3d(new PVector(pt.x+ 4, 10, pt.z+ 4), new PVector(pt.x+22, h-10, pt.z+22));
box3d(new PVector(pt.x+ 2, 10, pt.z+ 2), new PVector(pt.x+ 8, h-10, pt.z+ 8));
box3d(new PVector(pt.x+14.5, h, pt.z+14.5), new PVector(pt.x+15.5, h+40, pt.z+15.5));
if (h > 50) box3d(new PVector(pt.x+2, 50, pt.z+2), new PVector(pt.x+28, h, pt.z+28));
if (h > 50) box3d(new PVector(pt.x+4, 42, pt.z+4), new PVector(pt.x+26, 50, pt.z+26));
if (h > 42) box3d(new PVector(pt.x+2, 16, pt.z+2), new PVector(pt.x+28, 42, pt.z+28));
if (h > 16) box3d(new PVector(pt.x+4, 12, pt.z+4), new PVector(pt.x+26, 16, pt.z+26));
if (h > 12) basamento(pt, 12);
cilindro3d(new PVector(pt.x, 31, pt.z), h-16, 32, 13, true);
cilindro3d(new PVector(pt.x, 26, pt.z), 4, 32, 13, true);
cilindro3d(new PVector(pt.x, 21, pt.z), 4, 32, 13, true);
cilindro3d(new PVector(pt.x, 16, pt.z), 4, 32, 13, true);
cilindro3d(new PVector(pt.x, 12, pt.z), 4, 32, 11, true);
cilindro3d(new PVector(pt.x, 0, pt.z), 12, 32, 15, false);
cilindro3d(new PVector(pt.x, h-2, pt.z), 2, 8, 13, true);
cilindro3d(new PVector(pt.x, h-6, pt.z), 4, 8, 9, true);
cilindro3d(new PVector(pt.x, 8, pt.z), h-14, 8, 13, true);
box3d(pt, new PVector(pt.x+30, pt.y+1, pt.z+30));
for (int i=0; i<10; i++) {
float pz = map(i, 0, 10, 0, 22);
float px = random(0, pz);
PVector pt0 = new PVector(pt.x+26-px, pt.y+1, pt.z+26-pz+px);
box3d(new PVector(pt.x+5, 32, pt.z+5), new PVector(pt.x+25, h, pt.z+25));
box3d(new PVector(pt.x+10, 26, pt.z+10), new PVector(pt.x+20, 32, pt.z+20));
box3d(new PVector(pt.x+5, 26, pt.z+24), new PVector(pt.x+5, 32, pt.z+25));
box3d(new PVector(pt.x+5, 26, pt.z+18), new PVector(pt.x+5, 32, pt.z+19));
box3d(new PVector(pt.x+5, 26, pt.z+11), new PVector(pt.x+5, 32, pt.z+12));
box3d(new PVector(pt.x+24, 26, pt.z+5), new PVector(pt.x+25, 32, pt.z+6));
box3d(new PVector(pt.x+18, 26, pt.z+5), new PVector(pt.x+19, 32, pt.z+6));
box3d(new PVector(pt.x+11, 26, pt.z+5), new PVector(pt.x+12, 32, pt.z+6));
box3d(new PVector(pt.x+ 5, 26, pt.z+5), new PVector(pt.x+ 6, 32, pt.z+6));
cilindro3d(new PVector(pt.x, 6, pt.z), 20, 25, 15, false);
box3d(new PVector(pt.x+10, 0, pt.z+10), new PVector(pt.x+20, 6, pt.z+20));
box3d(new PVector(pt.x+5, 0, pt.z+24), new PVector(pt.x+5, 6, pt.z+25));
box3d(new PVector(pt.x+5, 0, pt.z+18), new PVector(pt.x+5, 6, pt.z+19));
box3d(new PVector(pt.x+5, 0, pt.z+11), new PVector(pt.x+5, 6, pt.z+12));
box3d(new PVector(pt.x+24, 0, pt.z+5), new PVector(pt.x+25, 6, pt.z+6));
box3d(new PVector(pt.x+18, 0, pt.z+5), new PVector(pt.x+19, 6, pt.z+6));
box3d(new PVector(pt.x+11, 0, pt.z+5), new PVector(pt.x+12, 6, pt.z+6));
box3d(new PVector(pt.x+ 5, 0, pt.z+5), new PVector(pt.x+ 6, 6, pt.z+6));
box3d(new PVector(pt.x+2, 6, pt.z+2), new PVector(pt.x+18, h-10, pt.z+18));
box3d(new PVector(pt.x, 0, pt.z+23), new PVector(pt.x+2, h , pt.z+28));
box3d(new PVector(pt.x, 0, pt.z+18), new PVector(pt.x+2, h-5, pt.z+23));
box3d(new PVector(pt.x, 0, pt.z+ 7), new PVector(pt.x+2, h-5, pt.z+12));
box3d(new PVector(pt.x, 0, pt.z+ 2), new PVector(pt.x+2, h , pt.z+ 7));
box3d(new PVector(pt.x+23, 0, pt.z), new PVector(pt.x+28, h , pt.z+2));
box3d(new PVector(pt.x+18, 0, pt.z), new PVector(pt.x+23, h-5, pt.z+2));
box3d(new PVector(pt.x+ 7, 0, pt.z), new PVector(pt.x+12, h-5, pt.z+2));
box3d(new PVector(pt.x+ 2, 0, pt.z), new PVector(pt.x+ 7, h , pt.z+2));
cilindro3d(new PVector(pt.x, 0, pt.z), h, 32, 11, true);
box3d(new PVector(pt.x, 0, pt.z+15), new PVector(pt.x+4, h, pt.z+30));
box3d(new PVector(pt.x+15, 0, pt.z), new PVector(pt.x+30, h, pt.z+4));
float iw = random(1, 1.5);
float ih = random(2, 10);
float ipos = random(2, 14);
rettangolo_bianco(new PVector(pt.x+ipos, 4, pt.z-1), new PVector(pt.x+ipos, 4+ih, pt.z-1), new PVector(pt.x+ipos, 4+ih, pt.z-1-iw), new PVector(pt.x+ipos, 4, pt.z-1-iw));
ipos = random(2, 14) + 15;
rettangolo_bianco(new PVector(pt.x+ipos, 4, pt.z-1), new PVector(pt.x+ipos, 4+ih, pt.z-1), new PVector(pt.x+ipos, 4+ih, pt.z-1-iw), new PVector(pt.x+ipos, 4, pt.z-1-iw));
rettangolo_bianco(new PVector(pt.x-1, 4, pt.z+ipos), new PVector(pt.x-1, 4+ih, pt.z+ipos), new PVector(pt.x-1-iw, 4+ih, pt.z+ipos), new PVector(pt.x-1-iw, 4, pt.z+ipos));
ipos = random(2, 14) + 15;
rettangolo_bianco(new PVector(pt.x-1, 4, pt.z+ipos), new PVector(pt.x-1, 4+ih, pt.z+ipos), new PVector(pt.x-1-iw, 4+ih, pt.z+ipos), new PVector(pt.x-1-iw, 4, pt.z+ipos));
void basamento(PVector pt, float h) {
int nr1 = int(random(1, 5));
int nr2 = int(random(1, 5));
float inter1 = 27.0 / nr1;
float inter2 = 27.0 / nr2;
box3d(pt, new PVector(pt.x+30, h, pt.z+30));
rettangolo_rigato(new PVector(pt.x, 6, pt.z+2), new PVector(pt.x, h-2, pt.z+2), new PVector(pt.x, h-2, pt.z+28), new PVector(pt.x, 6, pt.z+28));
for (int i=0; i<nr1; i++) {
rettangolo_rigato(new PVector(pt.x, 0, pt.z+2+i*inter1), new PVector(pt.x, 4, pt.z+2+i*inter1), new PVector(pt.x, 4, pt.z+1+(i+1)*inter1), new PVector(pt.x, 0, pt.z+1+(i+1)*inter1));
rettangolo_nero(new PVector(pt.x+2, 6, pt.z), new PVector(pt.x+2, h-2, pt.z), new PVector(pt.x+28, h-2, pt.z), new PVector(pt.x+28, 6, pt.z));
for (int i=0; i<nr2; i++) {
rettangolo_nero(new PVector(pt.x+2+i*inter2, 0, pt.z), new PVector(pt.x+2+i*inter2, 4, pt.z), new PVector(pt.x+1+(i+1)*inter2, 4, pt.z), new PVector(pt.x+1+(i+1)*inter2, 0, pt.z));
void albero(PVector pt0) {
PVector pp0 = proietta(pt0);
PVector pp1 = proietta(pt1);
PVector pp2 = proietta(pt2);
lista.agg(0, (int)pp1.x, (int)pp1.y);
lista.agg(6, int(pp2.x-pp1.x), 0);
void semaforox(PVector pt0) {
linea(proietta(new PVector(pt0.x -2, 0, pt0.z)), proietta(new PVector(pt0.x -2, 5, pt0.z)));
linea(proietta(new PVector(pt0.x-28, 0, pt0.z)), proietta(new PVector(pt0.x-28, 5, pt0.z)));
linea(proietta(new PVector(pt0.x -2, 4, pt0.z)), proietta(new PVector(pt0.x-28, 4, pt0.z)));
linea(proietta(new PVector(pt0.x -2, 5, pt0.z)), proietta(new PVector(pt0.x-28, 5, pt0.z)));
rettangolo_bianco(new PVector(pt0.x -4, 4, pt0.z), new PVector(pt0.x -4, 5, pt0.z), new PVector(pt0.x -9, 5, pt0.z), new PVector(pt0.x -9, 4, pt0.z));
rettangolo_bianco(new PVector(pt0.x-11, 4, pt0.z), new PVector(pt0.x-11, 5, pt0.z), new PVector(pt0.x-19, 5, pt0.z), new PVector(pt0.x-19, 4, pt0.z));
rettangolo_bianco(new PVector(pt0.x-21, 4, pt0.z), new PVector(pt0.x-21, 5, pt0.z), new PVector(pt0.x-26, 5, pt0.z), new PVector(pt0.x-26, 4, pt0.z));
void semaforoz(PVector pt0) {
linea(proietta(new PVector(pt0.x, 0, pt0.z -2)), proietta(new PVector(pt0.x, 5, pt0.z -2)));
linea(proietta(new PVector(pt0.x, 0, pt0.z-18)), proietta(new PVector(pt0.x, 5, pt0.z-18)));
linea(proietta(new PVector(pt0.x, 4, pt0.z -2)), proietta(new PVector(pt0.x, 4, pt0.z-18)));
linea(proietta(new PVector(pt0.x, 5, pt0.z -2)), proietta(new PVector(pt0.x, 5, pt0.z-18)));
rettangolo_bianco(new PVector(pt0.x, 4, pt0.z -4), new PVector(pt0.x, 5, pt0.z -4), new PVector(pt0.x, 5, pt0.z -9), new PVector(pt0.x, 4, pt0.z -9));
rettangolo_bianco(new PVector(pt0.x, 4, pt0.z-11), new PVector(pt0.x, 5, pt0.z-11), new PVector(pt0.x, 5, pt0.z-16), new PVector(pt0.x, 4, pt0.z-16));
void box3d(PVector pt1, PVector pt2) {
PVector p1 = proietta(new PVector(pt1.x, pt1.y, pt2.z));
PVector p2 = proietta(new PVector(pt1.x, pt2.y, pt2.z));
PVector p3 = proietta(new PVector(pt1.x, pt1.y, pt1.z));
PVector p4 = proietta(new PVector(pt1.x, pt2.y, pt1.z));
PVector p5 = proietta(new PVector(pt2.x, pt1.y, pt1.z));
PVector p6 = proietta(new PVector(pt2.x, pt2.y, pt1.z));
PVector p7 = proietta(new PVector(pt2.x, pt1.y, pt2.z));
lista.agg(3, (int)p1.x, (int)p1.y);
lista.agg(3, (int)p2.x, (int)p2.y);
lista.agg(3, (int)p4.x, (int)p4.y);
lista.agg(3, (int)p6.x, (int)p6.y);
lista.agg(3, (int)p5.x, (int)p5.y);
lista.agg(4, (int)p7.x, (int)p7.y);
lista.agg(3, (int)p1.x, (int)p1.y);
lista.agg(3, (int)p3.x, (int)p3.y);
lista.agg(3, (int)p5.x, (int)p5.y);
lista.agg(5, (int)p7.x, (int)p7.y);
_dlinea((int)p1.x, (int)p1.y, (int)p3.x, (int)p3.y);
_dlinea((int)p1.x, (int)p1.y, (int)p2.x, (int)p2.y);
_dlinea((int)p2.x, (int)p2.y, (int)p4.x, (int)p4.y);
_dlinea((int)p3.x, (int)p3.y, (int)p4.x, (int)p4.y);
_dlinea((int)p3.x, (int)p3.y, (int)p5.x, (int)p5.y);
_dlinea((int)p5.x, (int)p5.y, (int)p6.x, (int)p6.y);
_dlinea((int)p4.x, (int)p4.y, (int)p6.x, (int)p6.y);
_dlinea((int)p1.x, (int)p1.y, (int)p7.x, (int)p7.y);
_dlinea((int)p5.x, (int)p5.y, (int)p7.x, (int)p7.y);
striscia(pt2.y - pt1.y, p3, p4, p5, p6);
void cilindro3d(PVector pt, float h, int nrseg, float rad, boolean contorno) {
PVector [][] pv = new PVector[nrseg][2];
for (int i=0; i<nrseg; i++) {
float alfa = map(i, 0, nrseg, 0, TWO_PI);
pv[i][0] = proietta(new PVector(pt.x+15+rad*cos(alfa), pt.y, pt.z+15-rad*sin(alfa)));
pv[i][1] = proietta(new PVector(pt.x+15+rad*cos(alfa), pt.y+h, pt.z+15-rad*sin(alfa)));
for (int i=0; i<nrseg; i++) {
int j = (i + nrseg - 1) % nrseg;
if (pv[i][0].x <= pv[j][0].x) {
lista.agg(3, (int)pv[j][0].x, (int)pv[j][0].y);
lista.agg(3, (int)pv[i][0].x, (int)pv[i][0].y);
lista.agg(3, (int)pv[i][1].x, (int)pv[i][1].y);
lista.agg(4, (int)pv[j][1].x, (int)pv[j][1].y);
for (int i=0; i<nrseg; i++) {
lista.agg(3, (int)pv[i][0].x, (int)pv[i][0].y);
lista.agg(5, (int)pv[0][0].x, (int)pv[0][0].y);
for (int i=0; i<nrseg; i++) {
int j = (i + nrseg - 1) % nrseg;
float alfa = map(i, 0, nrseg, 0, TWO_PI) + 1;
if (pv[i][0].x <= pv[j][0].x) {
if (pv[(i+1)%nrseg][0].x >= pv[i][0].x) {
linea(pv[i][0], pv[i][1]);
if (contorno) linea(pv[i][0], pv[i][1]);
dlinea(pv[j][0], pv[i][0]);
dlinea(pv[j][1], pv[i][1]);
if (sin(alfa) > 0) striscia(h, pv[i][0], pv[i][1], pv[j][0], pv[j][1]);
if (pv[(i+1)%nrseg][0].x <= pv[i][0].x) {
linea(pv[i][0], pv[i][1]);
void pilotis(PVector pt0, float dex, float dez, float h) {
int nrx = int((dex - 1) / 6);
int nrz = int((dez - 1) / 6);
float delx = (dex-1) / nrx;
float delz = (dez-1) / nrz;
for (int i=nrz; i>0; i--) {
box3d(new PVector(pt0.x, 0, pt0.z+i*delz), new PVector(pt0.x+1, h, pt0.z+i*delz+1));
for (int i=nrx; i>=0; i--) {
box3d(new PVector(pt0.x+i*delx, 0, pt0.z), new PVector(pt0.x+i*delx+1, h, pt0.z+1));
void striscia(float del, PVector p1, PVector p2, PVector p3, PVector p4) {
float r1 = (p1.y - p2.y) / del;
float r2 = (p3.y - p4.y) / del;
_linea(int(p1.x), int(p2.y + pp * r1), int(p3.x), int(p4.y + pp * r2));
void rettangolo_bianco(PVector pt1, PVector pt2, PVector pt3, PVector pt4) {
PVector p1 = proietta(pt1);
PVector p2 = proietta(pt2);
PVector p3 = proietta(pt3);
PVector p4 = proietta(pt4);
lista.agg(3, (int)p1.x, (int)p1.y);
lista.agg(3, (int)p2.x, (int)p2.y);
lista.agg(3, (int)p3.x, (int)p3.y);
lista.agg(4, (int)p4.x, (int)p4.y);
void rettangolo_rigato(PVector pt1, PVector pt2, PVector pt3, PVector pt4) {
rettangolo_bianco(pt1, pt2, pt3, pt4);
striscia(pt2.y - pt1.y, proietta(pt1), proietta(pt2), proietta(pt4), proietta(pt3));
void rettangolo_nero(PVector pt1, PVector pt2, PVector pt3, PVector pt4) {
PVector p1 = proietta(pt1);
PVector p2 = proietta(pt2);
PVector p3 = proietta(pt3);
PVector p4 = proietta(pt4);
lista.agg(3, (int)p1.x, (int)p1.y);
lista.agg(3, (int)p2.x, (int)p2.y);
lista.agg(3, (int)p3.x, (int)p3.y);
lista.agg(5, (int)p4.x, (int)p4.y);
void rettf(int sx, int sy, int ex, int ey) {
for (int i=0; i<min(dex, dey); i+=6) {
lista.agg(1, sx, sy + i);
lista.agg(1, sx + i, sy);
for (int i=0; i<dex-dey; i+=6) {
lista.agg(1, sx + i, ey);
lista.agg(1, sx + dey + i, sy);
for (int i=0; i<dey-dex; i+=6) {
lista.agg(1, sx, sy + dex + i);
lista.agg(1, ex, sy + i);
for (int i=min(dex, dey); i>=0; i-=6) {
lista.agg(1, ex - i, ey);
lista.agg(1, ex, ey - i);
void _linea(int sx, int sy, int ex, int ey) {
void linea(PVector p1, PVector p2) {
_linea((int)p1.x, (int)p1.y, (int)p2.x, (int)p2.y);
void _dlinea(int sx, int sy, int ex, int ey) {
void dlinea(PVector p1, PVector p2) {
_dlinea((int)p1.x, (int)p1.y, (int)p2.x, (int)p2.y);
int mat[][] = new int [100000][3];
PVector [] pv = new PVector[100];
for (int i=0; i<pv.length; i++) {
pv[i] = new PVector(0, 0);
void agg(int tipo, int px, int py) {
mat[nr][1] = px + int(random(-de, de));
mat[nr][2] = py + int(random(-de, de));
line(penx, peny, mat[el][1], mat[el][2]);
rect(penx, peny, mat[el][1] - penx, mat[el][2] - peny);
for (int i=0; i<nrv; i++) {
vertex(pv[i].x, pv[i].y);
for (int i=0; i<nrv; i++) {
vertex(pv[i].x, pv[i].y);
float ra = random(2.1, 2.4);
ellipse(penx, peny, 2*mat[el][1], 2*mat[el][1]);
for (int i=0; i<nrs; i++) {
float alfa = map(i, 0, nrs, 0, 2 * TWO_PI);
float rad = mat[el][1] + 2 * de * sin(ra*alfa);
px1 = penx + int(rad * cos(alfa));
py1 = peny + int(rad * sin(alfa));
line(px0, py0, px1, py1);