generativeart is a Go package to generate many kinds of generative art.

generativeart

Go Go Report Card GitHub license

generativeart is a Go package to generate many kinds of generative art. The goal is to collect some excellent generative art (implemented in R or Processing), and rewrite them in Go again. I would paste the original link at the end of this README(If I remember. You can also submit a PR if you found I miss something.). Currently, it supports the following type.

This package is still working in progress, more types would be added. Welcome anyone interested in this filed to submit your PR.

  • Maze
  • Julia Set
  • Random Circle Trails
  • Silk Smoke
  • Spiral Square
  • Square Grid
  • Circle Line
  • Circle Loop
  • Silk Sky
  • Dot Line
  • Swirl
  • Point Ribbon
  • Janus
  • Random Shapes

For these kinds of art, the package provides as many as parameters to control the appearance.

Install

The go version I used is go 1.16.

go get github.com/jdxyw/generativeart

Art Type

NewCircleLine(step float64, lineNum int, radius, xaixs, yaixs float64)
NewCircleLoop(radius float64)
NewMaze(step int)
NewRandCicle(mc, msp int, minStep, maxStep, minr, maxr float64, isRandColor bool)
NewSilkSky(circleNum int, sunRadius float64)
NewSilkSmoke(mc, msp int, minStep, maxStep, minRadius, maxRadius float64, isRandColor bool)
NewSpiralSquare(squareNum int, rectSide, decay float64, randColor bool)
NewSwirl(a, b, c, d, xaixs, yaixs float64)
NewDotLine(n int, ras, canv float64, randColor bool)
NewPointRibbon(r float64)
NewJanus(n int, decay float64)
NewRandomShape(shapeNum int)

General Options

type Options struct {
	background  color.RGBA
	foreground  color.RGBA
	lineColor   color.RGBA
	lineWidth   float64
	colorSchema []color.RGBA
	nIters      int
	alpha       int
}

The Options is a global option for the whole canva. It includes those general parameters used by different kinds of types, such as background, lineColor, and colorScheme.

For those parameters specified for different kinds of art type, they have their own struct.

Usage and example

Silk Smoke

func main() {
	rand.Seed(time.Now().Unix())
	c := generativeart.NewCanva(500, 500)
	c.SetBackground(generativeart.Black)
	c.SetLineWidth(1.0)
	c.SetLineColor(generativeart.MediumAquamarine)
	c.SetAlpha(30)
	c.SetColorSchema(generativeart.Plasma)
	c.SetIterations(4)
	c.FillBackground()
	c.Draw(generativeart.NewSilkSmoke(400, 20, 0.2, 2, 10, 30, false))
	c.ToPNG("silksmoke.png")
}

Random Shapes

func main() {
	rand.Seed(time.Now().Unix())
	c := generativeart.NewCanva(500, 500)
	c.SetBackground(generativeart.White)
	c.FillBackground()
	c.SetColorSchema([]color.RGBA{
		{0xCF, 0x2B, 0x34, 0xFF},
		{0xF0, 0x8F, 0x46, 0xFF},
		{0xF0, 0xC1, 0x29, 0xFF},
		{0x19, 0x6E, 0x94, 0xFF},
		{0x35, 0x3A, 0x57, 0xFF},
	})
	c.Draw(generativeart.NewRandomShape(150))
	c.ToPNG("randomshape.png")
}

Spiral Square

func main() {
	rand.Seed(time.Now().Unix())
	c := generativeart.NewCanva(500, 500)
	c.SetBackground(generativeart.MistyRose)
	c.SetLineWidth(10)
	c.SetLineColor(generativeart.Orange)
	c.SetColorSchema(generativeart.Plasma)
	c.SetForeground(generativeart.Tomato)
	c.FillBackground()
	c.Draw(generativeart.NewSpiralSquare(40, 400, 0.05, true))
	c.ToPNG("spiralsquare.png")
}

Circle Loop

func main() {
	rand.Seed(time.Now().Unix())
	c := generativeart.NewCanva(500, 500)
	c.SetBackground(generativeart.Black)
	c.SetLineWidth(1)
	c.SetLineColor(generativeart.Orange)
	c.SetAlpha(30)
	c.SetIterations(1000)
	c.FillBackground()
	c.Draw(generativeart.NewCircleLoop(100))
	c.ToPNG("circleloop.png")
}

Dot Line

func main() {
	rand.Seed(time.Now().Unix())
	c := generativeart.NewCanva(2080, 2080)
	c.SetBackground(color.RGBA{230, 230, 230, 255})
	c.SetLineWidth(10)
	c.SetIterations(4000)
	c.SetColorSchema(generativeart.Plasma)
	c.FillBackground()
	c.Draw(generativeart.NewDotLine(100, 20, 50, false))
	c.ToPNG("dotline.png")
}

Junas

func main() {
	rand.Seed(time.Now().Unix())
	c := generativeart.NewCanva(500, 500)
	c.SetBackground(generativeart.Black)
	c.FillBackground()
	c.SetColorSchema(generativeart.DarkRed)
	c.SetForeground(generativeart.LightPink)
	c.Draw(generativeart.NewJanus(10, 0.2))
	c.ToPNG("janus.png")
}

Julia Set

func julia1(z complex128) complex128 {
	c := complex(-0.1, 0.651)
	z = z*z + c

	return z
}

func main() {
	rand.Seed(time.Now().Unix())
	c := generativeart.NewCanva(500, 500)
	c.SetIterations(800)
	c.SetColorSchema(generativeart.Viridis)
	c.FillBackground()
	c.Draw(generativeart.NewJulia(julia1, 40, 1.5, 1.5))
	c.ToPNG("julia.png")
}

Silk Sky

func main() {
	rand.Seed(time.Now().Unix())
	c := generativeart.NewCanva(600, 600)
	c.SetAlpha(10)
	c.Draw(generativeart.NewSilkSky(15, 5))
	c.ToPNG("silksky.png")
}

Point Ribbon

func main() {
	rand.Seed(time.Now().Unix())
	c := generativeart.NewCanva(500, 500)
	c.SetBackground(generativeart.Lavender)
	c.SetLineWidth(2)
	c.SetIterations(150000)
	c.FillBackground()
	c.Draw(generativeart.NewPointRibbon(50))
	c.ToPNG("pointribbon.png")
}

Maze

func main() {
	rand.Seed(time.Now().Unix())
	c := generativeart.NewCanva(600, 600)
	c.SetBackground(generativeart.Azure)
	c.SetLineWidth(3)
	c.SetLineColor(generativeart.Orange)
	c.FillBackground()
	c.Draw(generativeart.NewMaze(20))
	c.ToPNG("maze.png")
}

Random Circle

func main() {
	rand.Seed(time.Now().Unix())
	c := generativeart.NewCanva(500, 500)
	c.SetBackground(generativeart.MistyRose)
	c.SetLineWidth(1.0)
	c.SetLineColor(color.RGBA{
		R: 122,
		G: 122,
		B: 122,
		A: 30,
	})
	c.SetColorSchema(generativeart.Plasma)
	c.SetIterations(4)
	c.FillBackground()
	c.Draw(generativeart.NewRandCicle(30, 80, 0.2, 2, 10, 30, true))
	c.ToPNG("randcircle.png")
}

TODO

  • Add more kinds of generative arts or types.

Contribution

Thanks for the following sites and repos, I got lots of ideas, inspiration, code and tricks from them. The list would be very long, sorry for forgetting some of them.

Comments
  • undefined: common.Plasma

    undefined: common.Plasma

    I am trying to run the go files, using the command line: go run example.go AND also: go build example.go

    I recieve the following error:

    command-line-arguments

    .\example_dotline.go:18:19: undefined: common.Plasma

  • consider changing the module name to github.com/jdxyw/generativeart

    consider changing the module name to github.com/jdxyw/generativeart

    sadly when go getting it it throws a tantrum:

    ~/code/refs/generativeart
    ❯ go get github.com/jdxyw/generativeart
    go: github.com/jdxyw/generativeart upgrade => v0.0.0-20210303093834-f33224c60df0
    go get: github.com/jdxyw/[email protected]: parsing go.mod:
    	module declares its path as: generativeart
    	        but was required as: github.com/jdxyw/generativeart
    

    I'd open a PR myself but it requires updating all import paths all over the place. I might just do that 🤔

  • feat: ToBytes() Method

    feat: ToBytes() Method

    Changes:

    • c.ToBytes() ([]byte, error) method added
    • http request example for the ToBytes method added

    Details:

    The new ToBytes method renders the image to a buffer, jpeg-encodes the image, and returns the resulting byte slice.

    #4

  • Color scale library

    Color scale library

    I create color scale library, which maybe useful for generative art.

    Repo: https://github.com/mazznoer/colorgrad

    Sorry for my broken english and feel free to close this issue.

  • Canva.Options fields are not exported

    Canva.Options fields are not exported

    We currently cannot use the Options struct for the SetOptions() method because its fields aren't exported.

    Had to use the helpers function instead :

    type OptionsOverride struct {
    	Background  color.RGBA
    	Foreground  color.RGBA
    	LineColor   color.RGBA
    	LineWidth   float64
    	ColorSchema []color.RGBA
    	NIters      int
    	Alpha       int
    }
    
    func setCanvaOptions(c *generativeart.Canva, options OptionsOverride) {
    	c.SetBackground(options.Background)
    	c.SetForeground(options.Foreground)
    	c.SetLineColor(options.LineColor)
    	c.SetLineWidth(options.LineWidth)
    	c.SetColorSchema(options.ColorSchema)
    	c.SetIterations(options.NIters)
    	c.SetAlpha(options.Alpha)
    }
    
  • Is a wordcloud generator a useful addition?

    Is a wordcloud generator a useful addition?

    There happens to be one in golang: https://github.com/psykhi/wordclouds

    It appears to be quite useful and might be a nice addition to this collection.

:triangular_ruler: Create beautiful generative image patterns from a string in golang.
:triangular_ruler: Create beautiful generative image patterns from a string in golang.

geopattern Create beautiful generative image patterns from a string in golang. Go port of Jason Long's awesome GeoPattern library. Read geopattern's d

Dec 29, 2022
Generative Julia Set Image in Go
Generative Julia Set Image in Go

julia Generative Julia Set Image in Go In general terms, a Julia set is the boundary between points in the complex number plane or the Riemann sphere

Mar 20, 2022
Generate high-quality triangulated art from images.
Generate high-quality triangulated art from images.

An iterative algorithm to generate high quality triangulated images.

May 26, 2021
API for generate image to ASCII Art

ASCII API Generate ASCII art from image. You can try this API here: ascii.projec

Jul 1, 2022
3D line art engine.
3D line art engine.

ln The 3D Line Art Engine ln is a vector-based 3D renderer written in Go. It is used to produce 2D vector graphics (think SVGs) depicting 3D scenes. T

Dec 28, 2022
A cross-platform tool to convert images into ascii art and print them on the console
A cross-platform tool to convert images into ascii art and print them on the console

A cross-platform tool to convert images into ascii art and print them on the console

Dec 30, 2022
Convert images to computer generated art using delaunay triangulation.
Convert images to computer generated art using delaunay triangulation.

▲ Triangle is a tool for generating triangulated image using delaunay triangulation. It takes a source image and converts it to an abstract image comp

Dec 29, 2022
Ascii-art-web
Ascii-art-web

ASCII-ART-WEB Author: Alika96 How to run Run the following commands: For building an image: docker image build -t ascii-art-web-docker . For showing i

Dec 13, 2021
Human-friendly Go module that builds and prints directory trees using ASCII art

Human-friendly Go module that builds and prints directory trees using ASCII art.

Oct 11, 2022
A simple javascript website that takes user input, queries a Go based backend which then creates ascii art and sends it back to the frontend

A simple javascript website that takes user input, queries a Go based backend which then creates ascii art and sends it back to the frontend. Finally the site displays the ascii art and offers the option to download as multiple file types.

Jan 7, 2022
A command to output longified ascii art.

longify A command to output longified ascii art. Inspired by Tweet from @sheepla: https://twitter.com/Sheeeeepla/status/1522199846870196225 Installati

Sep 12, 2022
:football: Generate your own O'RLY animal book cover to troll your colleagues | 生成你自己的O'RLY动物书封面,让你的同事惊掉下巴

English | 中文 O'RLY Cover Generator O'RLY Cover Generator is a parody book cover generator, implemented in Golang and Vue.js, supporting a wide range o

Dec 24, 2022
An iterative algorithm to generate high quality triangulated images.
An iterative algorithm to generate high quality triangulated images.

Triangula uses a modified genetic algorithm to triangulate images. It works best with images smaller than 3000px and with fewer than 3000 points, typically producing an optimal result within a couple of minutes.

Jan 8, 2023
Generate image plots of processes' memory usage very quickly, within a single binary.
Generate image plots of processes' memory usage very quickly, within a single binary.

memplot A small utility written in golang to quickly plot memory usage of processes. memplot constantly samples memory usage of a process, for a given

Apr 17, 2021
Generate a TwitterCard(OGP) image for your Hugo posts.
Generate a TwitterCard(OGP) image for your Hugo posts.

Twitter Card Image Generator Generate Twitter card (OGP) images for your blog posts. Supported front-matters are title, author, categories, tags, and

Dec 17, 2022
code2img can generate image of source code
code2img can generate image of source code

code2img code2img can generate image of source code. This was inspired by carbon and silicon Features Doesn't need browser & Internet Copy image of so

Nov 15, 2022
Generate a favicon.ico from a short string
Generate a favicon.ico from a short string

icostring Generate a file in the ICO format from a short string of either 16 or 64 characters ('a'..'p', 'q' and 't') + an optional hex encoded color

Dec 24, 2021
A generator of cats/birds/mobilizon pictures optimised to generate or random avatars, or defined avatar from a "seed"

A generator of cats/birds/mobilizon pictures optimised to generate or random avatars, or defined avatar from a "seed". A derivation by David Revoy from the original MonsterID by Andreas Gohr's.

Feb 7, 2022
A pure Go package for coordinate transformations.

WGS84 A pure Go package for coordinate transformations. go get github.com/wroge/wgs84 Usage east, north, h := wgs84.LonLat().To(wgs84.ETRS89UTM(32)).R

Nov 25, 2022