add more control for domain warping
This commit is contained in:
parent
471e3eb992
commit
ed10f4403d
3 changed files with 14 additions and 12 deletions
|
@ -122,7 +122,7 @@ NewCircleNoise(dotsN, colorMin, colorMax int)
|
||||||
NewYarn(n int)
|
NewYarn(n int)
|
||||||
NewBlackHole(circleN int, density, circleGap float64)
|
NewBlackHole(circleN int, density, circleGap float64)
|
||||||
NewColorCanve(seg float64)
|
NewColorCanve(seg float64)
|
||||||
NewDomainWrap(scale, xOffset, yOffset float64, cmap ColorMapping)
|
NewDomainWrap(scale, scale2, xOffset, yOffset float64, cmap ColorMapping)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Docs
|
## Docs
|
||||||
|
@ -422,7 +422,7 @@ func main() {
|
||||||
```go
|
```go
|
||||||
func cmap(r, m1, m2 float64) color.RGBA {
|
func cmap(r, m1, m2 float64) color.RGBA {
|
||||||
rgb := 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(r*200, 0, 255)),
|
||||||
uint8(common.Constrain(m2*255*r, 70, 255)),
|
uint8(common.Constrain(m2*255*r, 70, 255)),
|
||||||
255,
|
255,
|
||||||
|
@ -435,7 +435,7 @@ func main() {
|
||||||
c := generativeart.NewCanva(500, 500)
|
c := generativeart.NewCanva(500, 500)
|
||||||
c.SetBackground(common.Black)
|
c.SetBackground(common.Black)
|
||||||
c.FillBackground()
|
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")
|
c.ToPNG("domainwarp.png")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -12,14 +12,16 @@ type ColorMapping func(float64, float64, float64) color.RGBA
|
||||||
type domainWrap struct {
|
type domainWrap struct {
|
||||||
noise *common.PerlinNoise
|
noise *common.PerlinNoise
|
||||||
scale float64
|
scale float64
|
||||||
|
scale2 float64
|
||||||
xOffset, yOffset float64
|
xOffset, yOffset float64
|
||||||
fn ColorMapping
|
fn ColorMapping
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDomainWrap returns a domainWrap object.
|
// 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{
|
return &domainWrap{
|
||||||
scale: scale,
|
scale: scale,
|
||||||
|
scale2: scale2,
|
||||||
xOffset: xOffset,
|
xOffset: xOffset,
|
||||||
yOffset: yOffset,
|
yOffset: yOffset,
|
||||||
noise: common.NewPerlinNoise(),
|
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)
|
qx := d.fbm(x+xOffest, y+yOffset)
|
||||||
qy := d.fbm(x+xOffest+5.2, y+yOffset+1.3)
|
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)
|
rx := d.fbm(x+d.scale2*qx+1.7, y+d.scale2*qy+9.2)
|
||||||
ry := d.fbm(x+4.0*qx+8.3, y+4.0*qy+2.8)
|
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 {
|
func (d *domainWrap) fbm(x, y float64) float64 {
|
||||||
|
|
|
@ -11,10 +11,10 @@ import (
|
||||||
|
|
||||||
func cmap(r, m1, m2 float64) color.RGBA {
|
func cmap(r, m1, m2 float64) color.RGBA {
|
||||||
rgb := color.RGBA{
|
rgb := color.RGBA{
|
||||||
uint8(common.Constrain(m1*255*r, 0, 255)),
|
R: uint8(common.Constrain(m1*200*r, 0, 255)),
|
||||||
uint8(common.Constrain(r*200, 0, 255)),
|
G: uint8(common.Constrain(r*200, 0, 255)),
|
||||||
uint8(common.Constrain(m2*255*r, 70, 255)),
|
B: uint8(common.Constrain(m2*255*r, 70, 255)),
|
||||||
255,
|
A: 255,
|
||||||
}
|
}
|
||||||
return rgb
|
return rgb
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,6 @@ func main() {
|
||||||
c := generativeart.NewCanva(500, 500)
|
c := generativeart.NewCanva(500, 500)
|
||||||
c.SetBackground(common.Black)
|
c.SetBackground(common.Black)
|
||||||
c.FillBackground()
|
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")
|
c.ToPNG("domainwarp.png")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue