How to make amazing generative art with simple JavaScript code

    Rate this content
    Bookmark

    Instead of manually drawing each image like traditional art, generative artists write programs that are capable of producing a variety of results. In this workshop you will learn how to create incredible generative art using only a web browser and text editor. Starting with basic concepts and building towards advanced theory, we will cover everything you need to know.

    FAQ

    Generative art refers to art that in whole or in part has been created with the use of an autonomous system. An autonomous system in this context is generally one that can independently determine features of an artwork that would otherwise require decisions made directly by the artist.

    Generative art can be created by using algorithms and computers to generate artwork. This often involves programming and can include techniques like manipulating code to create visual effects, using mathematical formulas to generate patterns, or employing artificial intelligence to create complex designs.

    JavaScript and C++ are commonly used for creating generative art due to their flexibility and the extensive libraries available for creating graphics and animations.

    Yes, generative art can include interactive elements. Interaction can be facilitated through programming, allowing the artwork to change or evolve based on user inputs or environmental data.

    Common tools for creating generative art include p5.js, Processing, and various web-based editors like CodePen. These tools provide frameworks and libraries that simplify the process of coding and visualizing generatively created artworks.

    Using different hues and textures adds depth and complexity to generative art, enhancing visual appeal and creating more dynamic and engaging pieces. It allows artists to convey emotions, themes, and abstract concepts through visual variations.

    Frank Force
    Frank Force
    165 min
    12 Apr, 2022

    Comments

    Sign in or register to post your comment.

    Video Summary and Transcription

    The Workshop on Generative Art and JavaScript covers various topics, including drawing shapes, using the debugger and CSS styling, and exploring variables and colors. It also delves into creating fire effects, drawing lines and shapes, and working with oscillation and particles. The workshop emphasizes the importance of saving work, experimenting, and building up from the basics. It highlights the uses of generative art in different industries and draws inspiration from textiles and the real world. Overall, it provides a comprehensive overview of generative art techniques and their applications.

    1. Introduction to Generative Art and JavaScript

    Short description:

    Hi everybody, I'm Frank Forrest, a generative artist and also a game developer. I've been focusing on learning JavaScript for generative art. I'll show you a website called Twitter, where I post super tiny JavaScript programs. These programs are all generative art and you can experiment, remix ideas, and even edit the code. We'll be working towards creating similar generative art in this workshop.

    Hi everybody, I'm Frank Forrest, a generative artist and also a game developer and I guess a bunch of other stuff. But right now I'm mostly focused on generative art. And I've really been focusing on, especially this year, but even a couple years ago I started getting into learning JavaScript because I had been learning C++ for so long. So I'm not sure if you guys are familiar with the kind of stuff that I do. So I'm just going to give you a quick... show you quickly like what what I've been up to. What I've been up to.

    So, let me see if I can do that. You have to bear with me a little bit because I'm still... I haven't used Zoom that much. So I'm still kind of getting into the flow of things here. Okay, so I hope you can all see my screen now. So I'm showing you a website called Twitter, which is a website to post super tiny JavaScript programs. All these programs are only 140 characters and they're all generative art programs. And I think it's a really great website to experiment and play around with different ideas and see what other people come up with and remix ideas. Like a lot of these are kind of remixes of other people's stuff. But if I... This is not the actual website by the way. This is a website that I made to make it a little bit faster to browse through these things.

    So I've done over a thousand of these. I have covered pretty much every possible top egg you can imagine. I'll sort by my most popular ones. Anything from like a landscape type of thing. This is all generative art and this is the kind of stuff you'll be learning in this workshop. These are all very, very tiny programs. I want to emphasize this here. You can see the code is literally right there on the screen. So if I was to, for example, go to one of these, now you can actually see the code right here and you can even edit the code. This is the kind of thing I'm going to be showing you. We're going to work towards this. So don't I don't expect you to understand exactly what's going on right here. So for example, I could poke these numbers to change kind of what the colors are. Make it more green, or maybe make it more blue or whatever. So this is kind of how I would be maybe tweaking what's going on with this generative art. I can make these instead of bigger square, I can make them like tiny squares, or I could put like a whole lot more of them, maybe. Or whatever. That's what we're going to play around with today.

    2. Creating an HTML File and Drawing Shapes

    Short description:

    We're going to start by creating a new HTML file. I'll show you how to draw a square using the fill rect function. Then I'll show you how to apply color to the shape using HTML color names or hex codes. Now, Chris, you can draw more rectangles if you want.

    So I see a few people have the camera on. So I just want to say hi to Luz and Gleb. Thank you. You know, I don't want to feel like anyone to be obligated to put their camera on. Bartosz, thanks. You know, just feel chill. Do whatever is most comfortable for you. Though it will help me if you feel like you want to share your screen if you're working on something. Because where you're going to be, maybe remixing some of each other's work, I think that would be kind of fun.

    So let's start totally from scratch. We're going to start by just creating a new text file, a new HTML file. So you can do this. You don't need any type of special program. You're just going to right-click. You're going to create a new file. I'm going to call it index.html. You can call it whatever you want. Index.html is kind of like the standard name that's used for HTML files because it will automatically get opened if you go to that folder. So now we have an HTML file. It's an empty file. So I'm going to open up notepad. Now I have notepad++, but I'm just going to use regular notepad here. I'm going to drag it right in there. Now, nothing's in there. So we want to create an HTML file from scratch. And now the thing is, there's a lot of complicated stuff with HTML. And I'm not going to be teaching any of that. I'm just going to go straight into the minimal amount of HTML that you need in order to create generative art. So let's get into it. We got our HTML file here on one side. On the other side, I'm going to open up a web browser. And what I can do is drag the HTML file into the web browser. So now I have a one-to-one. I've HTML on the left, and I have the web browser on the right. So if I was to just type some letters into here, save it, and go over to my web browser and reload it, you'll see that those letters show up in my web browser. Because an HTML file, really is very flexible. And it will automatically open as a text file or whatever you need.

    So let's create a canvas because you don't need a canvas for generative art. You can create generative art with anything you can imagine. But most generative art does use a canvas style drawing system. So in order to create a canvas, it's really that simple, we've just created a canvas. Now we need JavaScript code in order to operate on that canvas. So in order to do that, we create a script block, where do script and use angle bracket tags, and we do a slash script to end the block. Now we've got our our block set up here. And we want to be able to draw to that canvas. So we need to get a 2D context, which is, I'm just going to store it into a variable. I'll talk a little bit more about variables, but we'll store it to a variable, we're going to do X equals C, which is the canvas, when I do IDC, that automatic creates a variable for the canvas. So we're going to do X equals C dot, get context. That's going to give us our 2D context for the canvas. And JavaScript is so flexible, you should end lines on semicolon, because you might rarely have something happen that's not supposed to if you don't do that, but you don't really need semicolons.

    Now I have access to our context. So I'm going to show you how to draw a square, a rect. There's a function called fill rect. And these functions may seem very simple to you. Like how am I supposed to make amazing art with just a fill rect. But really, these are the building blocks. Like at the fundamental level, you will be calling fill rect. And a lot, most of my art uses fill rect or like these simple commands, because at the lowest level, that's really what it comes down to. So fill rect has four parameters, that's just the X and the Y position and the width and the height. So if I say, 100, 100 and then 500 and then 100, so we're going to get a rectangle that's hopefully pretty wide, a little off the side. Now I'm going to hit F5. That's a rectangle. So hopefully everybody has been able to follow so far of how to create a text file, an HTML file that has drawing a shape in it. So this is the very most basic thing. Now, let me show you how to apply color to that shape. Again, we're operating on this object called x. So we've stored our context2d, which is kind of our interface for drawing and stuff to this specific canvas. And it's stored in the variable called x. So I'll do x.DillStyle. Equals read, the word red. And then go over here at 5. They should have a red rectangle, right? So usually, though, you're not going to use names of colors. So this is just supported by HTML. There's a lot of names of colors. Another way to do it is with, if you've ever seen these hex codes. So you would use a hash symbol. And then there, you can either do 6 or 4 or 3 numbers. I usually just use 3. So that's going to be the red, green, and blue components. So if you do F, that would be four red. 0, 0. Let's do them. Let's do a green. So it would be 0 red, full green, and 0 blue. So we've got that. Now, Chris, you can draw more rectangles if you want. So we got one green. I'm just going to copy and paste. And this is not case-sensitive, at least for this part of it, for the color part of it. So I'll do a red rectangle.

    Watch more workshops on topic

    Make a Game With PlayCanvas in 2 Hours
    JSNation 2023JSNation 2023
    116 min
    Make a Game With PlayCanvas in 2 Hours
    Top Content
    Featured WorkshopFree
    Steven Yau
    Steven Yau
    In this workshop, we’ll build a game using the PlayCanvas WebGL engine from start to finish. From development to publishing, we’ll cover the most crucial features such as scripting, UI creation and much more.
    Table of the content:- Introduction- Intro to PlayCanvas- What we will be building- Adding a character model and animation- Making the character move with scripts- 'Fake' running- Adding obstacles- Detecting collisions- Adding a score counter- Game over and restarting- Wrap up!- Questions
    Workshop levelFamiliarity with game engines and game development aspects is recommended, but not required.
    Introduction to WebXR with Babylon.js
    JS GameDev Summit 2022JS GameDev Summit 2022
    86 min
    Introduction to WebXR with Babylon.js
    Workshop
    Gustavo Cordido
    Gustavo Cordido
    In this workshop, we'll introduce you to the core concepts of building Mixed Reality experiences with WebXR and Balon.js.
    You'll learn the following:- How to add 3D mesh objects and buttons to a scene- How to use procedural textures- How to add actions to objects- How to take advantage of the default Cross Reality (XR) experience- How to add physics to a scene
    For the first project in this workshop, you'll create an interactive Mixed Reality experience that'll display basketball player stats to fans and coaches. For the second project in this workshop, you'll create a voice activated WebXR app using Balon.js and Azure Speech-to-Text. You'll then deploy the web app using Static Website Hosting provided Azure Blob Storage.

    Check out more articles and videos

    We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

    The Whimsical Potential of JavaScript Frameworks
    React Summit US 2023React Summit US 2023
    28 min
    The Whimsical Potential of JavaScript Frameworks
    Top Content
    When it comes to building whimsical interfaces, React is a surprisingly capable ally. In this talk, I'll show you how I use React to orchestrate complex interactions by digging into some examples from my blog.
    Emotional & Functional UI Animations in React
    React Day Berlin 2022React Day Berlin 2022
    28 min
    Emotional & Functional UI Animations in React
    Boost the Performance of Your WebGL Unity Games!
    JS GameDev Summit 2023JS GameDev Summit 2023
    7 min
    Boost the Performance of Your WebGL Unity Games!
    Unity, when deployed on the web, faces three critical challenges: build size, memory usage, and overall performance. This lecture delves deep into advanced optimization techniques to help you address each of these issues. Attendees will gain insights into:
    - Effective strategies for optimizing textures, audio, and models.- A detailed analysis of our ASTC experimentation with Unity, shedding light on the unexpected results despite Unity's claims.- A comprehensive guide to Unity's memory profiling tool and its implications.- An exploration of lesser-known Unity settings that remain underutilized by many developers.
    Additionally, we'll introduce our proprietary tool designed specifically for Unity optimization. We will also showcase CrazyGames' developer dashboard, our platform that enables developers to monitor and enhance the performance of their web-based games seamlessly. 
    Join us to equip yourself with the latest strategies and tools to elevate your Unity web gaming projects.
    TresJS, a declarative way of creating 3D scenes from Vue components
    Vue.js London 2023Vue.js London 2023
    27 min
    TresJS, a declarative way of creating 3D scenes from Vue components
    Meet TresJS ▲ ■ ●, a declarative way of bringing the magic of ThreeJS using everyday Vue Components and composables. Think of it as React-three-fiber or Lunchbox but without the need of a custom renderer. It just works.Are you ready to add a new dimension to your Vue Apps?
    Unreal Engine in WebAssembly/WebGPU
    JS GameDev Summit 2022JS GameDev Summit 2022
    33 min
    Unreal Engine in WebAssembly/WebGPU
    Top Content
    Traditionally, browser games haven't been taken seriously. If you want to target the web, that traditionally has meant compromising on your vision as a game developer. Our team at Wonder Interactive is on a mission to change that, bringing one of the world's premiere native game engines to the browser - Unreal Engine. In our talk, we'll dive into our efforts porting the engine to the browser and carrying on the pioneering unfinished work started at Epic Games nearly a decade ago in collaboration with Mozilla. We'll dive into what this means for the future of games in the browser, and the open metaverse on the web.
    From Blender to the Web - the Journey of a 3D Model
    React Advanced Conference 2021React Advanced Conference 2021
    27 min
    From Blender to the Web - the Journey of a 3D Model
    Top Content
    Creating 3D experiences in the web can be something that sounds very daunting. I'm here to remove this idea from your mind and show you that the 3D world is for everyone. For that we will get a model from the 3D software Blender into the web packed with animations, accessibility controls and optimised for web use so join me in this journey as we make the web more awesome.