-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0_2_draw_pixels.dart
38 lines (31 loc) · 931 Bytes
/
0_2_draw_pixels.dart
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
import 'dart:io';
import 'dart:math';
import 'package:image/image.dart';
import 'openfile.dart';
/**
* Create and populate an image with random pixels.
* Save it as a PNG.
* Open it via the default Mac app.
*/
void main() {
const width = 640;
const height = 480;
const maxColourValue = 256;
Image image = Image(width, height);
var rnd = Random();
fill(image, getColor(255, 255, 255));
// Image is prepped - draw!
for (var x = 0; x < width; x++) {
for (var y = 0; y < height; y++) {
var r = rnd.nextInt(maxColourValue);
var g = rnd.nextInt(maxColourValue);
var b = rnd.nextInt(maxColourValue);
drawPixel(image, x, y, getColor(r, g, b));
}
}
// Done Drawing, now save it.
List<int> png = encodePng(image);
new File('output_randompixels.png').writeAsBytesSync(png);
// Open the file in the Mac previewer
OpenFile().openFileInPreview('output_randompixels.png');
}