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.


892 Comments


Sadhana
Sadhana
13 hours ago


Full Stack Development covers both front-end and back-end web engineering. Developers utilize HTML, CSS, JavaScript, and React to build responsive user interfaces, alongside Node.js, Express, and databases for server-side architecture. Linking these layers with APIs enables the creation of complete, scalable web applications. As an educational path, a Full Stack Developer Course in Chennai focuses on teaching these dual environments to help student developers build full-stack technical competencies.

Like

Pally Rabbert
Pally Rabbert
15 hours ago

Great post. I really enjoyed reading this article and found the information extremely useful and well organized.


Oscorm is the best freelance marketplace for connecting businesses with skilled professionals. It offers a secure, easy-to-use platform where clients can find top talent and freelancers can discover quality projects, making collaboration simple, efficient, and reliable.


Thank you for writing such a post. I really like that you shared this with us. I will look forward to reading more of your articles.

Like

Johana Lurtes
Johana Lurtes
15 hours ago

Entering an interview with a submissive posture leaves you vulnerable to misaligned organizational structures and unstated performance metrics. To avoid these traps, high-stakes candidates must adopt a consultant mindset, actively auditing a potential employer's operational health before signing an offer sheet. Navigating these critical final minutes requires a tactical shift toward a reverse interview, where strategic job interview questions act as a diagnostic framework to vet the company's internal health.


Like

John V. Brown
John V. Brown
15 hours ago

Great tutorial! It’s fascinating to see how creativity and technology come together to create unique kinetic generative art. Exploring new forms of design can inspire people in many ways. In the same spirit, finding good Halloween costumes allows people to express their creativity and bring imaginative ideas to life. Thanks for sharing!

Like

Prachi Singh
Prachi Singh
16 hours ago

Great article! It's exciting to see the growing innovation ecosystem in the capital. The top hackathons in Delhi provide excellent opportunities for students, developers, startups, and professionals to collaborate, solve real-world challenges, and connect with industry experts. These events are a great way to gain practical experience, expand your network, and showcase your skills.

Like

©2023 by Generative Hut.

bottom of page