Ex 1 Task 2
Shapes and Grid
Write functions for two basic shapes and place them in a grid. Vary position, rotation, scale, or the grid structure itself (irregularities, circle grid, etc.) to make it compelling. Export 3 compositions, give them a matching title and note what parameters you can manipulate.
Upload: 3 SVGs · 1 .js source file
Log in to post a comment.
const spacing = 25; // min=10, max=30, step=1
const size = 10; // min=1, max=20, step=1
const rotationFactor = 5; // min=0, max=20, step=1
const offset = 5; // min=0, max=20, step=1
const turtle = new Turtle();
const B = 200;
turtle.penup();
turtle.goto(-B, -B);
turtle.goto(B, B);
turtle.penup();
// --- TRIANGLE ---
function triangle(x, y, s, rot) {
turtle.penup();
turtle.goto(x, y);
turtle.setheading(rot);
turtle.pendown();
for (let i = 0; i < 3; i++) {
turtle.forward(s);
turtle.right(120);
}
turtle.penup();
}
// --- CIRCLE ---
function circle(x, y, r) {
turtle.penup();
turtle.goto(x + r, y);
turtle.pendown();
let steps = 40;
for (let i = 0; i <= steps; i++) {
let rad = i / steps * Math.PI * 2;
turtle.goto(
x + Math.cos(rad) * r,
y + Math.sin(rad) * r
);
}
turtle.penup();
}
// --- GRID SYSTEM ---
function walk(i) {
let cols = 15;
let rows = 15;
let total = cols * rows;
if (i >= total) return false;
let col = i % cols;
let row = Math.floor(i / cols);
// base grid position
//let x = -90 + col * spacing;
//let y = -90 + row * spacing;
let x = (col - (cols - 1) / 2) * spacing;
let y = (row - (rows - 1) / 2) * spacing;
// --- POSITION NOISE (increases downward) ---
let noiseScale = row / rows;
let nx = (Math.random() - 0.5) * offset * noiseScale;
let ny = (Math.random() - 0.5) * offset * noiseScale;
x += nx;
y += ny;
// --- ROTATION ---
let rot = (row + col) * rotationFactor;
// --- SCALE (optional but nice) ---
let s = size + row * 0.3;
// --- ALTERNATE SHAPES ---
if ((row + col) % 2 == 0) {
triangle(x, y, s, rot);
} else {
circle(x, y, s);
}
return true;
}