diff --git a/README.md b/README.md index 930e94c..5452cf6 100644 --- a/README.md +++ b/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 diff --git a/colorCircle.go b/colorcircle.go similarity index 100% rename from colorCircle.go rename to colorcircle.go diff --git a/colorcircle2.go b/colorcircle2.go new file mode 100644 index 0000000..d7f4cb7 --- /dev/null +++ b/colorcircle2.go @@ -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() + } + } +} diff --git a/example/example_colorcircle2.go b/example/example_colorcircle2.go new file mode 100644 index 0000000..bd778f7 --- /dev/null +++ b/example/example_colorcircle2.go @@ -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") +} diff --git a/images/colorcircle2.png b/images/colorcircle2.png new file mode 100644 index 0000000..5a8a412 Binary files /dev/null and b/images/colorcircle2.png differ