diff --git a/README.md b/README.md index 697d68d..0af92ba 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/contourline.go b/contourline.go index 880df6f..5ef5f85 100644 --- a/contourline.go +++ b/contourline.go @@ -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 { diff --git a/docs/doc.md b/docs/doc.md index 72e46ec..7a1394e 100644 --- a/docs/doc.md +++ b/docs/doc.md @@ -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 { diff --git a/example/example_contourline.go b/example/example_contourline.go index b472df7..9d36223 100644 --- a/example/example_contourline.go +++ b/example/example_contourline.go @@ -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") } diff --git a/images/contourline.png b/images/contourline.png new file mode 100644 index 0000000..cdbf023 Binary files /dev/null and b/images/contourline.png differ