add dots wave

This commit is contained in:
Yongwei Xing 2021-03-12 15:18:07 +08:00
parent 3275179fc1
commit dfd32aa0a6
6 changed files with 122 additions and 12 deletions

View file

@ -36,6 +36,7 @@ This package is still working in progress. More types would be added. Welcome an
- Ocean Fish - Ocean Fish
- Circle Loop2 - Circle Loop2
- Pixel Hole - Pixel Hole
- Dots Wave
For these kinds of art, the package provides as many parameters to control the appearance. 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) NewNoiseLine(n int)
NewCircleLoop2(depth int) NewCircleLoop2(depth int)
NewPixelHole(dotN int) NewPixelHole(dotN int)
NewDotsWave(dotsN int)
``` ```
## Docs ## Docs
@ -233,25 +235,28 @@ func main() {
![](images/pixelhole.png) ![](images/pixelhole.png)
### Silk Smoke ### Dots Wave
```go ```go
func main() { func main() {
rand.Seed(time.Now().Unix()) 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 := generativeart.NewCanva(500, 500)
c.SetBackground(generativeart.Black) c.SetBackground(common.Black)
c.SetLineWidth(1.0)
c.SetLineColor(generativeart.MediumAquamarine)
c.SetAlpha(30)
c.SetColorSchema(generativeart.Plasma)
c.SetIterations(4)
c.FillBackground() c.FillBackground()
c.Draw(generativeart.NewSilkSmoke(400, 20, 0.2, 2, 10, 30, false)) c.SetColorSchema(colors)
c.ToPNG("silksmoke.png") c.Draw(generativeart.NewDotsWave(300))
c.ToPNG("dotswave.png")
} }
``` ```
![](images/silksmoke.png) ![](images/dotswave.png)
### Contour Line ### Contour Line
@ -338,6 +343,26 @@ func main() {
![](images/oceanfish.png) ![](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 ### Circle Loop
```go ```go

View file

@ -150,4 +150,16 @@ cl := generativeart.NewCircleLoop2(7)
ph := generativeart.NewPixelHole(60) ph := generativeart.NewPixelHole(60)
``` ```
![](../images/pixelhole.png) ![](../images/pixelhole.png)
## Dots Wave
### parameters
- dotsN: The number of dots wave in the image.
```go
d := generativeart.NewDotsWave(300)
```
![](../images/dotswave.png)

48
dotswave.go Normal file
View file

@ -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()
}
}

View file

@ -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")
}

BIN
images/dotswave.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

View file

@ -23,7 +23,6 @@ func NewPixelHole(dotN int) *pixelHole {
// Generative draws a pixel hole images. // Generative draws a pixel hole images.
func (p *pixelHole) Generative(c *canva) { func (p *pixelHole) Generative(c *canva) {
ctex := gg.NewContextForRGBA(c.img) 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 { for i := 0.0; i < float64(c.opts.nIters); i += 1.0 {
ctex.Push() ctex.Push()
ctex.Translate(float64(c.width)/2, float64(c.height)/2) ctex.Translate(float64(c.width)/2, float64(c.height)/2)