add yarn; update readme
This commit is contained in:
parent
dd0fb2f4d7
commit
4d34123c4a
5 changed files with 135 additions and 20 deletions
22
README.md
22
README.md
|
@ -71,6 +71,7 @@ This package is still working in progress. More types would be added. Welcome an
|
|||
- Dots Wave
|
||||
- Circle Move
|
||||
- Circle Noise
|
||||
- Yarn
|
||||
|
||||
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)
|
||||
NewCircleMove(circleNum int)
|
||||
NewCircleNoise(dotsN, colorMin, colorMax int)
|
||||
NewYarn(n int)
|
||||
```
|
||||
|
||||
## Docs
|
||||
|
@ -137,6 +139,8 @@ For those parameters specified for different kinds of art types, they have their
|
|||
|
||||
## Usage and example
|
||||
|
||||
Below are some selective examples. For more examples, you could check the example folder.
|
||||
|
||||
### Junas
|
||||
|
||||
```go
|
||||
|
@ -403,15 +407,15 @@ func main() {
|
|||
|
||||
```go
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(500, 500)
|
||||
c.SetBackground(common.White)
|
||||
c.SetAlpha(80)
|
||||
c.SetLineWidth(0.3)
|
||||
c.FillBackground()
|
||||
c.SetIterations(400)
|
||||
c.Draw(arts.NewCircleNoise(2000, 60, 80))
|
||||
c.ToPNG("circlenoise.png")
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(500, 500)
|
||||
c.SetBackground(common.White)
|
||||
c.SetAlpha(80)
|
||||
c.SetLineWidth(0.3)
|
||||
c.FillBackground()
|
||||
c.SetIterations(400)
|
||||
c.Draw(arts.NewCircleNoise(2000, 60, 80))
|
||||
c.ToPNG("circlenoise.png")
|
||||
}
|
||||
```
|
||||
|
||||
|
|
44
arts/yarn.go
Normal file
44
arts/yarn.go
Normal 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
|
||||
}
|
||||
}
|
68
docs/doc.md
68
docs/doc.md
|
@ -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 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.
|
||||
|
||||
```go
|
||||
cc := generativeart.NewColorCircle2(30)
|
||||
cc := arts.NewColorCircle2(30)
|
||||
```
|
||||
|
||||
![](../images/colorcircle2.png)
|
||||
|
@ -23,7 +57,7 @@ cc := generativeart.NewColorCircle2(30)
|
|||
- randColor: Use the specified color or random colors.
|
||||
|
||||
```go
|
||||
dl := generativeart.NewDotLine(100, 20, 50, false)
|
||||
dl := arts.NewDotLine(100, 20, 50, false)
|
||||
```
|
||||
|
||||
![](../images/dotline.png)
|
||||
|
@ -90,7 +124,7 @@ func julia1(z complex128) complex128 {
|
|||
z = z*z + c
|
||||
return z
|
||||
}
|
||||
julia := generativeart.NewJulia(julia1, 40, 1.5, 1.5)
|
||||
julia := arts.NewJulia(julia1, 40, 1.5, 1.5)
|
||||
```
|
||||
|
||||
![](../images/julia.png)
|
||||
|
@ -104,7 +138,7 @@ julia := generativeart.NewJulia(julia1, 40, 1.5, 1.5)
|
|||
- n: The number of random line.
|
||||
|
||||
```go
|
||||
nl := generativeart.NewNoiseLine(1000)
|
||||
nl := arts.NewNoiseLine(1000)
|
||||
```
|
||||
|
||||
![](../images/noiseline.png)
|
||||
|
@ -119,7 +153,7 @@ nl := generativeart.NewNoiseLine(1000)
|
|||
- fishNum: The number of fish.
|
||||
|
||||
```go
|
||||
o := generativeart.NewOceanFish(100, 8)
|
||||
o := arts.NewOceanFish(100, 8)
|
||||
```
|
||||
|
||||
![](../images/oceanfish.png)
|
||||
|
@ -133,7 +167,7 @@ o := generativeart.NewOceanFish(100, 8)
|
|||
- depth: Control the number of circles.
|
||||
|
||||
```go
|
||||
cl := generativeart.NewCircleLoop2(7)
|
||||
cl := arts.NewCircleLoop2(7)
|
||||
```
|
||||
|
||||
![](../images/colorloop2.png)
|
||||
|
@ -147,7 +181,7 @@ cl := generativeart.NewCircleLoop2(7)
|
|||
- dotN: The number of point in each iteration.
|
||||
|
||||
```go
|
||||
ph := generativeart.NewPixelHole(60)
|
||||
ph := arts.NewPixelHole(60)
|
||||
```
|
||||
|
||||
![](../images/pixelhole.png)
|
||||
|
@ -159,7 +193,7 @@ ph := generativeart.NewPixelHole(60)
|
|||
- dotsN: The number of dots wave in the image.
|
||||
|
||||
```go
|
||||
d := generativeart.NewDotsWave(300)
|
||||
d := arts.NewDotsWave(300)
|
||||
```
|
||||
|
||||
![](../images/dotswave.png)
|
||||
|
@ -172,12 +206,12 @@ d := generativeart.NewDotsWave(300)
|
|||
|
||||
|
||||
```go
|
||||
cm := generativeart.NewCircleMove(1000)
|
||||
cm := arts.NewCircleMove(1000)
|
||||
```
|
||||
|
||||
![](../images/circlemove.png)
|
||||
|
||||
### Circle Noise
|
||||
## Circle Noise
|
||||
|
||||
### parameters
|
||||
|
||||
|
@ -185,4 +219,16 @@ cm := generativeart.NewCircleMove(1000)
|
|||
- colorMin: The minimum 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
21
example/example_yarn.go
Normal 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
BIN
images/yarn.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 107 KiB |
Loading…
Reference in a new issue