update the contourline and readme

This commit is contained in:
Yongwei Xing 2021-03-09 14:08:33 +08:00
parent eddb3f9709
commit f502fa09e4
5 changed files with 40 additions and 23 deletions

View file

@ -26,6 +26,7 @@ This package is still working in progress, more types would be added. Welcome an
- Color Circle - Color Circle
- Color Circle2 - Color Circle2
- Circle Grid - Circle Grid
- Contour Line
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.
@ -55,6 +56,7 @@ NewRandomShape(shapeNum int)
NewColorCircle(circleNum int) NewColorCircle(circleNum int)
NewColorCircle2(circleNum int) NewColorCircle2(circleNum int)
NewCircleGrid(circleNumMin, circleNumMax int) NewCircleGrid(circleNumMin, circleNumMax int)
NewContourLine(lineNum int)
``` ```
## Docs ## Docs
@ -190,24 +192,28 @@ func main() {
![](images/silksmoke.png) ![](images/silksmoke.png)
### Spiral Square ### Contour Line
```go ```go
func main() { func main() {
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().Unix())
c := generativeart.NewCanva(500, 500) colors := []color.RGBA{
c.SetBackground(generativeart.MistyRose) {0x58, 0x18, 0x45, 0xFF},
c.SetLineWidth(10) {0x90, 0x0C, 0x3F, 0xFF},
c.SetLineColor(generativeart.Orange) {0xC7, 0x00, 0x39, 0xFF},
c.SetColorSchema(generativeart.Plasma) {0xFF, 0x57, 0x33, 0xFF},
c.SetForeground(generativeart.Tomato) {0xFF, 0xC3, 0x0F, 0xFF},
}
c := generativeart.NewCanva(1600, 1600)
c.SetBackground(color.RGBA{0x1a, 0x06, 0x33, 0xFF})
c.FillBackground() c.FillBackground()
c.Draw(generativeart.NewSpiralSquare(40, 400, 0.05, true)) c.SetColorSchema(colors)
c.ToPNG("spiralsquare.png") c.Draw(generativeart.NewContourLine(500))
c.ToPNG("contourline.png")
} }
``` ```
![](images/spiralsquare.png) ![](images/contourline.png)
### Circle Loop ### Circle Loop
@ -345,3 +351,4 @@ Thanks for the following sites and repos, I got lots of ideas, inspiration, code
- https://editor.p5js.org/kenekk1/sketches/O44Dln5oo - https://editor.p5js.org/kenekk1/sketches/O44Dln5oo
- https://openprocessing.org/sketch/1071233 - https://openprocessing.org/sketch/1071233
- https://twitter.com/okazz_ - https://twitter.com/okazz_
- https://openprocessing.org/sketch/738638

View file

@ -1,8 +1,8 @@
package generativeart package generativeart
import ( import (
"github.com/aquilax/go-perlin"
"github.com/fogleman/gg" "github.com/fogleman/gg"
"github.com/jdxyw/generativeart/common"
"math" "math"
"math/rand" "math/rand"
) )
@ -11,6 +11,7 @@ type contourLine struct {
lineNum int lineNum int
} }
// NewContourLine returns a contourLine object.
func NewContourLine(lineNum int) *contourLine { func NewContourLine(lineNum int) *contourLine {
return &contourLine{ return &contourLine{
lineNum: lineNum, lineNum: lineNum,
@ -20,21 +21,21 @@ func NewContourLine(lineNum int) *contourLine {
// Generative draws a contour line image. // Generative draws a contour line image.
func (cl *contourLine) Generative(c *canva) { func (cl *contourLine) Generative(c *canva) {
ctex := gg.NewContextForRGBA(c.img) ctex := gg.NewContextForRGBA(c.img)
noise := perlin.NewPerlin(2, 2, 3, rand.Int63()) //noise := perlin.NewPerlin(2, 2, 3, rand.Int63())
noise := common.NewPerlinNoise()
for i := 0; i < cl.lineNum; i++ { for i := 0; i < cl.lineNum; i++ {
cl := c.opts.colorSchema[rand.Intn(len(c.opts.colorSchema))] cl := c.opts.colorSchema[rand.Intn(len(c.opts.colorSchema))]
for j := 0; j < 5; j++ {
x := rand.Float64() * float64(c.width) x := rand.Float64() * float64(c.width)
y := rand.Float64() * float64(c.height) y := rand.Float64() * float64(c.height)
theta := noise.Noise2D(x/800.0, y/800.0) * math.Pi * 2 * 800 for j := 0; j < 1500; j++ {
theta := noise.Noise(x/800.0, y/800.0, 0) * math.Pi * 2 * 800
x += math.Cos(theta) * 0.4 x += math.Cos(theta) * 0.4
y += math.Sin(theta) * 0.4 y += math.Sin(theta) * 0.4
ctex.SetColor(cl) ctex.SetColor(cl)
ctex.DrawEllipse(x, y, 1, 1) ctex.DrawEllipse(x, y, 2, 2)
ctex.Fill() ctex.Fill()
if x > float64(c.width) || x < 0 || y > float64(c.height) || y < 0 || rand.Float64() < 0.001 { if x > float64(c.width) || x < 0 || y > float64(c.height) || y < 0 || rand.Float64() < 0.001 {

View file

@ -44,15 +44,24 @@ rs := NewRandomShape(150)
## Janus ## Janus
`Janus` would draws a image with multiple circles split at its center with random noise in the horizontal direction. `Janus` would draw an image with multiple circles split at its center with random noise in the horizontal direction.
### TODO ### TODO
### parameters ### parameters
## Contour Line
`Contour Line` uses `perlin noise` to do some flow field.
### parameters
- lineNum: It indicates how many lines.
![](../images/contourline.png)
## Silk Sky ## Silk Sky
`Silk Sky` would draws a image with multiple circles converge to one point or circle. `Silk Sky` would draw an image with multiple circles converge to one point or one circle.
### parameters ### parameters
@ -73,7 +82,7 @@ silkSky := NewSilkSky(circleNum int, sunRadius float64)
- fn: The custom julia set function. - fn: The custom julia set function.
- maxz: The maximum modulus length of a complex number. - maxz: The maximum modulus length of a complex number.
- xaixs, yaixs: The range for the X-Y coordination used to mapping the julia set number to the real pixel of the image. These should be positive number. It only indicates the first quadrant range. - xaixs, yaixs: The range for the X-Y coordination used to mapping the julia set number to the real pixel of the image. These should be positive. It only indicates the first quadrant range.
```go ```go
func julia1(z complex128) complex128 { func julia1(z complex128) complex128 {

View file

@ -16,10 +16,10 @@ func main() {
{0xFF, 0x57, 0x33, 0xFF}, {0xFF, 0x57, 0x33, 0xFF},
{0xFF, 0xC3, 0x0F, 0xFF}, {0xFF, 0xC3, 0x0F, 0xFF},
} }
c := generativeart.NewCanva(800, 800) c := generativeart.NewCanva(1600, 1600)
c.SetBackground(color.RGBA{0x1a, 0x06, 0x33, 0xFF}) c.SetBackground(color.RGBA{0x1a, 0x06, 0x33, 0xFF})
c.FillBackground() c.FillBackground()
c.SetColorSchema(colors) c.SetColorSchema(colors)
c.Draw(generativeart.NewContourLine(200)) c.Draw(generativeart.NewContourLine(500))
c.ToPNG("contourline.png") c.ToPNG("contourline.png")
} }

BIN
images/contourline.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 KiB