-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yongwei Xing
committed
Mar 19, 2021
1 parent
4d34123
commit 28ac3ae
Showing
5 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.