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.
𝙺𝚑𝚎𝚕𝚛𝚊𝚓𝚊 𝚒𝚜 𝚊 𝚕𝚎𝚊𝚍𝚒𝚗𝚐 𝚘𝚗𝚕𝚒𝚗𝚎 𝚐𝚊𝚖𝚒𝚗𝚐 𝚙𝚕𝚊𝚝𝚏𝚘𝚛𝚖 𝚝𝚑𝚊𝚝 𝚍𝚎𝚕𝚒𝚟𝚎𝚛𝚜 𝚝𝚑𝚛𝚒𝚕𝚕𝚒𝚗𝚐 𝚎𝚗𝚝𝚎𝚛𝚝𝚊𝚒𝚗𝚖𝚎𝚗𝚝 𝚝𝚑𝚛𝚘𝚞𝚐𝚑 𝚘𝚗𝚕𝚒𝚗𝚎 𝚌𝚊𝚜𝚒𝚗𝚘, 𝚋𝚎𝚝𝚝𝚒𝚗𝚐, 𝚊𝚗𝚍 𝚕𝚘𝚝𝚝𝚎𝚛𝚢 𝚐𝚊𝚖𝚎𝚜. 𝙰𝚖𝚘𝚗𝚐 𝚒𝚝𝚜 𝚠𝚒𝚍𝚎 𝚟𝚊𝚛𝚒𝚎𝚝𝚢 𝚘𝚏 𝚘𝚏𝚏𝚎𝚛𝚒𝚗𝚐𝚜, 𝚃𝚎𝚎𝚗 𝙿𝚊𝚝𝚝𝚒 𝙿𝚘𝚔𝚎𝚛 𝚜𝚝𝚊𝚗𝚍𝚜 𝚘𝚞𝚝 𝚊𝚜 𝚊 𝚙𝚕𝚊𝚢𝚎𝚛 𝚏𝚊𝚟𝚘𝚛𝚒𝚝𝚎, 𝚋𝚕𝚎𝚗𝚍𝚒𝚗𝚐 𝚜𝚔𝚒𝚕𝚕, 𝚜𝚝𝚛𝚊𝚝𝚎𝚐𝚢, 𝚊𝚗𝚍 𝚎𝚡𝚌𝚒𝚝𝚎𝚖𝚎𝚗𝚝. 𝙺𝚑𝚎𝚕𝚛𝚊𝚓𝚊 𝚙𝚛𝚘𝚟𝚒𝚍𝚎𝚜 𝚊 𝚜𝚎𝚊𝚖𝚕𝚎𝚜𝚜, 𝚜𝚎𝚌𝚞𝚛𝚎, 𝚊𝚗𝚍 𝚒𝚖𝚖𝚎𝚛𝚜𝚒𝚟𝚎 𝚐𝚊𝚖𝚒𝚗𝚐 𝚎𝚗𝚟𝚒𝚛𝚘𝚗𝚖𝚎𝚗𝚝 𝚠𝚑𝚎𝚛𝚎 𝚞𝚜𝚎𝚛𝚜 𝚌𝚊𝚗 𝚎𝚗𝚓𝚘𝚢 𝚛𝚎𝚊𝚕-𝚝𝚒𝚖𝚎 𝚙𝚕𝚊𝚢, 𝚌𝚘𝚖𝚙𝚎𝚝𝚒𝚝𝚒𝚟𝚎 𝚌𝚑𝚊𝚕𝚕𝚎𝚗𝚐𝚎𝚜, 𝚊𝚗𝚍 𝚛𝚎𝚠𝚊𝚛𝚍𝚒𝚗𝚐 𝚙𝚛𝚘𝚖𝚘𝚝𝚒𝚘𝚗𝚜.
Cheap Airhostess Escorts in Delhi – Your Dream Fantasy Comes Alive
When it comes to living out your wildest dreams, nothing compares to the charm, elegance, and professionalism of Cheap airhostess escorts in Delhi. These stunning companions bring sophistication, style, and an adventurous spirit to every encounter. For those seeking intimacy without breaking the bank, the market is now filled with Affordable airhostess escorts Delhi who deliver unforgettable experiences at prices that suit every budget.
Whether you’re in the city for business, leisure, or a spontaneous escape, Delhi cheap airhostess call girls offer a unique blend of beauty and personality. These companions often have a background in the aviation industry, which means they are well-traveled, culturally aware, and know exactly how to make a man…
Are you planning to fly with Qantas from Georgia? Whether you book a new flight, change the dates of your trip or ask for a refund, Qantas Airways Booking Phone Number Georgia Airport saving you quick access to Georgia Airport.
Thanks for this wonderful piece! It reminded me how special it is to send a virgo birthday card that speaks to someone’s unique astrological traits.
Insightful content highlighting how targeted therapies and gene treatments are transforming patient outcomes.
Explore: www.delveinsight.com