diff --git a/README.md b/README.md index 93fa070..d8ae8fe 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ - [Circle Loop](#circle-loop) - [Circle Noise](#circle-noise) - [Julia Set](#julia-set) + - [Black Hole](#black-hole) - [Silk Sky](#silk-sky) - [Circle Move](#circle-move) - [Random Circle](#random-circle) @@ -72,6 +73,7 @@ This package is still working in progress. More types would be added. Welcome an - Circle Move - Circle Noise - Yarn +- Black Hole For these kinds of art, the package provides as many parameters to control the appearance. @@ -109,6 +111,7 @@ NewDotsWave(dotsN int) NewCircleMove(circleNum int) NewCircleNoise(dotsN, colorMin, colorMax int) NewYarn(n int) +NewBlackHole(circleN int, density, circleGap float64) ``` ## Docs @@ -445,6 +448,23 @@ func main() { ![](images/julia.png) +### Black Hole + +```go +func main() { + rand.Seed(time.Now().Unix()) + c := generativeart.NewCanva(500, 500) + c.SetBackground(color.RGBA{R: 30, G: 30, B: 30, A: 255}) + c.FillBackground() + c.SetLineWidth(1.0) + c.SetLineColor(common.Tomato) + c.Draw(arts.NewBlackHole(200, 400, 0.01)) + c.ToPNG("blackhole.png") +} +``` + +![](images/blackhole.png) + ### Silk Sky ```go diff --git a/arts/blackhole.go b/arts/blackhole.go new file mode 100644 index 0000000..da6f528 --- /dev/null +++ b/arts/blackhole.go @@ -0,0 +1,50 @@ +package arts + +import ( + "github.com/fogleman/gg" + "github.com/jdxyw/generativeart" + "github.com/jdxyw/generativeart/common" + "math" +) + +type blackHole struct { + circleN int + density float64 + circleGap float64 +} + +// NewBlackHole returns a blackhole object. +func NewBlackHole(circleN int, density, circleGap float64) *blackHole { + return &blackHole{ + circleN: circleN, + density: density, + circleGap: circleGap, + } +} + +// Generative draws a black hole image. +func (b *blackHole) Generative(c *generativeart.Canva) { + ctex := gg.NewContextForRGBA(c.Img()) + noise := common.NewPerlinNoise() + kMax := common.RandomRangeFloat64(0.5, 1) + ctex.SetLineWidth(0.4) + ctex.SetColor(c.Opts().LineColor()) + + for i := 0; i < b.circleN; i++ { + radius := float64(c.Width()/10) + float64(i)*0.05 + k := kMax * math.Sqrt(float64(i)/float64(b.circleN)) + noisiness := b.density * math.Pow(float64(i)/float64(b.circleN), 2) + + for theta := 0.0; theta < 361; theta += 1.0 { + r1 := math.Cos(gg.Radians(theta)) + 1 + r2 := math.Sin(gg.Radians(theta)) + 1 + r := radius + noise.Noise3D(k*r1, k*r2, float64(i)*b.circleGap)*noisiness + + x := float64(c.Width())/2 + r*math.Cos(gg.Radians(theta)) + y := float64(c.Height()/2) + r*math.Sin(gg.Radians(theta)) + ctex.LineTo(x, y) + } + ctex.Stroke() + ctex.ClearPath() + } +} diff --git a/docs/doc.md b/docs/doc.md index bcd674e..5fb0650 100644 --- a/docs/doc.md +++ b/docs/doc.md @@ -32,6 +32,8 @@ - [parameters](#parameters-13) - [Yarn](#yarn) - [parameters](#parameters-14) + - [Black Hole](#black-hole) + - [parameters](#parameters-15) ## Color Circle 2 `Color Circle2` is version 2 of `Color Circle`. It still draws the circle and point cloud. @@ -225,10 +227,24 @@ cm := arts.NewCircleMove(1000) ### parameters -- n: The number of curve. +- n: The number of the curve. ```go y := arts.NewYarn(2000) ``` -![](../images/yarn.png) \ No newline at end of file +![](../images/yarn.png) + +## Black Hole + +### parameters + +- circleN: The number of the circle. +- density: Control the density of the circle. +- circleGap: Identify the gap between two circles. + +```go +b := arts.NewBlackHole(200, 400, 0.01) +``` + +![](../images/blackhole.png) \ No newline at end of file diff --git a/example/example_blackhole.go b/example/example_blackhole.go new file mode 100644 index 0000000..b0a6ccc --- /dev/null +++ b/example/example_blackhole.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(color.RGBA{R: 30, G: 30, B: 30, A: 255}) + c.FillBackground() + c.SetLineWidth(1.0) + c.SetLineColor(common.Tomato) + c.Draw(arts.NewBlackHole(200, 400, 0.01)) + c.ToPNG("blackhole.png") +} diff --git a/images/blackhole.png b/images/blackhole.png new file mode 100644 index 0000000..8d962cc Binary files /dev/null and b/images/blackhole.png differ