Fields of Grain
Random lines rotated by a sine field
Log in to post a comment.
Canvas.setpenopacity(1);
// Global code will be evaluated once.
const turtle = new Turtle();
let seed = 1; // min=1 max=100 step=1
const bits = 20;
const samples = 150000;
const mod = 1<<bits;
const rot = 3.2; // min = 0.01 max = 6.28 step = 0.01
const density = 7; // min = 0 max = 20 step = 0.1
const min_length = 1.5; // min = 0 max = 10 step = 0.01
const length_range = 5; // min = 0 max = 10 step = 0.01
const x_rot = 0.01; // min = 0 max = 0.05 step = 0.0001
const y_rot = 0.03; // min = 0 max = 0.05 step = 0.0001
const num_lines = 10000; // min = 100 max = 10000 step = 100
function rot_line(x,y,length,rot) {
turtle.penup();
turtle.goto(x + Math.cos(rot * Math.PI / 180)*length/2, y + Math.sin(rot * Math.PI / 180)*length/2);
turtle.pendown();
turtle.goto(x - Math.cos(rot * Math.PI / 180)*length/2, y - Math.sin(rot * Math.PI / 180)*length/2);
}
function walk(i, t) {
for(let j = 0; j < num_lines; j++) {
let xi = random() * 200 - 100;
let yi = random() * 200 - 100;
let li = random() * length_range + min_length;
rot_line(xi, yi, li, density*Math.cos(t*rot+xi*x_rot)*xi+density*Math.sin(t*rot+yi*y_rot)*yi);
}
}
////////////////////////////////////////////////////////////////
// Pseudorandom number generator. Created by Reinder Nijhoff 2024
// https://turtletoy.net/turtle/a2274fd1fe
////////////////////////////////////////////////////////////////
function random() { // returns a number [0, 1]
let r = 1103515245 * (((seed+=12345) >> 1) ^ seed);
r = 1103515245 * (r ^ (r >> 3));
r = r ^ (r >> 16);
return (r % mod) / mod;
}