add noise lines
This commit is contained in:
parent
8738c34724
commit
97431251d7
7 changed files with 158 additions and 37 deletions
24
README.md
24
README.md
|
@ -27,6 +27,7 @@ This package is still working in progress. More types would be added. Welcome an
|
||||||
- Color Circle2
|
- Color Circle2
|
||||||
- Circle Grid
|
- Circle Grid
|
||||||
- Contour Line
|
- Contour Line
|
||||||
|
- Noise Line
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
@ -57,6 +58,7 @@ NewColorCircle(circleNum int)
|
||||||
NewColorCircle2(circleNum int)
|
NewColorCircle2(circleNum int)
|
||||||
NewCircleGrid(circleNumMin, circleNumMax int)
|
NewCircleGrid(circleNumMin, circleNumMax int)
|
||||||
NewContourLine(lineNum int)
|
NewContourLine(lineNum int)
|
||||||
|
NewNoiseLine(n int)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Docs
|
## Docs
|
||||||
|
@ -215,6 +217,28 @@ func main() {
|
||||||
|
|
||||||
![](images/contourline.png)
|
![](images/contourline.png)
|
||||||
|
|
||||||
|
### Noise Line
|
||||||
|
|
||||||
|
```go
|
||||||
|
func main() {
|
||||||
|
rand.Seed(time.Now().Unix())
|
||||||
|
colors := []color.RGBA{
|
||||||
|
{0x06, 0x7B, 0xC2, 0xFF},
|
||||||
|
{0x84, 0xBC, 0xDA, 0xFF},
|
||||||
|
{0xEC, 0xC3, 0x0B, 0xFF},
|
||||||
|
{0xF3, 0x77, 0x48, 0xFF},
|
||||||
|
{0xD5, 0x60, 0x62, 0xFF},
|
||||||
|
}
|
||||||
|
c := generativeart.NewCanva(1000, 1000)
|
||||||
|
c.SetBackground(color.RGBA{0xF0, 0xFE, 0xFF, 0xFF})
|
||||||
|
c.FillBackground()
|
||||||
|
c.SetColorSchema(colors)
|
||||||
|
c.Draw(generativeart.NewNoiseLine(1000))
|
||||||
|
c.ToPNG("noiseline.png")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
![](images/noiseline.png)
|
||||||
### Circle Loop
|
### Circle Loop
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
|
|
@ -21,7 +21,6 @@ func NewContourLine(lineNum int) *contourLine {
|
||||||
// Generative draws a contour line image.
|
// Generative draws a contour line image.
|
||||||
func (cl *contourLine) Generative(c *canva) {
|
func (cl *contourLine) Generative(c *canva) {
|
||||||
ctex := gg.NewContextForRGBA(c.img)
|
ctex := gg.NewContextForRGBA(c.img)
|
||||||
//noise := perlin.NewPerlin(2, 2, 3, rand.Int63())
|
|
||||||
noise := common.NewPerlinNoise()
|
noise := common.NewPerlinNoise()
|
||||||
for i := 0; i < cl.lineNum; i++ {
|
for i := 0; i < cl.lineNum; i++ {
|
||||||
cl := c.opts.colorSchema[rand.Intn(len(c.opts.colorSchema))]
|
cl := c.opts.colorSchema[rand.Intn(len(c.opts.colorSchema))]
|
||||||
|
|
14
docs/doc.md
14
docs/doc.md
|
@ -94,3 +94,17 @@ julia := generativeart.NewJulia(julia1, 40, 1.5, 1.5)
|
||||||
```
|
```
|
||||||
|
|
||||||
![](../images/julia.png)
|
![](../images/julia.png)
|
||||||
|
|
||||||
|
## Noise Line
|
||||||
|
|
||||||
|
`Noise Line` draws some random line and circles based on `perlin noise`.
|
||||||
|
|
||||||
|
### parameters
|
||||||
|
|
||||||
|
- n: The number of random line.
|
||||||
|
|
||||||
|
```go
|
||||||
|
nl := generativeart.NewNoiseLine(1000)
|
||||||
|
```
|
||||||
|
|
||||||
|
![](../images/noiseline.png)
|
25
example/example_noiseline.go
Normal file
25
example/example_noiseline.go
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jdxyw/generativeart"
|
||||||
|
"image/color"
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
rand.Seed(time.Now().Unix())
|
||||||
|
colors := []color.RGBA{
|
||||||
|
{0x06, 0x7B, 0xC2, 0xFF},
|
||||||
|
{0x84, 0xBC, 0xDA, 0xFF},
|
||||||
|
{0xEC, 0xC3, 0x0B, 0xFF},
|
||||||
|
{0xF3, 0x77, 0x48, 0xFF},
|
||||||
|
{0xD5, 0x60, 0x62, 0xFF},
|
||||||
|
}
|
||||||
|
c := generativeart.NewCanva(1000, 1000)
|
||||||
|
c.SetBackground(color.RGBA{0xF0, 0xFE, 0xFF, 0xFF})
|
||||||
|
c.FillBackground()
|
||||||
|
c.SetColorSchema(colors)
|
||||||
|
c.Draw(generativeart.NewNoiseLine(1000))
|
||||||
|
c.ToPNG("noiseline.png")
|
||||||
|
}
|
|
@ -1,41 +1,43 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "github.com/fogleman/gg"
|
||||||
"github.com/fogleman/gg"
|
|
||||||
"github.com/jdxyw/generativeart"
|
|
||||||
"github.com/llgcode/draw2d/draw2dimg"
|
|
||||||
"image"
|
|
||||||
"math/rand"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
const S = 400
|
//const S = 400
|
||||||
rand.Seed(time.Now().Unix())
|
//rand.Seed(time.Now().Unix())
|
||||||
dest := image.NewRGBA(image.Rect(0, 0, 500, 500))
|
//dest := image.NewRGBA(image.Rect(0, 0, 500, 500))
|
||||||
|
//
|
||||||
|
//ctex := gg.NewContextForRGBA(dest)
|
||||||
|
//ctex.Push()
|
||||||
|
//ctex.Translate(500/2, 500/2)
|
||||||
|
//ctex.Rotate(40)
|
||||||
|
//ctex.SetColor(color.RGBA{0xFF, 0x00, 0x00, 255})
|
||||||
|
//for theta :=0.0; theta<361.0; theta+=1.0 {
|
||||||
|
// x := 100*math.Cos(gg.Radians(theta)) - 100*math.Pow(math.Sin(gg.Radians(theta)), 2) / math.Sqrt(2)
|
||||||
|
// y := 100*math.Cos(gg.Radians(theta))*math.Sin(gg.Radians(theta))
|
||||||
|
//
|
||||||
|
// x1 := 100*math.Cos(gg.Radians(theta+1)) - 100*math.Pow(math.Sin(gg.Radians(theta+1)), 2) / math.Sqrt(2)
|
||||||
|
// y1 := 100*math.Cos(gg.Radians(theta+1))*math.Sin(gg.Radians(theta+1))
|
||||||
|
//
|
||||||
|
// ctex.DrawLine(x, y, x1, y1)
|
||||||
|
// ctex.Stroke()
|
||||||
|
//}
|
||||||
|
//ctex.Pop()
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//f, _ := os.Create("test.png")
|
||||||
|
//
|
||||||
|
//if err := png.Encode(f, dest); err != nil {
|
||||||
|
// f.Close()
|
||||||
|
//}
|
||||||
|
|
||||||
gc := draw2dimg.NewGraphicContext(dest)
|
dc := gg.NewContext(1000, 1000)
|
||||||
gc.SetStrokeColor(generativeart.Orange)
|
dc.DrawCircle(350, 500, 300)
|
||||||
gc.BeginPath()
|
dc.Clip()
|
||||||
gc.MoveTo(100, 100)
|
dc.DrawCircle(650, 500, 300)
|
||||||
gc.QuadCurveTo(150, 50, 200, 100)
|
dc.Clip()
|
||||||
//fmt.Println(gc.LastPoint())
|
dc.DrawRectangle(0, 0, 1000, 1000)
|
||||||
//gc.QuadCurveTo(200, 100, 300, 200)
|
dc.SetRGB(0, 0, 0)
|
||||||
gc.QuadCurveTo(250, 250, 200, 400)
|
dc.Fill()
|
||||||
gc.QuadCurveTo(100, 250, 100, 100)
|
dc.SavePNG("out.png")
|
||||||
//gc.QuadCurveTo(200, 400, 100, 10)
|
|
||||||
//gc.Close()
|
|
||||||
gc.Stroke()
|
|
||||||
|
|
||||||
ctex := gg.NewContextForRGBA(dest)
|
|
||||||
ctex.SetColor(generativeart.White)
|
|
||||||
//ctex.DrawCircle(100, 100, 5)
|
|
||||||
//ctex.DrawCircle(200, 400, 5)
|
|
||||||
//ctex.DrawCircle(200, 100, 5)
|
|
||||||
//ctex.DrawCircle(300, 200, 5)
|
|
||||||
//ctex.DrawCircle(200, 400, 5)
|
|
||||||
ctex.Fill()
|
|
||||||
//gc.FillStroke()
|
|
||||||
|
|
||||||
draw2dimg.SaveToPngFile("test.png", dest)
|
|
||||||
}
|
}
|
||||||
|
|
BIN
images/noiseline.png
Normal file
BIN
images/noiseline.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 336 KiB |
57
noiseline.go
Normal file
57
noiseline.go
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
package generativeart
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fogleman/gg"
|
||||||
|
"github.com/jdxyw/generativeart/common"
|
||||||
|
"math"
|
||||||
|
"math/rand"
|
||||||
|
)
|
||||||
|
|
||||||
|
type noiseLine struct {
|
||||||
|
n int
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewNoiseLine returns a noiseLine object.
|
||||||
|
func NewNoiseLine(n int) *noiseLine {
|
||||||
|
return &noiseLine{
|
||||||
|
n: n,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generative draws a noise line image.
|
||||||
|
func (nl *noiseLine) Generative(c *canva) {
|
||||||
|
ctex := gg.NewContextForRGBA(c.img)
|
||||||
|
noise := common.NewPerlinNoise()
|
||||||
|
|
||||||
|
ctex.SetColor(Black)
|
||||||
|
for i := 0; i < 80; i++ {
|
||||||
|
x := rand.Float64() * float64(c.width)
|
||||||
|
y := rand.Float64() * float64(c.height)
|
||||||
|
|
||||||
|
s := rand.Float64() * float64(c.width) / 8
|
||||||
|
ctex.SetLineWidth(0.5)
|
||||||
|
ctex.DrawEllipse(x, y, s, s)
|
||||||
|
ctex.Stroke()
|
||||||
|
}
|
||||||
|
|
||||||
|
t := rand.Float64() * 10
|
||||||
|
for i := 0; i < nl.n; i++ {
|
||||||
|
x := common.RandomRangeFloat64(-0.5, 1.5) * float64(c.width)
|
||||||
|
y := common.RandomRangeFloat64(-0.5, 1.5) * float64(c.height)
|
||||||
|
cl := c.opts.colorSchema[rand.Intn(len(c.opts.colorSchema))]
|
||||||
|
cl.A = uint8(c.opts.alpha)
|
||||||
|
|
||||||
|
l := 400
|
||||||
|
for j := 0; j < l; j++ {
|
||||||
|
var ns = 0.0005
|
||||||
|
w := math.Sin(math.Pi*float64(j)/float64(l-1)) * 5
|
||||||
|
theta := noise.Noise(x*ns, y*ns, t) * 100
|
||||||
|
ctex.SetColor(cl)
|
||||||
|
ctex.DrawCircle(x, y, w)
|
||||||
|
ctex.Fill()
|
||||||
|
x += math.Cos(theta)
|
||||||
|
y += math.Sin(theta)
|
||||||
|
t += 0.0000003
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue