add point ribbon
This commit is contained in:
parent
802f3c5a17
commit
f529917c67
6 changed files with 91 additions and 18 deletions
46
README.md
46
README.md
|
@ -161,6 +161,37 @@ func main() {
|
|||
|
||||
![](images/julia.png)
|
||||
|
||||
### Silk Sky
|
||||
|
||||
```go
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(600, 600)
|
||||
c.SetAlpha(10)
|
||||
c.Draw(generativeart.NewSilkSky(15, 5))
|
||||
c.ToPNG("silksky.png")
|
||||
}
|
||||
```
|
||||
|
||||
![](images/silksky.png)
|
||||
|
||||
### Point Ribbon
|
||||
|
||||
```go
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(500, 500)
|
||||
c.SetBackground(generativeart.Lavender)
|
||||
c.SetLineWidth(2)
|
||||
c.SetIterations(150000)
|
||||
c.FillBackground()
|
||||
c.Draw(generativeart.NewPointRibbon(50))
|
||||
c.ToPNG("pointribbon.png")
|
||||
}
|
||||
```
|
||||
|
||||
![](images/pointribbon.png)
|
||||
|
||||
### Swirl
|
||||
|
||||
```go
|
||||
|
@ -195,20 +226,6 @@ func main() {
|
|||
|
||||
![](images/circleline.png)
|
||||
|
||||
### Silk Sky
|
||||
|
||||
```go
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(600, 600)
|
||||
c.SetAlpha(10)
|
||||
c.Draw(generativeart.NewSilkSky(15, 5))
|
||||
c.ToPNG("silksky.png")
|
||||
}
|
||||
```
|
||||
|
||||
![](images/silksky.png)
|
||||
|
||||
### Maze
|
||||
|
||||
```go
|
||||
|
@ -268,3 +285,4 @@ Thanks for the following sites and repos, I got lots of ideas, inspiration, code
|
|||
- http://blog.dragonlab.de/2015/03/generative-art-week-1
|
||||
- https://editor.p5js.org/kenekk1/sketches/Ly-5XYvKX
|
||||
- http://paulbourke.net/fractals/peterdejong/
|
||||
- https://editor.p5js.org/kenekk1/sketches/O44Dln5oo
|
||||
|
|
1
color.go
1
color.go
|
@ -22,6 +22,7 @@ var (
|
|||
Orange = color.RGBA{0xFF, 0xA5, 0x00, 0xFF}
|
||||
Black = color.RGBA{0x00, 0x00, 0x00, 0xFF}
|
||||
White = color.RGBA{0xFF, 0xFF, 0xFF, 0xFF}
|
||||
LightGray = color.RGBA{200, 200, 200, 255}
|
||||
Outdoors = []color.RGBA{
|
||||
{67, 110, 165, 255},
|
||||
{47, 76, 114, 255},
|
||||
|
|
18
example/example_pointribbon.go
Normal file
18
example/example_pointribbon.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/jdxyw/generativeart"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
c := generativeart.NewCanva(500, 500)
|
||||
c.SetBackground(generativeart.Lavender)
|
||||
c.SetLineWidth(2)
|
||||
c.SetIterations(150000)
|
||||
c.FillBackground()
|
||||
c.Draw(generativeart.NewPointRibbon(50))
|
||||
c.ToPNG("pointribbon.png")
|
||||
}
|
BIN
images/pointribbon.png
Normal file
BIN
images/pointribbon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 120 KiB |
36
pointRibbon.go
Normal file
36
pointRibbon.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package generativeart
|
||||
|
||||
import (
|
||||
"github.com/fogleman/gg"
|
||||
"math"
|
||||
)
|
||||
|
||||
type pointRibbon struct {
|
||||
r float64
|
||||
}
|
||||
|
||||
// NewPointRibbon returns a pointRibbon object.
|
||||
func NewPointRibbon(r float64) *pointRibbon {
|
||||
return &pointRibbon{
|
||||
r: r,
|
||||
}
|
||||
}
|
||||
|
||||
// Generative draws a point ribbon image.
|
||||
// TODO: make the point as parameters.
|
||||
func (s *pointRibbon) Generative(c *canva) {
|
||||
ctex := gg.NewContextForRGBA(c.img)
|
||||
ctex.SetLineWidth(c.opts.lineWidth)
|
||||
|
||||
var t float64
|
||||
var dt = 0.0001
|
||||
for i := 0; i < c.opts.nIters; i++ {
|
||||
delta := 2.0*s.r*math.Cos(4.0*dt*t) + s.r*math.Cos(t)
|
||||
ctex.SetRGBA255(int(delta), int(2*s.r*math.Sin(t)-s.r*math.Cos(3*dt*t)), 100, 10)
|
||||
ctex.DrawPoint(2*s.r*math.Sin(2*t*dt)+s.r*math.Cos(t*dt)+float64(c.width/2),
|
||||
2*s.r*math.Sin(t*dt)-s.r*math.Sin(5*t)+float64(c.height/2), 1.0)
|
||||
ctex.Stroke()
|
||||
t += 0.01
|
||||
dt += 0.1
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue