Kinetic Generative Art Tutorial
- Pierre Paslier

- Jun 3, 2023
- 2 min read
Tutorial Intro
Welcome to this tutorial where we're going to explore the mesmerizing world of generative art, inspired by the kinetic sculptures of artists like Reuben Margolin. We'll use p5.js, a powerful JavaScript library that makes coding visual and interactive elements on the web accessible to everyone.
Our goal is to create a digital artwork with a series of rotating pendulums, each varying in speed and size, to simulate the motion seen in kinetic sculptures. The final result is a beautiful, ever-changing pattern that reflects the dynamic essence of kinetic art.
This tutorial is beginner-friendly, so don't worry if you're new to p5.js or programming in general. We'll walk through each line of code step by step, explaining the concepts as we go along.
By the end of this tutorial, not only will you have created a piece of generative art, but you will also have gained a deeper understanding of loops, arrays, and object-oriented programming in p5.js. You'll be equipped with the knowledge to create your own unique generative artworks. So, let's dive in and start coding!
Generative Art Code
let pendulums = [];
let pendulumCount = 40;
function setup() {
createCanvas(windowWidth, windowHeight);
for(let i = 0; i < pendulumCount; i++){
pendulums[i] = new Pendulum(i);
}
}
function draw() {
blendMode(NORMAL);
background(255 );
translate(width / 2, height / 2);
for(let i = 0; i < pendulumCount; i++){
pendulums[i].display();
pendulums[i].update();
}
}
class Pendulum {
constructor(n){
this.angle = 0;
this.angleSpeed = 0.01 + n * 0.004;
this.radius = 30 + n * 6;
}
update() {
this.angle += this.angleSpeed;
}
display(){
let x = this.radius * cos(this.angle);
let y = this.radius * sin(this.angle);
stroke(0,100);
line(0, 0, x, y);
fill(0);
ellipse(x, y, 5, 5);
}
}That's it! Hope you've enjoyed learning about this particular piece and make sure to check out the other free tutorials on generativehut.com.



luckywin mình thấy bạn bè nhắc hoài nên cũng bấm vào coi thử cho biết chứ không chơi gì. Lướt một vòng thấy trang làm khá dễ nhìn, kiểu chia khối nội dung rõ nên kéo xuống không bị rối mắt, đọc nhanh vẫn biết mình đang ở phần nào. Có đoạn giới thiệu họ ghi luôn mấy thứ như mã hóa SSL 256-bit với xác thực OTP, nhìn vậy cũng yên tâm hơn vì họ để thông tin ngay trên mặt trang chứ không giấu ở đâu. Mình thích cái menu đặt khá nổi, bấm qua lại mấy mục như hướng dẫn với FAQ cũng mượt, tiêu đề từng cụm được làm nổi nên nhìn phát là nhận ra…
hitclub hôm trước mình lướt thấy người ta bàn tán nên ghé thử cho biết, kiểu xem giao diện với cách trình bày thôi chứ mình cũng không rành mấy trò. Vào trang cái là thấy họ chia nội dung theo từng khối khá gọn, kéo xuống tới đâu biết mình đang đọc phần nào tới đó, không bị loạn chữ. Mình để ý họ có nhắc vụ nạp rút nhanh tầm 1–3 phút, thông tin này đặt ngay trong phần nội dung chính nên không phải mò. Mà nhìn chung font với tiêu đề dễ đọc, khoảng cách thoáng nên đọc trên điện thoại cũng ổn. Mấy box thông tin được tách riêng nhìn rõ, menu và các heading…
Student accommodation in Preston offers modern, fully furnished living spaces with excellent amenities, secure facilities, and convenient locations near university campuses. Designed for comfort and convenience, it provides students with a supportive environment that encourages academic success and an enjoyable student experience.
luongsontv mình lướt thử cho biết vì thấy bạn bè nhắc, kiểu vào xem giao diện có dễ dùng không thôi. Ấn tượng đầu là bố cục chia thành từng khối nhìn khá thoáng, nên mới vào cũng không bị ngợp hay phải đoán chỗ nào với chỗ nào. Mình cũng để ý cái menu đặt ngay chỗ dễ thấy, bấm qua lại mấy mục nhanh, không phải kéo lên kéo xuống tìm nút. Thông tin trên trang trình bày gọn gàng, nhìn lướt là bắt được ý chính chứ không bị dồn chữ kín màn hình. Nói chung cảm giác dùng nhẹ nhàng, nhất là đoạn điều hướng giữa các khối nội dung với menu nổi bật khá rõ…
A studio flat in Preston provides stylish, self-contained accommodation with a private kitchen, en-suite bathroom, and comfortable living space. Perfect for students and young professionals, it offers independence, convenience, and easy access to universities, local amenities, and transport links.