Random Tiling
Random Tiling by Philippe Guglielmetti, aka Dr. Goulu 2011
inspired by http://paulbourke.net/texture_colour/randomtile/
and http://www.openprocessing.org/visuals/?visualID=5464
HTML
<script type="application/processing">
/*
Random Tiling by Philippe Guglielmetti, aka Dr. Goulu 2011
inspired by http://paulbourke.net/texture_colour/randomtile/
and http://www.openprocessing.org/visuals/?visualID=5464
*/
float c=1.1;
int n=0; // start with circles
float g(int i) {return pow(i,-c);}
float RiemannZeta() {
float s=0;
for (int i=1; g(i)>1E-6; i++) {s+=g(i);}
return s;
}
float Angle2D(float x1,float y1,float x2,float y2)
{
float dtheta = atan2(y2,x2) - atan2(y1,x1);
while (dtheta > PI)
dtheta -= 2*PI;
while (dtheta < -PI)
dtheta += 2*PI;
return(dtheta);
}
boolean LineIntersect(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4)
{
float eps=1e-9;
float denom = (y4-y3) * (x2-x1) - (x4-x3) * (y2-y1);
float numera = (x4-x3) * (y1-y3) - (y4-y3) * (x1-x3);
float numerb = (x2-x1) * (y1-y3) - (y2-y1) * (x1-x3);
// Are the line coincident?
if (abs(numera) < eps && abs(numerb) < eps && abs(denom) < eps)
return(true);
// Are the line parallel
if (abs (denom) < eps)
return(false);
// Is the intersection along the the segments
float mua = numera / denom;
float mub = numerb / denom;
if (mua < 0 || mua > 1 || mub < 0 || mub > 1)
return(false);
return(true );
}
class Poly {
int pts; // points
float area,phi;
float cx,cy;
float cr; // cercle circonscrit
Poly(int n, float a) {
area=a;
pts=n;
if (pts<3) {
cr=sqrt(area/PI);
}
else if (pts==10){ // pentagram
float t=2*sin(PI/5);
t=(5*t*t/4)*(tan(3*PI/10)-tan(PI/5));
cr=sqrt(area/t);
}
else{
cr=sqrt(2*area/(n*sin(2*PI/n))); //http://www.mathwords.com/a/area_regular_polygon.htm
}
}
void Random(float pmin, float pmax) {
cx=random(cr,width-cr);
cy=random(cr,height-cr);
phi=random(pmin,pmax);
}
float X(int i) {
float r=cr;
if (pts==10 && i%2==1) {r=r/2.5;}
return...
JavaScript
var scripts = document.getElementsByTagName("script");
for (var i = 0; i < scripts.length; i++) {
if (scripts[i].type == "application/processing") {
var src = scripts[i].src,
canvas = scripts[i].nextSibling;
if (src && src.indexOf("#")) {
canvas = document.getElementById(src.substr(src.indexOf("#") + 1));
} else {
while (canvas && canvas.nodeName.toUpperCase() != "CANVAS")
canvas = canvas.nextSibling;
}
if (canvas) {
new Processing(canvas, scripts[i].text);
}
}
}