diff --git a/README.md b/README.md index 0c240ab..93fa070 100644 --- a/README.md +++ b/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") } ``` diff --git a/arts/yarn.go b/arts/yarn.go new file mode 100644 index 0000000..04b8b34 --- /dev/null +++ b/arts/yarn.go @@ -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 + } +} diff --git a/docs/doc.md b/docs/doc.md index 59e61cd..bcd674e 100644 --- a/docs/doc.md +++ b/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) \ No newline at end of file +![](../images/circlenoise.png) + +## Yarn + +### parameters + +- n: The number of curve. + +```go +y := arts.NewYarn(2000) +``` + +![](../images/yarn.png) \ No newline at end of file diff --git a/example/example_yarn.go b/example/example_yarn.go new file mode 100644 index 0000000..8df7794 --- /dev/null +++ b/example/example_yarn.go @@ -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") +} diff --git a/images/yarn.png b/images/yarn.png new file mode 100644 index 0000000..fb03c24 Binary files /dev/null and b/images/yarn.png differ