Skip to content

Commit

Permalink
add the black hole
Browse files Browse the repository at this point in the history
  • Loading branch information
Yongwei Xing committed Mar 19, 2021
1 parent 4d34123 commit 28ac3ae
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 2 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions arts/blackhole.go
Original file line number Diff line number Diff line change
@@ -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()
}
}
20 changes: 18 additions & 2 deletions docs/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
![](../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 changes: 21 additions & 0 deletions example/example_blackhole.go
Original file line number Diff line number Diff line change
@@ -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")
}
Binary file added images/blackhole.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 28ac3ae

Please sign in to comment.