add color circle 2
This commit is contained in:
parent
fb7fc70a2f
commit
8afd28c7c7
5 changed files with 97 additions and 12 deletions
23
README.md
23
README.md
|
@ -24,6 +24,7 @@ This package is still working in progress, more types would be added. Welcome an
|
|||
- Janus
|
||||
- Random Shapes
|
||||
- Color Circle
|
||||
- Color Circle2
|
||||
|
||||
For these kinds of art, the package provides as many as parameters to control the appearance.
|
||||
|
||||
|
@ -51,6 +52,7 @@ NewPointRibbon(r float64)
|
|||
NewJanus(n int, decay float64)
|
||||
NewRandomShape(shapeNum int)
|
||||
NewColorCircle(circleNum int)
|
||||
NewColorCircle2(circleNum int)
|
||||
```
|
||||
|
||||
## General Options
|
||||
|
@ -117,25 +119,22 @@ func main() {
|
|||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
colors := []color.RGBA{
|
||||
{0xFF, 0xC6, 0x18, 0xFF},
|
||||
{0xF4, 0x25, 0x39, 0xFF},
|
||||
{0x41, 0x78, 0xF4, 0xFF},
|
||||
{0xFE, 0x84, 0xFE, 0xFF},
|
||||
{0xFF, 0x81, 0x19, 0xFF},
|
||||
{0x56, 0xAC, 0x51, 0xFF},
|
||||
{0x98, 0x19, 0xFA, 0xFF},
|
||||
{0xFF, 0xFF, 0xFF, 0xFF},
|
||||
{0x11, 0x60, 0xC6, 0xFF},
|
||||
{0xFD, 0xD9, 0x00, 0xFF},
|
||||
{0xF5, 0xB4, 0xF8, 0xFF},
|
||||
{0xEF, 0x13, 0x55, 0xFF},
|
||||
{0xF4, 0x9F, 0x0A, 0xFF},
|
||||
}
|
||||
c := generativeart.NewCanva(1000, 1000)
|
||||
c := generativeart.NewCanva(800, 800)
|
||||
c.SetBackground(generativeart.White)
|
||||
c.FillBackground()
|
||||
c.SetColorSchema(colors)
|
||||
c.Draw(generativeart.NewColorCircle(500))
|
||||
c.ToPNG("colorcircle.png")
|
||||
c.Draw(generativeart.NewColorCircle2(30))
|
||||
c.ToPNG("colorcircle2.png")
|
||||
}
|
||||
```
|
||||
|
||||
![](images/colorcircle.png)
|
||||
![](images/colorcircle2.png)
|
||||
|
||||
### Silk Smoke
|
||||
|
||||
|
|
61
colorcircle2.go
Normal file
61
colorcircle2.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
package generativeart
|
||||
|
||||
import (
|
||||
"github.com/fogleman/gg"
|
||||
"math"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
type colorCircle2 struct {
|
||||
circleNum int
|
||||
}
|
||||
|
||||
// NewColorCircle2 returns a colorCircle2 object.
|
||||
func NewColorCircle2(circleNum int) *colorCircle2 {
|
||||
return &colorCircle2{
|
||||
circleNum: circleNum,
|
||||
}
|
||||
}
|
||||
|
||||
// Generative draws a color circle image.
|
||||
func (cc *colorCircle2) Generative(c *canva) {
|
||||
ctex := gg.NewContextForRGBA(c.img)
|
||||
|
||||
for i := 0; i < cc.circleNum; i++ {
|
||||
x := RandomRangeFloat64(0, float64(c.width))
|
||||
y := RandomRangeFloat64(0, float64(c.height))
|
||||
|
||||
r1 := RandomRangeFloat64(50.0, float64(c.width)/4)
|
||||
r2 := RandomRangeFloat64(10.0, float64(c.width)/3)
|
||||
|
||||
cc.circle(ctex, c, x, y, r1, r2)
|
||||
if rand.Float64() < 0.3 {
|
||||
col := c.opts.colorSchema[rand.Intn(len(c.opts.colorSchema))]
|
||||
ctex.SetColor(col)
|
||||
ctex.DrawCircle(x, y, r1/2.0)
|
||||
ctex.Fill()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (cc *colorCircle2) circle(ctex *gg.Context, c *canva, x, y, d, dx float64) {
|
||||
col := c.opts.colorSchema[rand.Intn(len(c.opts.colorSchema))]
|
||||
|
||||
for j := 0.0; j < dx; j += 1.0 {
|
||||
dd := d + j*2.0
|
||||
alpha := int((dx / j) * 255.0)
|
||||
if alpha > 255 {
|
||||
alpha = 255
|
||||
}
|
||||
col.A = uint8(alpha)
|
||||
|
||||
ctex.SetColor(col)
|
||||
for i := 0; i < 150; i++ {
|
||||
theta := RandomRangeFloat64(0, math.Pi*2)
|
||||
xx := x + dd*0.5*math.Cos(theta)
|
||||
yy := y + dd*0.5*math.Sin(theta)
|
||||
ctex.DrawPoint(xx, yy, 0.51)
|
||||
ctex.Fill()
|
||||
}
|
||||
}
|
||||
}
|
25
example/example_colorcircle2.go
Normal file
25
example/example_colorcircle2.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/jdxyw/generativeart"
|
||||
"image/color"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
colors := []color.RGBA{
|
||||
{0x11, 0x60, 0xC6, 0xFF},
|
||||
{0xFD, 0xD9, 0x00, 0xFF},
|
||||
{0xF5, 0xB4, 0xF8, 0xFF},
|
||||
{0xEF, 0x13, 0x55, 0xFF},
|
||||
{0xF4, 0x9F, 0x0A, 0xFF},
|
||||
}
|
||||
c := generativeart.NewCanva(800, 800)
|
||||
c.SetBackground(generativeart.White)
|
||||
c.FillBackground()
|
||||
c.SetColorSchema(colors)
|
||||
c.Draw(generativeart.NewColorCircle2(30))
|
||||
c.ToPNG("colorcircle2.png")
|
||||
}
|
BIN
images/colorcircle2.png
Normal file
BIN
images/colorcircle2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 813 KiB |
Loading…
Reference in a new issue