grain
Add Grain to full canvas, or for a zone
grain(
amount,
[points]
) -> NULL
Add Grain to full canvas, or for a zone
Arguments
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
amount | yes | - | Amount on grain (5 => random grain between -5 and 5) | |
points | - | - | Coords of zone [x1,y1,x2,y2] - if empty:all canvas |
Full example
var tanSize = 300 ;
canvas(tanSize*3, tanSize*2, "#EAEBEB");
stroke("#000");
weight(1);
var offsetY = 30 ;
var oY = 0 ;
def tangram(posx, posy, w) {
var x = posx*tanSize + w/2;
var y = posy*tanSize + posy + w/2;
var h = w;
var u = w / 4;
coord_open();
coord_translate(x,y);
triangle_right(cx=0, cy=0, a=u*2*sqrt(2), b=u*2*sqrt(2), angle=PI*5/4, from=true, fill="#66BB6A");
triangle_right(cx=0, cy=0, a=u*2*sqrt(2), b=u*2*sqrt(2), angle=PI*3/4, from=true, fill="#EF5350");
triangle_right(cx=u*2, cy=u*2, a=u*2, b=u*2, angle=PI, from=true, fill="#BDBDBD");
polygon([u,-u, u*2,0, u,u, 0,0], fill="#FFCA28");
triangle_right(cx=u, cy=-u, a=u*sqrt(2), b=u*sqrt(2), angle=-PI/4, from=true, fill="#EC407A");
triangle_right(cx=0, cy=0, a=u*sqrt(2), b=u*sqrt(2), angle=PI/4, from=true, fill="#26C6DA");
polygon([-u*2,u*2, 0,u*2, u,u, -u,u], fill="#7E57C2");
coord_close();
}
tangram(0,0, tanSize);
tangram(1,0, tanSize);
tangram(2,0, tanSize);
tangram(0,1, tanSize);
tangram(1,1, tanSize);
tangram(2,1, tanSize);
font_default(30);
def getRect(posx, posy) {
return [posx*tanSize, posy*tanSize + posy, (posx+1)*tanSize, (posy+1)*tanSize + posy];
}
def explain(txt, posx, posy) {
text(txt, tanSize/2 + posx*tanSize, tanSize + posy*tanSize , ax=middle, ay=start);
}
var gAmount = 30 ;
grain(gAmount*1, points=getRect(1,0)); explain(gAmount*1, 1, 0);
grain(gAmount*2, points=getRect(2,0)); explain(gAmount*2, 2, 0);
grain(gAmount*3, points=getRect(0,1)); explain(gAmount*3, 0, 1);
grain(gAmount*4, points=getRect(1,1)); explain(gAmount*4, 1, 1);
grain(gAmount*5, points=getRect(2,1)); explain(gAmount*5, 2, 1);
save(whoami() + ".png");
