add more control for domain warping

This commit is contained in:
Yongwei Xing 2021-03-30 17:10:04 +08:00
parent 471e3eb992
commit ed10f4403d
3 changed files with 14 additions and 12 deletions

View file

@ -122,7 +122,7 @@ NewCircleNoise(dotsN, colorMin, colorMax int)
NewYarn(n int)
NewBlackHole(circleN int, density, circleGap float64)
NewColorCanve(seg float64)
NewDomainWrap(scale, xOffset, yOffset float64, cmap ColorMapping)
NewDomainWrap(scale, scale2, xOffset, yOffset float64, cmap ColorMapping)
```
## Docs
@ -422,7 +422,7 @@ func main() {
```go
func cmap(r, m1, m2 float64) color.RGBA {
rgb := color.RGBA{
uint8(common.Constrain(m1*255*r, 0, 255)),
uint8(common.Constrain(m1*200*r, 0, 255)),
uint8(common.Constrain(r*200, 0, 255)),
uint8(common.Constrain(m2*255*r, 70, 255)),
255,
@ -435,7 +435,7 @@ func main() {
c := generativeart.NewCanva(500, 500)
c.SetBackground(common.Black)
c.FillBackground()
c.Draw(arts.NewDomainWrap(0.01, 4, 8, cmap))
c.Draw(arts.NewDomainWrap(0.01, 4,4, 20, cmap))
c.ToPNG("domainwarp.png")
}
```

View file

@ -12,14 +12,16 @@ type ColorMapping func(float64, float64, float64) color.RGBA
type domainWrap struct {
noise *common.PerlinNoise
scale float64
scale2 float64
xOffset, yOffset float64
fn ColorMapping
}
// NewDomainWrap returns a domainWrap object.
func NewDomainWrap(scale, xOffset, yOffset float64, cmap ColorMapping) *domainWrap {
func NewDomainWrap(scale, scale2, xOffset, yOffset float64, cmap ColorMapping) *domainWrap {
return &domainWrap{
scale: scale,
scale2: scale2,
xOffset: xOffset,
yOffset: yOffset,
noise: common.NewPerlinNoise(),
@ -43,10 +45,10 @@ func (d *domainWrap) pattern(x, y, xOffest, yOffset float64) (float64, float64,
qx := d.fbm(x+xOffest, y+yOffset)
qy := d.fbm(x+xOffest+5.2, y+yOffset+1.3)
rx := d.fbm(x+4.0*qx+1.7, y+4.0*qy+9.2)
ry := d.fbm(x+4.0*qx+8.3, y+4.0*qy+2.8)
rx := d.fbm(x+d.scale2*qx+1.7, y+d.scale2*qy+9.2)
ry := d.fbm(x+d.scale2*qx+8.3, y+d.scale2*qy+2.8)
return d.fbm(qx+4*rx, qy+4*ry), common.Magnitude(qx, qy), common.Magnitude(rx, ry)
return d.fbm(qx+d.scale2*rx, qy+d.scale2*ry), common.Magnitude(qx, qy), common.Magnitude(rx, ry)
}
func (d *domainWrap) fbm(x, y float64) float64 {

View file

@ -11,10 +11,10 @@ import (
func cmap(r, m1, m2 float64) color.RGBA {
rgb := color.RGBA{
uint8(common.Constrain(m1*255*r, 0, 255)),
uint8(common.Constrain(r*200, 0, 255)),
uint8(common.Constrain(m2*255*r, 70, 255)),
255,
R: uint8(common.Constrain(m1*200*r, 0, 255)),
G: uint8(common.Constrain(r*200, 0, 255)),
B: uint8(common.Constrain(m2*255*r, 70, 255)),
A: 255,
}
return rgb
}
@ -24,6 +24,6 @@ func main() {
c := generativeart.NewCanva(500, 500)
c.SetBackground(common.Black)
c.FillBackground()
c.Draw(arts.NewDomainWrap(0.01, 4, 8, cmap))
c.Draw(arts.NewDomainWrap(0.01, 4,4, 20, cmap))
c.ToPNG("domainwarp.png")
}