add yarn; update readme

This commit is contained in:
Yongwei Xing 2021-03-18 13:26:55 +08:00
parent dd0fb2f4d7
commit 4d34123c4a
5 changed files with 135 additions and 20 deletions

View file

@ -71,6 +71,7 @@ This package is still working in progress. More types would be added. Welcome an
- Dots Wave - Dots Wave
- Circle Move - Circle Move
- Circle Noise - Circle Noise
- Yarn
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.
@ -107,6 +108,7 @@ NewPixelHole(dotN int)
NewDotsWave(dotsN int) NewDotsWave(dotsN int)
NewCircleMove(circleNum int) NewCircleMove(circleNum int)
NewCircleNoise(dotsN, colorMin, colorMax int) NewCircleNoise(dotsN, colorMin, colorMax int)
NewYarn(n int)
``` ```
## Docs ## Docs
@ -137,6 +139,8 @@ For those parameters specified for different kinds of art types, they have their
## Usage and example ## Usage and example
Below are some selective examples. For more examples, you could check the example folder.
### Junas ### Junas
```go ```go

44
arts/yarn.go Normal file
View file

@ -0,0 +1,44 @@
package arts
import (
"github.com/fogleman/gg"
"github.com/jdxyw/generativeart"
"github.com/jdxyw/generativeart/common"
)
type yarn struct {
n int
}
// NewYarn returns a yarn object.
func NewYarn(n int) *yarn {
return &yarn{
n: n,
}
}
// Generative draws a yarn image.
func (y *yarn) Generative(c *generativeart.Canva) {
ctex := gg.NewContextForRGBA(c.Img())
ctex.SetLineWidth(c.Opts().LineWidth())
ctex.SetColor(c.Opts().LineColor())
noise := common.NewPerlinNoise()
var offset = 0.0
var inc = 0.005
for i := 0; i < y.n; i++ {
x0 := float64(c.Width()) * noise.Noise1D(offset+15)
x1 := float64(c.Width()) * noise.Noise1D(offset+25)
x2 := float64(c.Width()) * noise.Noise1D(offset+35)
x3 := float64(c.Width()) * noise.Noise1D(offset+45)
y0 := float64(c.Height()) * noise.Noise1D(offset+55)
y1 := float64(c.Height()) * noise.Noise1D(offset+65)
y2 := float64(c.Height()) * noise.Noise1D(offset+75)
y3 := float64(c.Height()) * noise.Noise1D(offset+85)
ctex.MoveTo(x0, y0)
ctex.CubicTo(x1, y1, x2, y2, x3, y3)
ctex.Stroke()
ctex.ClearPath()
offset += inc
}
}

View file

@ -1,3 +1,37 @@
# Table of Contents
- [Table of Contents](#table-of-contents)
- [Color Circle 2](#color-circle-2)
- [parameters](#parameters)
- [Dot Line](#dot-line)
- [parameters](#parameters-1)
- [Random Shape](#random-shape)
- [parameters](#parameters-2)
- [Janus](#janus)
- [TODO](#todo)
- [parameters](#parameters-3)
- [Contour Line](#contour-line)
- [parameters](#parameters-4)
- [Silk Sky](#silk-sky)
- [parameters](#parameters-5)
- [Julia](#julia)
- [parameters](#parameters-6)
- [Noise Line](#noise-line)
- [parameters](#parameters-7)
- [Ocean Fish](#ocean-fish)
- [parameters](#parameters-8)
- [Circle Loop2](#circle-loop2)
- [parameters](#parameters-9)
- [Pixel Hole](#pixel-hole)
- [parameters](#parameters-10)
- [Dots Wave](#dots-wave)
- [parameters](#parameters-11)
- [Circle Move](#circle-move)
- [parameters](#parameters-12)
- [Circle Noise](#circle-noise)
- [parameters](#parameters-13)
- [Yarn](#yarn)
- [parameters](#parameters-14)
## Color Circle 2 ## Color Circle 2
`Color Circle2` is version 2 of `Color Circle`. It still draws the circle and point cloud. `Color Circle2` is version 2 of `Color Circle`. It still draws the circle and point cloud.
@ -7,7 +41,7 @@
- circleNum: The number of the circle in this drawing. - circleNum: The number of the circle in this drawing.
```go ```go
cc := generativeart.NewColorCircle2(30) cc := arts.NewColorCircle2(30)
``` ```
![](../images/colorcircle2.png) ![](../images/colorcircle2.png)
@ -23,7 +57,7 @@ cc := generativeart.NewColorCircle2(30)
- randColor: Use the specified color or random colors. - randColor: Use the specified color or random colors.
```go ```go
dl := generativeart.NewDotLine(100, 20, 50, false) dl := arts.NewDotLine(100, 20, 50, false)
``` ```
![](../images/dotline.png) ![](../images/dotline.png)
@ -90,7 +124,7 @@ func julia1(z complex128) complex128 {
z = z*z + c z = z*z + c
return z return z
} }
julia := generativeart.NewJulia(julia1, 40, 1.5, 1.5) julia := arts.NewJulia(julia1, 40, 1.5, 1.5)
``` ```
![](../images/julia.png) ![](../images/julia.png)
@ -104,7 +138,7 @@ julia := generativeart.NewJulia(julia1, 40, 1.5, 1.5)
- n: The number of random line. - n: The number of random line.
```go ```go
nl := generativeart.NewNoiseLine(1000) nl := arts.NewNoiseLine(1000)
``` ```
![](../images/noiseline.png) ![](../images/noiseline.png)
@ -119,7 +153,7 @@ nl := generativeart.NewNoiseLine(1000)
- fishNum: The number of fish. - fishNum: The number of fish.
```go ```go
o := generativeart.NewOceanFish(100, 8) o := arts.NewOceanFish(100, 8)
``` ```
![](../images/oceanfish.png) ![](../images/oceanfish.png)
@ -133,7 +167,7 @@ o := generativeart.NewOceanFish(100, 8)
- depth: Control the number of circles. - depth: Control the number of circles.
```go ```go
cl := generativeart.NewCircleLoop2(7) cl := arts.NewCircleLoop2(7)
``` ```
![](../images/colorloop2.png) ![](../images/colorloop2.png)
@ -147,7 +181,7 @@ cl := generativeart.NewCircleLoop2(7)
- dotN: The number of point in each iteration. - dotN: The number of point in each iteration.
```go ```go
ph := generativeart.NewPixelHole(60) ph := arts.NewPixelHole(60)
``` ```
![](../images/pixelhole.png) ![](../images/pixelhole.png)
@ -159,7 +193,7 @@ ph := generativeart.NewPixelHole(60)
- dotsN: The number of dots wave in the image. - dotsN: The number of dots wave in the image.
```go ```go
d := generativeart.NewDotsWave(300) d := arts.NewDotsWave(300)
``` ```
![](../images/dotswave.png) ![](../images/dotswave.png)
@ -172,12 +206,12 @@ d := generativeart.NewDotsWave(300)
```go ```go
cm := generativeart.NewCircleMove(1000) cm := arts.NewCircleMove(1000)
``` ```
![](../images/circlemove.png) ![](../images/circlemove.png)
### Circle Noise ## Circle Noise
### parameters ### parameters
@ -186,3 +220,15 @@ cm := generativeart.NewCircleMove(1000)
- colorMax: The maximum color. - colorMax: The maximum color.
![](../images/circlenoise.png) ![](../images/circlenoise.png)
## Yarn
### parameters
- n: The number of curve.
```go
y := arts.NewYarn(2000)
```
![](../images/yarn.png)

21
example/example_yarn.go Normal file
View file

@ -0,0 +1,21 @@
package main
import (
"github.com/jdxyw/generativeart"
"github.com/jdxyw/generativeart/arts"
"github.com/jdxyw/generativeart/common"
"image/color"
"math/rand"
"time"
)
func main() {
rand.Seed(time.Now().Unix())
c := generativeart.NewCanva(500, 500)
c.SetBackground(common.Orange)
c.FillBackground()
c.SetLineWidth(0.3)
c.SetLineColor(color.RGBA{A: 60})
c.Draw(arts.NewYarn(2000))
c.ToPNG("yarn.png")
}

BIN
images/yarn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB