diff --git a/README.md b/README.md index ccc0839..6d6dd3b 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ This package is still working in progress. More types would be added. Welcome an - Ocean Fish - Circle Loop2 - Pixel Hole +- Dots Wave For these kinds of art, the package provides as many parameters to control the appearance. @@ -69,6 +70,7 @@ NewContourLine(lineNum int) NewNoiseLine(n int) NewCircleLoop2(depth int) NewPixelHole(dotN int) +NewDotsWave(dotsN int) ``` ## Docs @@ -233,25 +235,28 @@ func main() { ![](images/pixelhole.png) -### Silk Smoke +### Dots Wave ```go func main() { rand.Seed(time.Now().Unix()) + colors := []color.RGBA{ + {0xFF, 0xBE, 0x0B, 0xFF}, + {0xFB, 0x56, 0x07, 0xFF}, + {0xFF, 0x00, 0x6E, 0xFF}, + {0x83, 0x38, 0xEC, 0xFF}, + {0x3A, 0x86, 0xFF, 0xFF}, + } c := generativeart.NewCanva(500, 500) - c.SetBackground(generativeart.Black) - c.SetLineWidth(1.0) - c.SetLineColor(generativeart.MediumAquamarine) - c.SetAlpha(30) - c.SetColorSchema(generativeart.Plasma) - c.SetIterations(4) + c.SetBackground(common.Black) c.FillBackground() - c.Draw(generativeart.NewSilkSmoke(400, 20, 0.2, 2, 10, 30, false)) - c.ToPNG("silksmoke.png") + c.SetColorSchema(colors) + c.Draw(generativeart.NewDotsWave(300)) + c.ToPNG("dotswave.png") } ``` -![](images/silksmoke.png) +![](images/dotswave.png) ### Contour Line @@ -338,6 +343,26 @@ func main() { ![](images/oceanfish.png) +### Silk Smoke + +```go +func main() { + rand.Seed(time.Now().Unix()) + c := generativeart.NewCanva(500, 500) + 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) + ### Circle Loop ```go diff --git a/docs/doc.md b/docs/doc.md index 73decb5..ad6f5ec 100644 --- a/docs/doc.md +++ b/docs/doc.md @@ -150,4 +150,16 @@ cl := generativeart.NewCircleLoop2(7) ph := generativeart.NewPixelHole(60) ``` -![](../images/pixelhole.png) \ No newline at end of file +![](../images/pixelhole.png) + +## Dots Wave + +### parameters + +- dotsN: The number of dots wave in the image. + +```go +d := generativeart.NewDotsWave(300) +``` + +![](../images/dotswave.png) \ No newline at end of file diff --git a/dotswave.go b/dotswave.go new file mode 100644 index 0000000..de14fd8 --- /dev/null +++ b/dotswave.go @@ -0,0 +1,48 @@ +package generativeart + +import ( + "github.com/fogleman/gg" + "github.com/jdxyw/generativeart/common" + "math" + "math/rand" +) + +type dotsWave struct { + dotsN int +} + +// NewDotsWave returns a dotsWave object. +func NewDotsWave(dotsN int) *dotsWave { + return &dotsWave{ + dotsN: dotsN, + } +} + +// Generative draws a dots wave images. +func (d *dotsWave) Generative(c *canva) { + ctex := gg.NewContextForRGBA(c.img) + noise := common.NewPerlinNoise() + for i := 0; i < d.dotsN; i++ { + x := common.RandomRangeFloat64(-0.1, 1.1) * float64(c.width) + y := common.RandomRangeFloat64(-0.1, 1.1) * float64(c.height) + + num := common.RandomRangeFloat64(100, 1000) + r := rand.Float64() * float64(c.width) * 0.15 * rand.Float64() + ind := common.RandomRangeFloat64(1, 8) + + ctex.Push() + ctex.Translate(x, y) + ctex.Rotate(float64(rand.Intn(8)) * math.Pi / 4) + rand.Shuffle(len(c.opts.colorSchema), func(i, j int) { + c.opts.colorSchema[i], c.opts.colorSchema[j] = c.opts.colorSchema[j], c.opts.colorSchema[i] + }) + for j := 0.0; j < num; j += ind { + s := float64(c.width) * 0.15 * common.RandomRangeFloat64(0, common.RandomRangeFloat64(0, common.RandomRangeFloat64(0, common.RandomRangeFloat64(0, common.RandomRangeFloat64(0, common.RandomRangeFloat64(0, rand.Float64())))))) + ci := int(float64(len(c.opts.colorSchema)) * noise.Noise3D(j*0.01, x, y)) + ctex.SetColor(c.opts.colorSchema[ci]) + ctex.DrawCircle(j, r*math.Sin(j*0.05), s*2/3) + ctex.Fill() + } + ctex.Pop() + } +} diff --git a/example/example_dotswave.go b/example/example_dotswave.go new file mode 100644 index 0000000..c77be1b --- /dev/null +++ b/example/example_dotswave.go @@ -0,0 +1,26 @@ +package main + +import ( + "github.com/jdxyw/generativeart" + "github.com/jdxyw/generativeart/common" + "image/color" + "math/rand" + "time" +) + +func main() { + rand.Seed(time.Now().Unix()) + colors := []color.RGBA{ + {0xFF, 0xBE, 0x0B, 0xFF}, + {0xFB, 0x56, 0x07, 0xFF}, + {0xFF, 0x00, 0x6E, 0xFF}, + {0x83, 0x38, 0xEC, 0xFF}, + {0x3A, 0x86, 0xFF, 0xFF}, + } + c := generativeart.NewCanva(500, 500) + c.SetBackground(common.Black) + c.FillBackground() + c.SetColorSchema(colors) + c.Draw(generativeart.NewDotsWave(300)) + c.ToPNG("dotswave.png") +} diff --git a/images/dotswave.png b/images/dotswave.png new file mode 100644 index 0000000..172e3e1 Binary files /dev/null and b/images/dotswave.png differ diff --git a/pixelhole.go b/pixelhole.go index 2761b03..791404f 100644 --- a/pixelhole.go +++ b/pixelhole.go @@ -23,7 +23,6 @@ func NewPixelHole(dotN int) *pixelHole { // Generative draws a pixel hole images. func (p *pixelHole) Generative(c *canva) { ctex := gg.NewContextForRGBA(c.img) - //ctex.Translate(float64(c.width)/2, float64(c.height)/2) for i := 0.0; i < float64(c.opts.nIters); i += 1.0 { ctex.Push() ctex.Translate(float64(c.width)/2, float64(c.height)/2)