Update README
168
README.md
|
@ -13,6 +13,8 @@ generativeart is a `Go` package to generate many kinds of generative art. The co
|
|||
- Spiral Square
|
||||
- Square Grid
|
||||
- Circle Line
|
||||
- Circle Loop
|
||||
- Silk Sky
|
||||
|
||||
For these kinds of art, the package provides as many as parameters to control the appearance.
|
||||
|
||||
|
@ -22,8 +24,174 @@ For these kinds of art, the package provides as many as parameters to control th
|
|||
go get github.com/jdxyw/generativeart
|
||||
```
|
||||
|
||||
## Art Type
|
||||
|
||||
```go
|
||||
NewCircleLine(step float64, lineNum int, radius float64)
|
||||
NewCircleLoop(radius float64)
|
||||
NewMaze()
|
||||
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)
|
||||
```
|
||||
|
||||
## Usage and example
|
||||
|
||||
### Silk Smoke
|
||||
|
||||
```go
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(500, 500, 2, 2)
|
||||
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")
|
||||
}
|
||||
```
|
||||
|
||||
![](images/silksmoke.png)
|
||||
|
||||
### Spiral Square
|
||||
|
||||
```go
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(500, 500, 2, 2)
|
||||
c.SetBackground(generativeart.MistyRose)
|
||||
c.SetLineWidth(10)
|
||||
c.SetLineColor(generativeart.Orange)
|
||||
c.SetColorSchema(generativeart.Viridis)
|
||||
c.SetForeground(generativeart.Tomato)
|
||||
c.FillBackground()
|
||||
c.Draw(generativeart.NewSpiralSquare(40, 400, 0.05, true))
|
||||
c.ToPNG("spiralsquare.png")
|
||||
}
|
||||
```
|
||||
|
||||
![](images/spiralsquare.png)
|
||||
|
||||
### Circle Loop
|
||||
|
||||
```go
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(500, 500, 2, 2)
|
||||
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")
|
||||
}
|
||||
```
|
||||
|
||||
![](images/circleloop.png)
|
||||
|
||||
### Julia Set
|
||||
|
||||
```go
|
||||
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, 1.5, 1.5)
|
||||
c.SetIterations(800)
|
||||
c.SetColorSchema(generativeart.Viridis)
|
||||
c.FillBackground()
|
||||
c.Draw(generativeart.NewJulia(julia1, 40))
|
||||
c.ToPNG("julia.png")
|
||||
}
|
||||
```
|
||||
|
||||
![](images/julia.png)
|
||||
|
||||
### Circle Line
|
||||
|
||||
```go
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(600, 600, 2, 2)
|
||||
c.SetBackground(generativeart.Tan)
|
||||
c.SetLineWidth(1.0)
|
||||
c.SetLineColor(generativeart.LightPink)
|
||||
c.FillBackground()
|
||||
c.Draw(generativeart.NewCircleLine(0.02, 600, 1.5))
|
||||
c.ToPNG("circleline.png")
|
||||
}
|
||||
```
|
||||
|
||||
![](images/circleline.png)
|
||||
|
||||
### Silk Sky
|
||||
|
||||
```go
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(600, 600, 1, 1)
|
||||
c.SetAlpha(10)
|
||||
c.Draw(generativeart.NewSilkSky(15, 5))
|
||||
c.ToPNG("silksky.png")
|
||||
}
|
||||
```
|
||||
|
||||
![](images/silksky.png)
|
||||
|
||||
### Maze
|
||||
|
||||
```go
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(600, 600, 2, 2)
|
||||
c.SetBackground(generativeart.Azure)
|
||||
c.SetLineWidth(3)
|
||||
c.SetLineColor(generativeart.Orange)
|
||||
c.FillBackground()
|
||||
c.Draw(generativeart.NewMaze())
|
||||
c.ToPNG("maze.png")
|
||||
}
|
||||
```
|
||||
|
||||
![](images/maze.png)
|
||||
|
||||
### Random Circle
|
||||
|
||||
```go
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(500, 500, 2, 2)
|
||||
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")
|
||||
}
|
||||
```
|
||||
|
||||
![](images/randcircle.png)
|
||||
|
||||
## TODO
|
||||
|
||||
- Add more kinds of generative arts or types.
|
||||
|
|
|
@ -8,10 +8,10 @@ import (
|
|||
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(800, 800, 2, 2)
|
||||
c := generativeart.NewCanva(600, 600, 2, 2)
|
||||
c.SetBackground(generativeart.Tan)
|
||||
c.SetLineWidth(1.0)
|
||||
c.SetLineColor(generativeart.Lavender)
|
||||
c.SetLineColor(generativeart.LightPink)
|
||||
c.FillBackground()
|
||||
c.Draw(generativeart.NewCircleLine(0.02, 600, 1.5))
|
||||
c.ToPNG("circleline.png")
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(600, 600, 1, 1)
|
||||
c.SetBackground(generativeart.Viridis[rand.Intn(255)])
|
||||
c.SetColorSchema(generativeart.Viridis)
|
||||
c.SetBackground(generativeart.DarkPink[rand.Intn(5)])
|
||||
c.SetColorSchema(generativeart.DarkPink)
|
||||
c.Draw(generativeart.NewGirdSquares())
|
||||
c.ToPNG("gsquare.png")
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ func julia1(z complex128) complex128 {
|
|||
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(800, 800, 1.5, 1.5)
|
||||
c := generativeart.NewCanva(500, 500, 1.5, 1.5)
|
||||
c.SetIterations(800)
|
||||
c.SetColorSchema(generativeart.Viridis)
|
||||
c.FillBackground()
|
||||
|
|
|
@ -8,9 +8,10 @@ import (
|
|||
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(800, 800, 2, 2)
|
||||
c := generativeart.NewCanva(600, 600, 2, 2)
|
||||
c.SetBackground(generativeart.Azure)
|
||||
c.SetForeground(generativeart.Tomato)
|
||||
c.SetLineWidth(3)
|
||||
c.SetLineColor(generativeart.Orange)
|
||||
c.FillBackground()
|
||||
c.Draw(generativeart.NewMaze())
|
||||
c.ToPNG("maze.png")
|
||||
|
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"generativeart"
|
||||
"image/color"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
@ -12,12 +11,8 @@ func main() {
|
|||
c := generativeart.NewCanva(500, 500, 2, 2)
|
||||
c.SetBackground(generativeart.Black)
|
||||
c.SetLineWidth(1.0)
|
||||
c.SetLineColor(color.RGBA{
|
||||
R: 255,
|
||||
G: 255,
|
||||
B: 255,
|
||||
A: 30,
|
||||
})
|
||||
c.SetLineColor(generativeart.MediumAquamarine)
|
||||
c.SetAlpha(30)
|
||||
c.SetColorSchema(generativeart.Plasma)
|
||||
c.SetIterations(4)
|
||||
c.FillBackground()
|
||||
|
|
BIN
images/circleline.png
Normal file
After Width: | Height: | Size: 268 KiB |
BIN
images/circleloop.png
Normal file
After Width: | Height: | Size: 132 KiB |
BIN
images/julia.png
Normal file
After Width: | Height: | Size: 90 KiB |
BIN
images/maze.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
images/randcircle.png
Normal file
After Width: | Height: | Size: 279 KiB |
BIN
images/silksky.png
Normal file
After Width: | Height: | Size: 154 KiB |
BIN
images/silksmoke.png
Normal file
After Width: | Height: | Size: 312 KiB |
BIN
images/spiralsquare.png
Normal file
After Width: | Height: | Size: 92 KiB |
2
maze.go
|
@ -16,7 +16,7 @@ func NewMaze() *maze {
|
|||
// Generative draws a random maze image.
|
||||
func (m *maze) Generative(c *canva) {
|
||||
ctex := gg.NewContextForRGBA(c.img)
|
||||
ctex.SetColor(c.opts.background)
|
||||
ctex.SetColor(c.opts.lineColor)
|
||||
ctex.SetLineWidth(c.opts.lineWidth)
|
||||
step := c.opts.step
|
||||
for x := 0; x < c.width; x += step {
|
||||
|
|
|
@ -22,7 +22,7 @@ func NewSilkSky(circleNum int, sunRadius float64) *silkSky {
|
|||
func (s *silkSky) Generative(c *canva) {
|
||||
ctex := gg.NewContextForRGBA(c.img)
|
||||
xm := float64(rand.Intn(c.width/5)) + float64(c.width*4/5-c.width/5)
|
||||
ym := float64(rand.Intn(c.height/5))+ float64(c.height*4/5-c.height/5)
|
||||
ym := float64(rand.Intn(c.height/5)) + float64(c.height*4/5-c.height/5)
|
||||
|
||||
mh := s.circleNum*2 + 2
|
||||
ms := s.circleNum*2 + 50
|
||||
|
|
|
@ -57,7 +57,7 @@ func (s *sileSmoke) Generative(c *canva) {
|
|||
cx := (c1.x + c2.x) / 2
|
||||
cy := (c1.y + c2.y) / 2
|
||||
|
||||
ctex.SetRGBA255(int(cl.R), int(cl.G), int(cl.B), 30)
|
||||
ctex.SetRGBA255(int(cl.R), int(cl.G), int(cl.B), c.opts.alpha)
|
||||
ctex.SetLineWidth(c.opts.lineWidth)
|
||||
|
||||
ctex.LineTo(c1.x, c1.y)
|
||||
|
|