Published
Edited
Apr 19, 2020
Insert cell
md`# SuperHi - Creative Coding - Project 2`
Insert cell
Two = require("two.js")

Insert cell
animation = {
const elem = html`<div>`;
elem.style.backgroundColor = "#ffe8b4";

const params = {
width: 500,
height: 500,
autostart: true
}

const two = new Two(params).appendTo(elem);

const numberOfShapes = 12;
const plotRadius = 150;

const shapes = [];

const fullRotation = Math.PI * 2;

for (let i = 0; i < numberOfShapes; i++) {
const angle = (fullRotation * i) / numberOfShapes;

const x = plotRadius * Math.cos(angle);
const y = plotRadius * Math.sin(angle);

const shape = two.makeRectangle(x, y, 50, 50);
shape.noStroke();
var gradLinA = two.makeLinearGradient(
-100,
50,
100,
-50,
new Two.Stop(0, "#f9bc31", 1),
new Two.Stop(1, "red", 1),
);
shape.fill = gradLinA;
shape.rotation = angle;

shapes.push(shape);
}

const group = two.makeGroup(shapes);
group.translation.set(250,250);

let scaler = 1;
let scaling = "grow";
two.bind('update', function() {
group.rotation += 0.005;
if (scaling === "grow"){
scaler += 0.005;
}
if (scaling === "shrink"){
scaler -= 0.005;
}
if (scaler > 3){
scaling = "shrink";
}
if (scaler <0.5){
scaling = "grow";
}

shapes.forEach(shape => {
shape.rotation += 0.025;
shape.scale = scaler;
})
})
return elem;

}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more