1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
use cloudmap::cm3;
use cloudmap::cm3_arrow;
use cloudmap::cm3_blue;
use cloudmap::cm3_mud;
fn main() {
toimage_cm3();
toimage_arrow();
toimage_blue();
toimage_mud();
println!("Hello, world!");
}
fn toimage_arrow() {
let imgx = 100;
let imgy = 100;
let (ca, cb, cc, cd) = (1.0, 0.9, 0.41, 1.0);
let scalex = 3.0 / imgx as f32;
let scaley = 3.0 / imgy as f32;
let mut imgbuf = image::ImageBuffer::new(imgx, imgy);
for x in 0..imgx {
// print!(" {}", x);
for y in 0..imgy {
let pixel = imgbuf.get_pixel_mut(x, y);
let image::Rgba(data) = *pixel;
let mut cmv: [u32; 4] = [0, 0, 0, 0];
let mut u = 0.0;
let mut v = 0.0;
let ux = -0.950;
let vy = 0.050;
let vv = 0.2;
if imgx - y <= x {
// // print!(" up\n");
u = ((x as f64) * 2.0 - (imgx as f64)) / imgx as f64;
v = ((y as f64) * 2.0 - (imgx as f64)) / imgx as f64;
cmv = cm3_arrow(ux, vy, u, v, vv, 0.0, 12);
} else {
// print!(" down\n");
// u = 1.0 - ((y as f64)*1.0-0.5*(imgx as f64))/ imgx as f64;
// v = ((x as f64)*1.0-0.5*(imgx as f64))/ imgx as f64;
u = ((y as f64) * 2.0 - (imgx as f64)) / imgx as f64;
v = ((x as f64) * 2.0 - (imgx as f64)) / imgx as f64;
cmv = cm3_arrow(ux, vy, v, u, vv, 0.0, 12);
}
*pixel = image::Rgba([cmv[0] as u8, cmv[1] as u8, cmv[2] as u8, cmv[3] as u8]);
}
}
// Save the image as “fractal.png”, the format is deduced from the path
imgbuf.save("cm_arrow.png").unwrap();
}
fn toimage_cm3() {
let imgx = 100;
let imgy = 100;
// let (ca,cb,cc,cd)=(0.427,1.0,0.6069,0.41406);
let (ca, cb, cc, cd) = (1.0, 0.9, 0.0, 1.0);
let scalex = 3.0 / imgx as f32;
let scaley = 3.0 / imgy as f32;
// Create a new ImgBuf with width: imgx and height: imgy
let mut imgbuf = image::ImageBuffer::new(imgx, imgy);
// Iterate over the coordinates and pixels of the image
for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
// let r = (0.3 * x as f32) as u8;
// let b = (0.3 * y as f32) as u8;
*pixel = image::Rgba([0, 0, 0, 0]);
}
// A redundant loop to demonstrate reading image data
for x in 0..imgx - 1 {
// print!(" {}\n", x);
for y in 0..imgy - 1 {
let pixel = imgbuf.get_pixel_mut(x, y);
let image::Rgba(data) = *pixel;
let mut cmv = [0, 0, 0, 0];
let mut u = 0.0;
let mut v = 0.0;
if imgx - y <= x {
let u = x as f64 / imgx as f64;
let v = 1.0 - y as f64 / imgx as f64;
cmv = cm3(u, v, ca, cb, cc, 0.0, 12);
} else {
let u = 1.0 - y as f64 / imgx as f64;
let v = x as f64 / imgx as f64;
cmv = cm3(u, v, ca, cd, cc, 0.0, 12);
}
// print!("{} {} {} ,", cmv[0], cmv[1], cmv[2]);
*pixel = image::Rgba([cmv[0] as u8, cmv[1] as u8, cmv[2] as u8, cmv[3] as u8]);
}
}
// Save the image as “fractal.png”, the format is deduced from the path
imgbuf.save("cm.png").unwrap();
}
fn toimage_blue() {
let imgx = 100;
let imgy = 100;
// let (ca,cb,cc,cd)=(0.427,1.0,0.6069,0.41406);
let (ca, cb, cc, cd) = (1.0, 0.9, 0.0, 1.0);
let scalex = 3.0 / imgx as f32;
let scaley = 3.0 / imgy as f32;
// Create a new ImgBuf with width: imgx and height: imgy
let mut imgbuf = image::ImageBuffer::new(imgx, imgy);
// Iterate over the coordinates and pixels of the image
for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
// let r = (0.3 * x as f32) as u8;
// let b = (0.3 * y as f32) as u8;
*pixel = image::Rgba([0, 0, 0, 0]);
}
// A redundant loop to demonstrate reading image data
for x in 0..imgx - 1 {
// print!(" {}\n", x);
for y in 0..imgy - 1 {
let pixel = imgbuf.get_pixel_mut(x, y);
let image::Rgba(data) = *pixel;
let mut cmv = [0, 0, 0, 0];
let mut u = 0.0;
let mut v = 0.0;
if imgx - y <= x {
let u = x as f64 / imgx as f64;
let v = 1.0 - y as f64 / imgx as f64;
cmv = cm3_blue(u, v, ca, cb, cc, 0.0, 12);
} else {
let u = 1.0 - y as f64 / imgx as f64;
let v: f64 = x as f64 / imgx as f64;
cmv = cm3_blue(u, v, ca, cd, cc, 0.0, 12);
}
// print!("{} {} {} ,", cmv[0], cmv[1], cmv[2]);
*pixel = image::Rgba([cmv[0] as u8, cmv[1] as u8, cmv[2] as u8, cmv[3] as u8]);
}
}
// Save the image as “fractal.png”, the format is deduced from the path
imgbuf.save("cm_blue.png").unwrap();
}
fn toimage_mud() {
let imgx = 100;
let imgy = 100;
// let (ca,cb,cc,cd)=(0.427,1.0,0.6069,0.41406);
let (ca, cb, cc, cd) = (1.0, 0.9, 0.0, 1.0);
let scalex = 3.0 / imgx as f32;
let scaley = 3.0 / imgy as f32;
// Create a new ImgBuf with width: imgx and height: imgy
let mut imgbuf = image::ImageBuffer::new(imgx, imgy);
// Iterate over the coordinates and pixels of the image
for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
// let r = (0.3 * x as f32) as u8;
// let b = (0.3 * y as f32) as u8;
*pixel = image::Rgba([0, 0, 0, 0]);
}
// A redundant loop to demonstrate reading image data
for x in 0..imgx - 1 {
// print!(" {}\n", x);
for y in 0..imgy - 1 {
let pixel = imgbuf.get_pixel_mut(x, y);
let image::Rgba(data) = *pixel;
let mut cmv = [0, 0, 0, 0];
let mut u = 0.0;
let mut v = 0.0;
if imgx - y <= x {
let u = x as f64 / imgx as f64;
let v = 1.0 - y as f64 / imgx as f64;
cmv = cm3_mud(u, v, ca, cb, cc, 0.0, 12);
} else {
let u = 1.0 - y as f64 / imgx as f64;
let v = x as f64 / imgx as f64;
cmv = cm3_mud(u, v, ca, cd, cc, 0.0, 12);
}
// print!("{} {} {} ,", cmv[0], cmv[1], cmv[2]);
*pixel = image::Rgba([cmv[0] as u8, cmv[1] as u8, cmv[2] as u8, cmv[3] as u8]);
}
}
// Save the image as “fractal.png”, the format is deduced from the path
imgbuf.save("cm_mud.png").unwrap();
}