Alexander Deplov

Hexagons

Hexagons

Code

var group = new Group()
var degress = [60, 120]

function createHexagon(x, y) {
    var triangle = new Path.RegularPolygon({
        center: [x * 60, y * 69],
        sides: 6,
        radius: 40,
        strokeColor: 'black',
        rotation: 90,
        opacity: 0.8
    })
    var rect = new Path.Rectangle({
        size: [20, 40],
        strokeColor: 'black'
    })
    if (x % 2 == 0) {
        triangle.position.y += 35
    }
    rect.position = triangle.position
    rect.rotation = degress[Math.floor(Math.random() * degress.length)]
    group.addChild(triangle)
    group.addChild(rect)
}
for (var x = 0; x < 10; x++) {
    for (var y = 0; y < 10; y++) {
        createHexagon(x, y)
    }
}

function onFrame(event) {
    var tick = event.count / 120
    if (tick % 2 == 0) {
        for (i = 0; i < group.children.length; i++) {
            var path = group.children[i]
            path.rotation = degress[Math.floor(Math.random() * degress.length)]
            var tween = path.tweenTo({
                fillColor: Color.random(),
            }, {
                duration: 100 + Math.random() * 4000,
                easing: 'easeInCubic',
            })
            if (path.fillColor) path.fillColor.saturation = 0
        }
    }
}
group.position = view.center