add some other colors

This commit is contained in:
Yongwei Xing 2021-02-26 17:23:56 +08:00
parent 86f6c84ad6
commit e6decd968c
4 changed files with 32 additions and 39 deletions

View file

@ -2,13 +2,24 @@ package generativeart
import "image/color"
var MistyRose = color.RGBA{0xFF, 0xE4, 0xE1, 0xFF}
var DarkSalmon = color.RGBA{0xE9, 0x96, 0x7A, 0xFF}
var Tan = color.RGBA{0xD2, 0xB4, 0x8C, 0xFF}
var Bisque = color.RGBA{0xFF, 0xE4, 0xC4, 0xFF}
var Mintcream = color.RGBA{0xF5, 0xFF, 0xFA, 0xFF}
var Aquamarine = color.RGBA{0x7F, 0xFF, 0xD4, 0xFF}
var Azure = color.RGBA{0xF0, 0xFF, 0xFF, 0xFF}
var Lavender = color.RGBA{0xE6, 0xE6, 0xFA, 0xFF}
var Plum = color.RGBA{0xDD, 0xA0, 0xDD, 0xFF}
var AntiqueWhite = color.RGBA{0xFA, 0xEB, 0xD7, 0xFF}
var (
MistyRose = color.RGBA{0xFF, 0xE4, 0xE1, 0xFF}
DarkSalmon = color.RGBA{0xE9, 0x96, 0x7A, 0xFF}
Tan = color.RGBA{0xD2, 0xB4, 0x8C, 0xFF}
Bisque = color.RGBA{0xFF, 0xE4, 0xC4, 0xFF}
Mintcream = color.RGBA{0xF5, 0xFF, 0xFA, 0xFF}
Aquamarine = color.RGBA{0x7F, 0xFF, 0xD4, 0xFF}
Azure = color.RGBA{0xF0, 0xFF, 0xFF, 0xFF}
Lavender = color.RGBA{0xE6, 0xE6, 0xFA, 0xFF}
Plum = color.RGBA{0xDD, 0xA0, 0xDD, 0xFF}
AntiqueWhite = color.RGBA{0xFA, 0xEB, 0xD7, 0xFF}
NavajoWhite = color.RGBA{0xFF, 0xDE, 0xAD, 0xFF}
Moccasin = color.RGBA{0xFF, 0xE4, 0xB5, 0xFF}
MediumAquamarine = color.RGBA{0x66, 0xCD, 0xAA, 0xFF}
PaleTurquoise = color.RGBA{0xAF, 0xEE, 0xEE, 0xFF}
LightPink = color.RGBA{0xFF, 0xB6, 0xC1, 0xFF}
Tomato = color.RGBA{0xFF, 0x63, 0x47, 0xFF}
Orange = color.RGBA{0xFF, 0xA5, 0x00, 0xFF}
Black = color.RGBA{0x00, 0x00, 0x00, 0xFF}
White = color.RGBA{0xFF, 0xFF, 0xFF, 0xFF}
)

View file

@ -6,14 +6,14 @@ import (
)
func formula1(x, y float64) (float64, float64) {
return -0.13*x*x - math.Sin(y*y) + math.Cos(x*y),
-0.96*y*y*y - math.Cos(x*x)
return 0.18*x*x - math.Sin(y*y),
0.059*y*y*y - math.Cos(x*x)
}
func main() {
c := generativeart.NewCanva(800, 800, 4, 4)
c.FillBackgroud(generativeart.AntiqueWhite)
c := generativeart.NewCanva(1600, 1600, 4, 4)
c.FillBackgroud(generativeart.Tomato)
g := generativeart.NewWave(formula1)
g.GenerativePolar(c, generativeart.DarkSalmon)
g.GenerativePolar(c, generativeart.Black)
c.ToPng("g1.png")
}

View file

@ -5,17 +5,8 @@ import "math"
func ConvertCartesianToPixel(x, y, xaixs, yaixs float64, h, w int) (int, int) {
xr, yr := x/xaixs, y/yaixs
var i, j int
if xr > 0 {
i = w/2 + int(float64(w)/2*xr)
} else {
i = w/2 + int(float64(w)/2*xr)
}
if yr > 0 {
j = h/2 + int(float64(h)/2*yr)
} else {
j = h/2 + int(float64(h)/2*yr)
}
i = w/2 + int(float64(w)/2*xr)
j = h/2 + int(float64(h)/2*yr)
return i, j
}
@ -37,17 +28,8 @@ func ConvertPolarToPixel(r, theta, xaixs, yaixs float64, h, w int) (int, int) {
xr, yr := x/xaixs, y/yaixs
var i, j int
if xr > 0 {
i = w/2 + int(float64(w)/2*xr)
} else {
i = w/2 + int(float64(w)/2*xr)
}
if yr > 0 {
j = h/2 + int(float64(h)/2*yr)
} else {
j = h/2 + int(float64(h)/2*yr)
}
i = w/2 + int(float64(w)/2*xr)
j = h/2 + int(float64(h)/2*yr)
return i, j
}

View file

@ -32,8 +32,8 @@ func (w *wave) GenerativePolar(c *canva, rgba color.RGBA) {
// Generative draws the image in cartesian coordinate system.
func (w *wave) Generative(c *canva, rgba color.RGBA) {
for x := -math.Pi; x <= math.Pi; x += 0.008 {
for y := -math.Pi; y <= math.Pi; y += 0.008 {
for x := -math.Pi; x <= math.Pi; x += 0.002 {
for y := -math.Pi; y <= math.Pi; y += 0.002 {
xi, yi := w.fn(x, y)
i, j := ConvertCartesianToPixel(xi, yi, c.xaixs, c.yaixs, c.height, c.width)
if i < 0 || i > c.width-1 || j < 0 || j > c.height-1 {