Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float map[][], light[][];
- PShape tile;
- int scale = 5;
- void setup() {
- size(800, 600, P2D);
- noStroke();
- tile = createShape(RECT, 0, 0, scale, scale);
- map = new float[width / scale][height / scale];
- light = new float[width / scale][height / scale];
- for (int y = 0; y < height / scale; y++) { // generate random map
- for (int x = 0; x < width / scale; x++) {
- map[x][y] = noise(x * 0.05, y * 0.05);
- light[x][y] = 0;
- }
- }
- }
- void draw() {
- // background(0, 0, 50);
- updateLight();
- for (int y = 0; y < height / scale; y++) {
- for (int x = 0; x < width / scale; x++) {
- pushMatrix();
- translate(x * scale, y * scale);
- tile.setFill(color(map[x][y] * light[x][y] * 255));
- shape(tile);
- popMatrix();
- }
- }
- fill(255, 0, 0);
- text("FPS: " + round(frameRate), width / 2, 20);
- }
- void updateLight() {
- for (int y = 0; y < height / scale; y++) { // set light level of each tile depending on mouse distance
- for (int x = 0; x < width / scale; x++) {
- light[x][y] = map(sqrt(sq(mouseX - x * scale) + sq(mouseY - y * scale)) * 3, 0, 1000, 1, 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement