GenArt.js is a JavaScript library designed for easy creation of generative art. It’s a project that I’ve been working on over the past few days, so it’s not perfect.
To get started, you’ll need to download the latest version of the library. Then, create a new .html file in your preferred text editor, and add the downloaded library to the html file. Next, create an empty .js file, and paste this code into it:
let canv = GA.canvas(1024, 1024);
canv.global();
function generate() {
// your generation code here...
}
Once you reference the new file in your html file, you’re good to go!
x - x position of the circle
y - y position of the circle
radius - radius of the circle
x - x position of the ellipse
y - y position of the ellipse
radiusx - x radius of the ellipse
radiusy - y radius of the ellipse
x - x position of the square
y - y position of the square
size - edge length of the square
x - x position of the rectangle
y - y position of the rectangle
width - width of the rectangle
height - height of the rectangle
x1 - first x position of the line
y1 - first y position of the line
x2 - second x position of the line
y2 - second y position of the line
pointArray - The list of points that defines the lines of the polyline. Points can be in either the [x, y]
format or the {x: x, y: y}
format. You can even mix these formats together, in a single function call.
pointArray - The list of points that defines the lines of the polygon. Points can be in either the [x, y]
format or the {x: x, y: y}
format. You can even mix these formats together, in a single function call.
perfectPolygon(x, y, radius, vertices, [rotation])
- Draw a perfect polygon (a polygon where all edge lengths and angles are the same)
x - x position of the polgon
y - y position of the polygon
radius - radius of the polygon
vertices - number of vertices in the polygon
rotation (optional) - the rotation of the polygon, in degrees. Defaults to 0
pointArray - The list of points that defines the start, end, and control point(s) of the curve. Points can be in either the [x, y]
format or the {x: x, y: y}
format. You can even mix these formats together, in a single function call.
pointArray - The list of points that defines the start, end, and control point(s) of the curve. Points can be in either the [x, y]
format or the {x: x, y: y}
format. You can even mix these formats together, in a single function call.
pointArray - The list of points that defines the control point(s) of the curve. Points can be in either the [x, y]
format or the {x: x, y: y}
format. You can even mix these formats together, in a single function call.
color - The color of the background. This parameter is very versatile, as it can be a hex code, rgb string, html color name, or list of rgb(a) values.
color - The new fill color. This parameter is very versatile, as it can be a hex code, rgb string, html color name, or list of rgb(a) values.
color - The new stroke color. This parameter is very versatile, as it can be a hex code, rgb string, html color name, or list of rgb(a) values.
weight - the weight (width) of future strokes
pushStyle()
- Saves the current styling for later. The styling can be restored with the popStyle() function
popStyle()
- Restores the most recently saved style, and removes it from the list of saved styles. You must call pushStyle() before you call this
x - the amount for shapes to be translated on the X axis
y (optional) - the amount for shapes to be translated on the Y axis. Defaults to 0
angle - angle in degrees for the shapes to be rotated
x (optional) - The center for the rotation on the X axis. Defaults to 0
y (optional, must be specified if x is) - The center for the rotation on the Y axis. Defaults to 0
x - The amount to scale objects, on the X axis
y (optional) - The amount to scale objects, on the Y axis. Defaults to x if not specified.
angle - Angle to skew the objects at
angle - Angle to skew the objects at