-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.c
43 lines (32 loc) · 896 Bytes
/
example.c
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
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#define IMPORT_PERLIN
#include "perlin.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <stdint.h>
#define WIDTH 700
#define HIGHT 300
int main(){
srand(time(NULL));
uint8_t pixels[WIDTH * HIGHT * 3];
int index = 0;
uint8_t r = 0;
uint8_t g = 0;
uint8_t b = 0;
int value = 0;
perlinSEED = (int) time(NULL);
for(int i = 0; i < HIGHT; i++){
for(int j = 0; j < WIDTH; j++){
value = round(perlin(i, j, 0.01, 2, true) * 255);
//value = round(value / 20) * 20; /* Try uncommenting this */
pixels[index++] = value;
pixels[index++] = value;
pixels[index++] = value;
}
}
stbi_write_png("perlin.png", WIDTH, HIGHT, 3, &pixels, WIDTH * 3);
return 0;
}