add the black hole
This commit is contained in:
parent
4d34123c4a
commit
28ac3ae4eb
5 changed files with 109 additions and 2 deletions
20
README.md
20
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
|
||||
|
|
50
arts/blackhole.go
Normal file
50
arts/blackhole.go
Normal file
|
@ -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()
|
||||
}
|
||||
}
|
18
docs/doc.md
18
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)
|
||||
|
||||
## 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)
|
21
example/example_blackhole.go
Normal file
21
example/example_blackhole.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(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")
|
||||
}
|
BIN
images/blackhole.png
Normal file
BIN
images/blackhole.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 292 KiB |
Loading…
Reference in a new issue