createCanvas(windowWidth, windowHeight);
TZ = 1/sqrt(3)*GTZ ; TZx = GTZ ; TZy = sqrt(3)/2*GTZ
TX = floor(windowWidth/TZx) ; TY = floor(windowHeight/TZy)
HA = [[0]] ; HX = [0] ; HY = [0] ; HC = [] ; HCo = [] ; HCiv = []
for(ix=0.5*(iy % 2);ix<TX;ix++)
HC[c] = tercol(ix/8,iy/8) ; HCo[c] = HC[c]
HCiv[c] = (blue(HC[c]) > 200 ? -1 : 0)
HA[c++] = expand(expand([(ix+.25)*TZx-sin(PI/3)*TZ,(iy+.5)*TZy-cos(PI/3)*TZ,
(ix+.25)*TZx-sin(2*PI/3)*TZ,(iy+.5)*TZy-cos(2*PI/3)*TZ,
(ix+.25)*TZx-sin(3*PI/3)*TZ,(iy+.5)*TZy-cos(3*PI/3)*TZ,
(ix+.25)*TZx-sin(4*PI/3)*TZ,(iy+.5)*TZy-cos(4*PI/3)*TZ,
(ix+.25)*TZx-sin(5*PI/3)*TZ,(iy+.5)*TZy-cos(5*PI/3)*TZ,
(ix+.25)*TZx,(iy+.5)*TZy-TZ],GTZ*0.75),GTZ/2)
civ = [] ; civz = [] ; civstr = []
function mouseClicked() {
var col = color(random(255),random(255),random(255))
HC[gethex(mouseX,mouseY)] = col
HCiv[gethex(mouseX,mouseY)] = civ.length
ix = round(ix/TZx-0.5*(iy % 2))
for(i=0;i<civ.length+1;i++) {if (civz[i] > 0) civstr[i] = noise(i*100,time/75) ; civz[i] = 0}
fill(lerpColor(HC[i],HCo[i],.25))
for(ii=0;ii<48;ii+=2) vertex(HA[i][ii],HA[i][ii+1])
if (HCiv[i] > 0 && random(1) < 0.15)
var nc = get_neighbour(HX[i],HY[i])
if (nc > -1 && nc < HC.length)
if (HCiv[nc] != -1 && HCiv[nc] != HCiv[i])
if (random(1) < .9 || HCiv[nc] > 0)
if (civstr[HCiv[i]]+random(0.05) > civstr[HCiv[nc]] || HCiv[nc] == 0)
var col = color(random(255),random(255),random(255))
text("Click to start civilization",10,15)
for(i=0;i<civ.length+1;i++)
rect(0,25*nc,50+15*sqrt(civz[i]),25)
if (civz[i]*sq(sq(sq(sq(sq(sq(sq(sq(random(1))))))))) > 35 && i > 0)
var col = color(random(255),random(255),random(255))
if (noise(HX[ii]/200+offset,HY[ii]/200) > .5)
text((i == 0 ? "no people land " : "civilization numero "+i)+": "+civz[i],10,15+25*nc++)
function get_neighbour(ix,iy) {
var d = floor(random(6))*PI/3
if (random(1) < .99) {ix += cos(d)*TZ ; iy += sin(d)*TZ}
else {ix += random(random(random(200)))*(random(1) > .5 ? 1 : -1) ; iy += random(random(random(200)))*(random(1) > .5 ? 1 : -1)}
A[i] += -50+100*noise(A[i]/100+1000,A[i+1]/100)
A[i+1] += -50+100*noise(A[i]/100+1000,A[i+1]/100)
NA[i*2+2] = (A[i]+A[(i+2) % c])/2
NA[i*2+3] = (A[i+1]+A[(i+3) % c])/2
NA[i] += -v/2+v*noise(NA[i]/10+100,NA[i+1]/10)
NA[i+1] += -v/2+v*noise(NA[i]/10,NA[i+1]/10+100)
var b = -4+8*noise(ix/4,iy/4-100)
return(lerpColor(lerpColor(lerpColor(color(130,240,80),b>0 ? color(220,210,100) : color(0,220,100),abs(b)),color(200,190,160),h*4-2),color(0),random(.05)))
return(lerpColor(color(50,50,220),color(0,150,250),h*2))