JSFiddle - React, Tailwind, and code Playground
HTML
<div id="h">Loading</div>
CSS
body {
color: #BB0000;
background-color: black;
}
#h {
width: 320px;
height: 320px;
font-size: 8px;
border: 1px solid #ddd;
}
span {
display: block;
float: left;
width: 10px;
height: 10px;
text-align: center;
text-indent: -9999px;
}
span:hover {
text-indent: 0;
}
JavaScript
var size = 32;
var start_light = 1;
var deterioration = 1;
var multiplication = 0;
function LightSource(x,y,l) {
this.x = x;
this.y = y;
this.l = l;
}
a = new Array(size);
for (i = 0; i < size; i++) {
a[i] = new Array(size);
for (y = 0; y < size; y++) {
a[i][y] = start_light;
}
}
function display(arr) {
h = "";
for (y=0; y < size; y++) {
for (x=0; x < size; x++) {
h += "<span style='background-color:rgba(255,255,255," + (arr[x][y]/10) + ")'>" + Math.round(arr[x][y]) + "</span>";
if (x == size - 1) h += "<br/>";
}
}
$("#h").html(h);
}
// Setting light point
ls = new Array();
ls.push(new LightSource(6,6,4));
ls.push(new LightSource(2,2,3));
ls.push(new LightSource(9,9,5));
/*
ls.push(new LightSource(11,18,8));
ls.push(new LightSource(28,20,2));
ls.push(new LightSource(10,2,2));
ls.push(new LightSource(25,4,4));
ls.push(new LightSource(22,20,4));
ls.push(new LightSource(2,29,5));
ls.push(new LightSource(31,31,10));*/
ls.push(new LightSource(20,14,8));
ls.push(new LightSource(20,19,8));
var start = new Date().getTime();
for (z = 0; z < ls.length; z++) {
for (x = 0; x < size; x++) {
for (y = 0; y < size; y++) {
xd = x-ls[z].x;
yd = y-ls[z].y;
dist = Math.sqrt(xd*xd+yd*yd) * deterioration;
/*if (ls[z].l - dist > a[x][y]) {
a[x][y] = a[x][y]*multiplication + (ls[z].l - dist);
} else if (ls[z].l - dist > 0){
a[x][y] += multiplication * (ls[z].l - dist);
}*/
if (ls[z].l - dist > 0) {
a[x][y] += ((10-a[x][y])/10)*(ls[z].l - dist);
}
if (a[x][y] > 10) a[x][y] = 10;
}
}
}
var end = new Date().getTime();
var time = end - start;
console.log("Time taken: " + time);
display(a);