 We have Niraj Pandey. I hope I pronounced your name correctly. That's correct. He's a student at Ashoka University and he's studying computer science. He's interested in generative arts, software development and quantitative finance. And he's going to talk about creating art with code. So how to use algorithms to create very nice looking things, I suppose. Well, this is going to be exciting. So let's see what you have to present. By the way, where are you joining from? I'm joining from India. And where in India? New Delhi. Ah, right. Nice. Very nice. How's the weather in New Delhi? What time is it now? It's pretty good. It's 2.30 p.m. in the afternoon. Good. Well, comfortable time, right. Excellent. So let's start the screen sharing and then you can go ahead and give the talk. Shall I start the screen? Yes, please. Okay, so the talk is the joy of creating art with code and I'm neither hi everyone. And a little bit about myself. Currently a sophomore student at Ashoka University and my interest lies in software development, generative art, distributed computing and quantitative finance. So these are the points for discussion of the talk. So we'll be talking about generative art. The history behind generative art. We'll see a quick overthrow of how processing that pie mode works. And then we'll see how we can use the geometry algorithms and randomness that frames our generative art. And we'll be seeing some quick examples using processing that pie. So the main objective or the main goal of that stock is to look at Python as an artistic tool with the simplicity of generative art. Using processing and pie title. So what is a generative art? So an art created through the use of an autonomous system is simply generative art. That's the simplest definition you will see. So it uses iterative commands to draw vector based shapes on the screen and most of the art created draws inspiration from modern art and especially the pop art. And usually an autonomous system is required because without it it will mostly be a digital art and randomness can be one form of that autonomous system. So before we go forward, so let's see how all this came from. So when you talk about the analog art, which is the art which is manipulated by hand, the complexity and scale requires exponentially more effort and time. And when you talk about computers, they excel at repeating processes for like endlessly without exhaustion. As you will see, the ease at which we, computers can create these art forms contributes greatly to the aesthetic of generative art. In the past, one major challenge which was faced by the early generative artists was the limitation of an output device. So the primary source of that time was using a plotter, which is a mechanical device holding a pen whose movements were controlled by the instructions that were programmed into the computer. And one of the first artists to produce a plotter color drawing was Freda Nick and the painting, the art has been shown on the screen. It's called homage. And this is one of the earliest best known pieces of generative art. It's called Scotter by George Neese and Scotter starts with a standard 12 by 12 rows and it increases in magnitude as we go like down the road and it changes the rotation, the magnitude of location change. So generative art is one of the best option and you're working on similar art places because maybe you want to create a similar art piece using your hand on a pen and paper. And it might take you hours to produce one. So instead you can just input some simple commands from the computer and you can create thousands of such art pieces in a couple of minutes. So after the creation of processing, it became much, much easier for artists and creators to design and make computer art. So it was created by Ben Fry and K series who worked on the processing foundation from the last like 19, 20 years now. And processing is programming language and environment built with media art communities, you can say it's created to teach individuals the intro of programming within the media arts context and so as a software schedule. And okay. So the examples you'll be seeing in this talk will be using Python mode and processing mostly. So it's a good practice to quickly get an overview of how processing mode actually works with Python. So this is exactly how of any function will look like in processing, in Python mode in processing. So we have two major functions. One is a setup and the other is a draw. And the setup function is basically it runs once the program is executed and mostly the methods which are called inside the setup function are the creating the size of the canvas, adding a background color and maybe adding noise, adding some blur effects, et cetera. And the draw function runs until the program is stopped. So which means it is running in loops. So each statement is executed in sequence. As you can see, if you don't want the draw function to run again and again, you can simply use no loop. And otherwise, after the last line is executed, the first line will be executed back again. And if you run this program, you'll simply get a black canvas with a small ellipse or a circle on the screen or the canvas. So most of the art pieces are using mathematical functions like noise, trigonometry, filter methods like blur, and use various algorithms such as L systems, pixel mapping, Poisson dis-sampling, et cetera. So we'll be discussing a few in this slides and see how we can incorporate all these mathematical functions and algorithms and create some simpler static art pieces. Okay, so we have the random function, which is like one of the most important functions which artists use pretty often. So the use case is pretty simple. It just provides you with a random floating point number between zero and one. And random function differs in different programming languages. So it's not like going to be the same, how we are going to be using in processing. So in processing, random function is used by directly calling random and it returns a random floating point between zero and one. And if you want a random number between a range, it will be, you have to provide a min and max range. And if you're not using processing, if you're using some other environment like PyKyro, you can simply use the random module, which is available in Python. Okay, so before we move forward and start exploring art pieces that uses vector operations, shapes and the method, we should understand how exactly a artist canvas looks like when you're working on a generative art. So, okay, so the canvas is like a 2D Cartesian plane, where each point can be considered as a vector, which is a vector in a 2D Cartesian plane. That's basically the distance between two points. So as you can see on the right-hand side, we have a Cartesian plane and each point is denoted by X comma Y, which basically stores the information on how to get to that point from the previous point or here we're using origin. And we can further use operations or linear algebra operations like linear transformation, rotation, to add some instructions to the vectors. And creating a point and a line is again pretty straightforward. So if you want to go through all these again, so you can directly go to the processing official documentation and all these stuff is already being mentioned there. So I'll just quickly go through it. So a point can be created by passing an X, Y coordinate and the processing will add a point to that pixel position in the canvas. And if you want a line, you can simply add the coordinates of those two points, X1 comma Y1, X2 comma Y2 and the processing will add a line between two points. And if you want to change the thickness, you can use stroke weight. And if you want to change the color, you can add the color by using stroke. And similarly, if you're working with PyKyro, you can use set line width, which is a substitute of stroke weight. And similarly, you can create a line by using line two and other functions. And these are the very basic examples of how you can use those straight lines and points on the canvas to create some very simple art pieces. It's like on the left-hand side, there are vertical lines of different length and opacity, and they're using some points of random points with various variable opacity. And on the right-hand side, we have just lines, but they're using a lot set of colors pallets and I'll randomly using those to fill the stroke fill. And the next is, okay. So this is a very important function and we use it pretty often. It's called Curve Vertex and Bezier Curves. So Curve Vertex is an implementation of catmolorm spline, which is a type of interpolating spline. That is, it basically goes through the points in processing. It specifies the vector coordinates for curves. So this function can be called in between, can only be called in between begin shape and end shape method so that it can create some sort of stroke curves. And these functions allow creating complex forms on our Cartesian plane. And on the other hand, we have Bezier Curve, which is a versatile mathematical curve in vector graphics. Basically these are the vector graphics that could be scaled indefinitely and has a series of anchor points and control points. So for Bezier Curve, you need at least three points which is the initial point, the final point and one control point or the anchor point. And you can simply call Bezier by providing the three-point coordinate and it will create a Bezier Curve on the scandals. And similarly, you can use Curve 2 to create a curve on the canvas if you're using PyKidl, which draws a curve from the point A to D and it has B and C as the anchor points. So this is how curves of variable opacity and lens look like when we let the draw function run for a number of time. And to implement this, what we are doing here is we are basically inside the canvas, we are creating a follow from, which is going from zero to three, so zero to four. So we are creating four points here. So we have X and Y array initialized and on line 17 and 18, we are adding the noise value. So for now, I'm not going to tell you what exactly is noise. So for now, you can think of it as a random number, generating function. So once we have those X and Y values, we are like incrementing the M and N factors and once we are done with the loop, we are creating a Bezier Curve with all those four values and we are increasing the offset values so that once the draw function is done with one loop, it should the next Bezier Curve should not be formed on the same position. There should be a distance in between and when we let it run for some time, you get some like cool looking curves and all these things. Similarly, there is another inbuilt function in processing which is curve vertex and it's like we need at least four points to create a simple curve on the screen and you can call this function by simply calling curve vertex and providing the point coordinates X and Y. And here what we're doing like on line 13, we are calling the curve vertex and we are going from top left of the canvas to the bottom right and we are adding, we are also using on line 15 no loop which means we just want the draw function to execute once and on line 13 we are using curve vertex which is taking the I and J index of the loops and we are adding the random value between minus 10 and 10 to those I and J index and but if we would have run the program with a single curve vertex function we would have got just a single point on the canvas but we want some curves so we added four, five, six, I think six more points. So when we run this program we get these scribble type effects on the canvas and if you let like add more points it will make more like curves and if you let the function run run for more number of times by using frame count check then it might cover entire screen and the next is okay so we can also create some basic shapes like ellipse, rectangles and squares and in the further videos we'll see how we can implement them actually to create art pieces so ellipses can be created by providing four parameters which is AB stands for the X and Y coordinates and C and D are basically the width and height and a rectangle takes four required parameters which is A and B again the X, Y coordinates and C and D are the width and the height and other four variables are basically the border radius of the rectangle and square takes X and Y coordinates and the side length of the square similarly we can create the same shapes in PyCycle. Okay so one best example is by creating some art pieces which were already being created by artists so this is an art piece called composition two in red, blue and yellow it was created by Piet Mondrian so this is not the actual painting this is like created randomly with random fills and random shapes but it looks similar it's using just rectangles and stroke colors and on the right hand side it's the same sketch that we created on the left side but instead of creating a single sketch on the canvas we are adding multiple rectangles and this is one simple example where we can just use rectangles this is very simple and using just rectangles and some random color fill we can create some cool looking sketch so to create this what we are doing is like we are going from top to bottom of the canvas and at each index we are dividing the width of the canvas by a random midpoint and then we are creating a rectangle from the initial position to that midpoint and from that midpoint to the final one so once we are done creating rectangles we are filling them with a random color between 0 and 255 so it can be a shade of black to white so once we run the function we get something like this on the left hand side and on the right hand side instead of using just random colors we are also using a color palette and then we are choosing colors from there and okay linear interpolation so the ler function or the linear interpolation function is very convenient for creating motion along the straight path and for drawing dotted lines so it basically calculates the number between two numbers at a specific increment or the specific increment of time so the amt or the amount parameter is the amount to interpolate between the two values and we can say the zero value will be the first value zero point will be the immediate next value and so on so to understand the linear interpolation in a better way we can think of something like a gradient fill in the canvas so this isn't very easy to use in build function in processing called ler color so what we are doing here is we are going from left to right of the canvas and we are adding a variable linear int value which is basically mapping the value of index i to zero and one because we want the int value to be very small between zero and one just like the noise value and then we are using this linear int value to add a color fill so we are using the color fill as linear int color which is basically using the lerp color function and this lerp color function is taking the initial value of the color and the final color value and it's adding the specific increment of unit point that we created above line number 11 and once we have this color fill we are just filling the rectangle we are creating and once we let the function run we get this smooth gradient fill on the canvas and okay so by now we talked a lot about how we can use random numbers or random generated stuff to create these art pieces so unlike random numbers generated that has no relationship between the previous number generated and the next number like we saw in the previous slides with me draw random points and the graph was pretty much like zigzag in a zigzag form and here instead of that the graphs lines are pretty much smooth so in Perlin noise the numbers generated are pretty much close to each other and has a relationship with each other and it's more organic in nature and that's because these numbers generated are naturally ordered sequence of pseudo random numbers so what it means is we can see here okay after this so implementing a noise like generating a noise number is pretty straightforward like just like random we just pass the XYZ coordinate or if you're working on XY coordinate system then just use noise and pass the coordinates value and it returns some Perlin noise at that value and sometimes we want that noise value to be constant whenever the draw function runs again and again so we can just fix the noise value to a constant value by using noise seed and similarly if you're not using processing you can use the noise module in Python for PyCard and other environments okay we can see this example to understand noise in a better way so what we're doing here is we are loading all the pixels from the image and what we're doing is like if you add a variable initialize a variable R and you're trying using it to fill all those pixel back so you're creating a variable R so basically we're looping from top left of the canvas and to the top bottom right so we're covering all the pixel values and at each index we are creating a variable R which is generating a noise value at X offset and Y offset and there's noise value is between 0 and 1 only so this value is pretty small with a color value we want a color to be between 0 and 255 to maintain the RGB index so we're basically multiplying it by 255 so that we get a color shade between black and white and not just black and once we have all these values we are updating the pixel index with this color and eventually we are updating all the pixels and once we run this function you get this cloud like effect so basically this is just like small small points with noise values all the values pixel values are pretty much close to each other so that the noise values are close to each other and to understand this for like in a better way we can say if we have a canvas and if we have two points on the canvas and those two points are pretty close to each other then if we try to generate some random points on the noise points on those two points then the numbers will be pretty close to each other and we would have used random instead of noise we would have got a canvas with just random points and this doesn't show any discernible pattern also okay so we can also use noise and some trigonometric functions like sine and cosine waves to create these waves like structure with the ion structures and to implement this we basically doing like we are making a while loop and we have some zero to two pi so we want our points to be aligned in a circular manner so we are adding an x offset and a y offset which is basically mapping the cosine value and the sine value between zero and ten because initially these values are between minus one and one and once we have these offset values we are creating a noise factor which we will be using to create an x and y coordinates so in a noise factor what we are doing is like we are basically using those x offset and the y offset values and we are also using a z offset because we want the curves to go in other direction as well so we are mapping those values between zero and one fifty that's because we don't want our curves to be very small so we want them to spread out across the canvas and once we have the noise factor we are changing the x and y coordinates and once we have changed those coordinate values and we are just creating curve vertex that we saw in the previous slides and once we are done with this we are decrementing the radius that we used in the noise factor sorry the x and y coordinates that's because we want that at each time the draw function is executing we want the next curves to be created at a distance different from the initial one and we can also change like cool so we can also change the RGB values or opacity whatever you want to do and you can also add other instructions and if you run the program you get something like this so I'll just quickly go through the other slides because we are left with not much time okay so Perlin noise so it's like a very important function for adding movement to your art pieces and you can also add some nice functions to add grain like effect on this canvas and this is an example of how you can use Perlin noise fields so these fields are basically the 2D fields of vectors each pointing in a similar but different direction as it's neighboring vectors and the velocities of these vectors depends on the other vectors only so depending on how we draw these particles we can generate some pretty cool stuff and as these are used for adding a moment in your art piece you can see that we are creating a noise field where the particles are moving from the right hand side to the top left and to implement this we are just basically creating some random vector points on the canvas and just appending those vector points to the points object and once you have those points object inside the draw function we are taking those the values of that object one by one and storing it inside vector object and we are looping from 0 to 20 and what you're doing is we are creating a noise value which is like we are mapping the x and y coordinates of that point between 0 and 2 pi because we are getting the radiance value over here because by radiance value we can change the x2 and y2 parameters on line number 21 and 22 and once we have created x1, y1, x2, y2 variables we can add the vertex value at x1, y1 and we then have to update the vector object according to the x2 and y2 values that's because once you have a point added to the canvas we want the next point to have a slightly different direction but as these are using noise values they will all be directing to a similar direction eventually and eventually if you let the program run for some time you will get something like this and we use heavy use of geometrical patterns and factors and chaotic the chaos theory when they are working in generative art a very simple example of geometrical pattern would be the sierpinski triangle so this is a very basic and another famous example of geometric pattern and where we are recursively dividing the triangle into smaller triangles and adding a stroke to it and we can also modify the sierpinski triangle by not just adding a stroke we can also add some fill inside and we can use linear transformation that we talked about earlier we can use rotations we can rotate these triangles we can use curve vertex to shed the sides of it and we can also use recursive approach to create factors and by using vertex and curve vertex and when you talk about the factor the first thing that comes to the mind is a Mandelbrot set so the more the zoom inside the Mandelbrot set the more similar patterns are able to see and that's the most fascinating part about factors and this is being represented on a complex plane where x y axis represents a real and the z axis represents the imaginary path so we pick a point in the coordinate plane and add the iterated and pass it through the equation z and plus 1 z and square plus c and we can also add some instructions of changing the colors and everything accordingly and similarly we can create Julia sets which are pretty much similar to Mandelbrot set and these are basically the boundary points that tends to infinity and then tends to infinity when you go deeper inside the Mandelbrot set we see that the Mandelbrot set is extending outwards on the x y plane and creates a bifurcation diagram and this logistic map is basically a part of the Mandelbrot set and this bifurcation diagram is created only on a real line because we put only real numbers into the equation and one fascinating thing about this bifurcation diagram is that this method was the first method to generate random numbers on computers and gives rise to a very famous topic called chaotic behavior or chaos theory and which is basically deterministic chaos something which is unpredictable so very small change in the initial state can bring drastically different changes in the final outcome and so we can change an initial change by some margin and we think the final outcome will be slightly different like you can see the four images but what we actually got in the end is our deterministic chaos and the best example to see chaos theory is attractors and which are basically mathematical functions that tends to evolve over time and if you're using processing you can just use points to create these attractors and if you're not using processing there's a very cool library called PiWis which has great examples of attractors and you can experiment with them like Swenson attractors, Bithead attractors and more okay so this is like the second last topic so we'll see how we can simulate the water paint effects or the oil paint effects on the canvas so the second image shows how we can use the water paint effects on the canvas on the 2D Cartesian plane so to give you an overview what I'm basically doing is like I'm basically creating a shape such as polygon and then starting extending its edges outwards and doing by doing so recursively and passing it through a deformation technique and eventually we will be getting some fine details and fine vertexes on the outer layer which eventually gives us this cool watercolor effect and further you can also create use some blur effects etc to add some more features and so how to do it so I'll quickly take 2-3 minutes to finish this thing so first we divide the polygon in firstly we create a polygon of say 20 sides and append those values to the polygon object then we initialized a mid range of 50 and we tried to divide those sides so we call the function getMid and by passing the parameters as the polygon object and the mid variable these values we passed are basically the mean and standard deviation in our function so inside the getMid function we as we pass the two values as mean and the standard deviation we are looping over which is taking the previous value and the current value of the polygon and we are just passing them to the getCenterPoint function which is returning a random number fitting to Gaussian distribution and once we had that value we can append those the previous value and the newly generated midpoint value to the new vector object and we can just directly return it and now what I'm doing is like I'm looping the length of the newly updated polygon so initially we had some 20 sides of the polygon now we have thousands of sides and once we have those points we can simply create the x, y coordinates by passing that value of side x and side y with a random value between 0 and 25 just give me one minute I'm done okay so we just we are sending the values back to the random Gauss values and once we have those coordinates we can add x and y position and this is a random Gaussian method for the scene and eventually we'll get something like this and this is the last thing where okay this is using shaders for creating oil paint effects and you can check the link for better understanding or the better approach which is going to say by Tyler Hobs this is the last thing which is like pixel sorting algorithms which is I just I won't be going to the code I'll just give you a quick over through I'll just take one more minute what we do is in the pixel sorting is it's basically isolating the horizontal and vertical lines of pixel in an image and we are sorting the positions based on a number of criteria so basically we load the pixels we then pick the original pixel with some x's of function we then pick the next pixel position change the number of signs and maybe you change you can also see a change in the direction of pixels we just compare it and swap the pixels so and this is a very simple implementation of it and eventually if you just then the function with this values you'll get something like this and this is Niresh I'm sorry to have to cut your short it was a very nice talk thank you very much if you have some questions you can go back to the talk call back and just chat with me thank you so much yes thank you very much and let me play your applause so let me just do this like this applause thank you thank you