top of page

Kinetic Generative Art Tutorial

  • Writer: Pierre Paslier
    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.


837 Comments


nolafo.wle156+abc123
34 minutes ago

BALL88 hôm bữa mình ghé thử cho biết vì thấy mọi người nói nhiều, kiểu vào xem giao diện trước đã chứ chưa đặt gì mấy. Cảm giác đầu tiên là trang nhìn khá gọn, chữ nghĩa và các khối thông tin chia ra rõ nên không bị rối mắt. Mình có nghía qua mục cược trực tiếp (In-Play) thì thấy phần kèo hiển thị khá trực quan, nhìn lướt là hiểu đang có gì chứ không phải ngồi đọc dài dòng. Mấy thao tác chuyển mục cũng mượt, bấm qua lại không bị lạc, nhất là trên điện thoại vẫn dễ theo dõi. Nói chung mình thích kiểu họ trình bày kèo theo dạng bảng khối rõ ràng, nhìn…

Like

airlinesdeskinfo1
airlinesdeskinfo1
2 hours ago

Turkish airlines office in los angeles in Southern California is a reflection of the airline's worldwide reputation for quality, ease of use, and passenger happiness. The group is dedicated to provide flawless travel solutions, making sure that each client gets prompt, courteous service. Passengers seeking dependable assistance and a seamless travel experience continue to choose the Turkish Airlines Office in Los Angeles because to its commitment to excellent support, travel expertise, and customer care.

Like

David Miller
David Miller
21 hours ago

Great tutorial! I really enjoyed reading this guide and learning more about the creative possibilities of generative art. The way the concepts were explained makes the topic approachable while still providing valuable insights for artists and designers. It's fascinating how unique ideas can evolve into memorable visual experiences through experimentation and creativity. The same appreciation for originality can be seen in iconic cultural designs such as the David Byrnes Big Suit, which continues to inspire people through its distinctive and unconventional style. Thanks for sharing such an informative and engaging article.

Like

billy24barne.s7.8.3.5
a day ago

thapcamtv dạo này mình thấy có người nhắc tới khi nói về các nền tảng giải trí trực tuyến nên cũng thử mở vào xem cách họ bố trí giao diện ra sao. Mình không đi sâu vào nội dung hay từng trò cụ thể, mà chủ yếu quan sát cách các chuyên mục được phân chia trên trang và cách thông tin hiển thị cho người dùng. Nhìn tổng thể thì các khu như thể thao, casino, game bài hay slot thường được sắp xếp theo từng nhóm khá rõ, hiển thị dạng khối và danh sách nên lướt qua cũng dễ theo dõi. Các bảng dữ liệu được trình bày dạng cột khá gọn, giúp quan sát nhanh…

Like

savannapatt.er.s.on.7.0.4
2 days ago

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…

Like

©2023 by Generative Hut.

bottom of page