Update README

This commit is contained in:
Yongwei Xing 2021-03-03 17:38:34 +08:00
parent eb5b0e05bd
commit f33224c60d
17 changed files with 181 additions and 17 deletions

168
README.md
View file

@ -13,6 +13,8 @@ generativeart is a `Go` package to generate many kinds of generative art. The co
- Spiral Square - Spiral Square
- Square Grid - Square Grid
- Circle Line - Circle Line
- Circle Loop
- Silk Sky
For these kinds of art, the package provides as many as parameters to control the appearance. 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 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 ## 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 ## TODO
- Add more kinds of generative arts or types. - Add more kinds of generative arts or types.

View file

@ -8,10 +8,10 @@ import (
func main() { func main() {
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().Unix())
c := generativeart.NewCanva(800, 800, 2, 2) c := generativeart.NewCanva(600, 600, 2, 2)
c.SetBackground(generativeart.Tan) c.SetBackground(generativeart.Tan)
c.SetLineWidth(1.0) c.SetLineWidth(1.0)
c.SetLineColor(generativeart.Lavender) c.SetLineColor(generativeart.LightPink)
c.FillBackground() c.FillBackground()
c.Draw(generativeart.NewCircleLine(0.02, 600, 1.5)) c.Draw(generativeart.NewCircleLine(0.02, 600, 1.5))
c.ToPNG("circleline.png") c.ToPNG("circleline.png")

View file

@ -9,8 +9,8 @@ import (
func main() { func main() {
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().Unix())
c := generativeart.NewCanva(600, 600, 1, 1) c := generativeart.NewCanva(600, 600, 1, 1)
c.SetBackground(generativeart.Viridis[rand.Intn(255)]) c.SetBackground(generativeart.DarkPink[rand.Intn(5)])
c.SetColorSchema(generativeart.Viridis) c.SetColorSchema(generativeart.DarkPink)
c.Draw(generativeart.NewGirdSquares()) c.Draw(generativeart.NewGirdSquares())
c.ToPNG("gsquare.png") c.ToPNG("gsquare.png")
} }

View file

@ -16,7 +16,7 @@ func julia1(z complex128) complex128 {
func main() { func main() {
rand.Seed(time.Now().Unix()) 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.SetIterations(800)
c.SetColorSchema(generativeart.Viridis) c.SetColorSchema(generativeart.Viridis)
c.FillBackground() c.FillBackground()

View file

@ -8,9 +8,10 @@ import (
func main() { func main() {
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().Unix())
c := generativeart.NewCanva(800, 800, 2, 2) c := generativeart.NewCanva(600, 600, 2, 2)
c.SetBackground(generativeart.Azure) c.SetBackground(generativeart.Azure)
c.SetForeground(generativeart.Tomato) c.SetLineWidth(3)
c.SetLineColor(generativeart.Orange)
c.FillBackground() c.FillBackground()
c.Draw(generativeart.NewMaze()) c.Draw(generativeart.NewMaze())
c.ToPNG("maze.png") c.ToPNG("maze.png")

View file

@ -2,7 +2,6 @@ package main
import ( import (
"generativeart" "generativeart"
"image/color"
"math/rand" "math/rand"
"time" "time"
) )
@ -12,12 +11,8 @@ func main() {
c := generativeart.NewCanva(500, 500, 2, 2) c := generativeart.NewCanva(500, 500, 2, 2)
c.SetBackground(generativeart.Black) c.SetBackground(generativeart.Black)
c.SetLineWidth(1.0) c.SetLineWidth(1.0)
c.SetLineColor(color.RGBA{ c.SetLineColor(generativeart.MediumAquamarine)
R: 255, c.SetAlpha(30)
G: 255,
B: 255,
A: 30,
})
c.SetColorSchema(generativeart.Plasma) c.SetColorSchema(generativeart.Plasma)
c.SetIterations(4) c.SetIterations(4)
c.FillBackground() c.FillBackground()

BIN
images/circleline.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 KiB

BIN
images/circleloop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

BIN
images/julia.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

BIN
images/maze.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
images/randcircle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 KiB

BIN
images/silksky.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

BIN
images/silksmoke.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 KiB

BIN
images/spiralsquare.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

View file

@ -16,7 +16,7 @@ func NewMaze() *maze {
// Generative draws a random maze image. // Generative draws a random maze image.
func (m *maze) Generative(c *canva) { func (m *maze) Generative(c *canva) {
ctex := gg.NewContextForRGBA(c.img) ctex := gg.NewContextForRGBA(c.img)
ctex.SetColor(c.opts.background) ctex.SetColor(c.opts.lineColor)
ctex.SetLineWidth(c.opts.lineWidth) ctex.SetLineWidth(c.opts.lineWidth)
step := c.opts.step step := c.opts.step
for x := 0; x < c.width; x += step { for x := 0; x < c.width; x += step {

View file

@ -22,7 +22,7 @@ func NewSilkSky(circleNum int, sunRadius float64) *silkSky {
func (s *silkSky) Generative(c *canva) { func (s *silkSky) Generative(c *canva) {
ctex := gg.NewContextForRGBA(c.img) ctex := gg.NewContextForRGBA(c.img)
xm := float64(rand.Intn(c.width/5)) + float64(c.width*4/5-c.width/5) 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 mh := s.circleNum*2 + 2
ms := s.circleNum*2 + 50 ms := s.circleNum*2 + 50

View file

@ -57,7 +57,7 @@ func (s *sileSmoke) Generative(c *canva) {
cx := (c1.x + c2.x) / 2 cx := (c1.x + c2.x) / 2
cy := (c1.y + c2.y) / 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.SetLineWidth(c.opts.lineWidth)
ctex.LineTo(c1.x, c1.y) ctex.LineTo(c1.x, c1.y)