1.生成灰度的曼德勃罗集图像代码示例,其中求根方程为y=x^2-1。
import (
"bufio"
"fmt"
"image"
"image/color"
"image/png"
"math/cmplx"
"os"
)
func main() {
const (
xmin, ymin, xmax, ymax = -2, -2, +2, +2
width, height = 2048, 2048
)
img := image.NewRGBA(image.Rect(0, 0, width, height))
// 使用image库返回image.Image接口的image.RGBA类型数据,width与height分别为新建图片的宽度和高度
for py := 0; py < height; py++ {
y := float64(py)/height*(ymax-ymin) + ymin // 转换为对应+2与-2区域的复平面点y坐标
for px := 0; px < width; px++ {
x := float64(px)/width*(xmax-xmin) + xmin // 转换为对应+2与-2区域的复平面点x坐标
z :=