xxxxxxxxxx
62
let angles = [90, 45]
let p = [0, 0]
const length = 1
let x = 0
let y = 0
let rotation = 0
function setup() {
frameRate(10)
createCanvas(400, 400)
background(51)
fill(130)
noStroke()
angleMode(DEGREES)
}
function draw() {
translate(width/2, height/2)
hexagon(x, y, 20, rotation)
rotation += 1
// drawPoint(p, 10)
// let angle = average(angles)
// angles.push(angle)
// p = newPoint(p, angle, length)
}
function hexagon(cx, cy, length, rotation) {
push()
rotate(rotation)
for (let i = 0; i < 6; i++) {
angle = i * 360 / 6
let x = cx + length * cos(angle)
let y = cy + length * sin(angle)
circle(x, y, 5)
}
pop()
}
function drawPoint(p, size) {
let [x, y] = p
circle(x, y, size)
}
function newAngle(angles) {
let i = angles.length - 1
return (angles[i] + angles[i-1]) / 2
}
function average(a) {
let total = 0
for (let n of a) {
total += n
}
return total / a.length
}
function newPoint(p, angle, length) {
let [x, y] = p
let new_x = x + cos(angle) * length
let new_y = y + sin(angle) * length
return [new_x, new_y]
}