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 Circle2
- Circle Grid
- Contour Line
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)
NewColorCircle2(circleNum int)
NewCircleGrid(circleNumMin, circleNumMax int)
NewContourLine(lineNum int)
```
## Docs
@ -190,24 +192,28 @@ func main() {
![](images/silksmoke.png)
### Spiral Square
### Contour Line
```go
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)
colors := []color.RGBA{
{0x58, 0x18, 0x45, 0xFF},
{0x90, 0x0C, 0x3F, 0xFF},
{0xC7, 0x00, 0x39, 0xFF},
{0xFF, 0x57, 0x33, 0xFF},
{0xFF, 0xC3, 0x0F, 0xFF},
}
c := generativeart.NewCanva(1600, 1600)
c.SetBackground(color.RGBA{0x1a, 0x06, 0x33, 0xFF})
c.FillBackground()
c.Draw(generativeart.NewSpiralSquare(40, 400, 0.05, true))
c.ToPNG("spiralsquare.png")
c.SetColorSchema(colors)
c.Draw(generativeart.NewContourLine(500))
c.ToPNG("contourline.png")
}
```
![](images/spiralsquare.png)
![](images/contourline.png)
### 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://openprocessing.org/sketch/1071233
- https://twitter.com/okazz_
- https://openprocessing.org/sketch/738638

View file

@ -1,8 +1,8 @@
package generativeart
import (
"github.com/aquilax/go-perlin"
"github.com/fogleman/gg"
"github.com/jdxyw/generativeart/common"
"math"
"math/rand"
)
@ -11,6 +11,7 @@ type contourLine struct {
lineNum int
}
// NewContourLine returns a contourLine object.
func NewContourLine(lineNum int) *contourLine {
return &contourLine{
lineNum: lineNum,
@ -20,21 +21,21 @@ func NewContourLine(lineNum int) *contourLine {
// Generative draws a contour line image.
func (cl *contourLine) Generative(c *canva) {
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++ {
cl := c.opts.colorSchema[rand.Intn(len(c.opts.colorSchema))]
x := rand.Float64() * float64(c.width)
y := rand.Float64() * float64(c.height)
for j := 0; j < 5; j++ {
x := rand.Float64() * float64(c.width)
y := rand.Float64() * float64(c.height)
for j := 0; j < 1500; j++ {
theta := noise.Noise2D(x/800.0, y/800.0) * math.Pi * 2 * 800
theta := noise.Noise(x/800.0, y/800.0, 0) * math.Pi * 2 * 800
x += math.Cos(theta) * 0.4
y += math.Sin(theta) * 0.4
ctex.SetColor(cl)
ctex.DrawEllipse(x, y, 1, 1)
ctex.DrawEllipse(x, y, 2, 2)
ctex.Fill()
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` 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
### 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` 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
@ -73,7 +82,7 @@ silkSky := NewSilkSky(circleNum int, sunRadius float64)
- fn: The custom julia set function.
- 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
func julia1(z complex128) complex128 {

View file

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

BIN
images/contourline.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 KiB