Merge branch 'main' of https://github.com/R74nCom/sandboxels
This commit is contained in:
commit
68394deff3
File diff suppressed because it is too large
Load Diff
|
|
@ -6,9 +6,9 @@ var nextLightmap = [];
|
||||||
var lightmapWidth, lightmapHeight;
|
var lightmapWidth, lightmapHeight;
|
||||||
var lightmapScale = 3;
|
var lightmapScale = 3;
|
||||||
var pixelSizeQuarter = pixelSizeHalf / 2;
|
var pixelSizeQuarter = pixelSizeHalf / 2;
|
||||||
|
var falloff = 0.7;
|
||||||
|
|
||||||
// Define RGB colors
|
// Define RGB colors
|
||||||
var fireColor = [255, 69, 0];
|
|
||||||
var coldFireColor = [0, 191, 255];
|
var coldFireColor = [0, 191, 255];
|
||||||
var fireflyColor = [240, 255, 70];
|
var fireflyColor = [240, 255, 70];
|
||||||
var radColor = [75, 100, 30];
|
var radColor = [75, 100, 30];
|
||||||
|
|
@ -27,10 +27,8 @@ if (!rgbToArray) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colorString.startsWith('rgb')) {
|
if (colorString.startsWith('rgb')) {
|
||||||
// Handle RGB format
|
|
||||||
return colorString.slice(4, -1).split(',').map(val => parseInt(val.trim()));
|
return colorString.slice(4, -1).split(',').map(val => parseInt(val.trim()));
|
||||||
} else if (colorString.startsWith('#')) {
|
} else if (colorString.startsWith('#')) {
|
||||||
// Handle HEX format
|
|
||||||
let hex = colorString.slice(1);
|
let hex = colorString.slice(1);
|
||||||
|
|
||||||
// Handle shorthand hex (e.g., #03F)
|
// Handle shorthand hex (e.g., #03F)
|
||||||
|
|
@ -59,18 +57,20 @@ function scaleList(numbers, scale) {
|
||||||
return numbers.map(number => number * scale);
|
return numbers.map(number => number * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeLightmap(width, height) {
|
function initializeLightmap(_width, _height) {
|
||||||
lightmapWidth = Math.ceil(width / lightmapScale);
|
const lightmapWidth = Math.ceil(_width / lightmapScale);
|
||||||
lightmapHeight = Math.ceil(height / lightmapScale);
|
const lightmapHeight = Math.ceil(_height / lightmapScale);
|
||||||
|
|
||||||
for (var y = 0; y < lightmapHeight; y++) {
|
const createLightmapArray = (width, height) =>
|
||||||
lightmap[y] = [];
|
Array.from({ length: height }, () =>
|
||||||
nextLightmap[y] = [];
|
Array.from({ length: width }, () => ({ color: [0, 0, 0] }))
|
||||||
for (var x = 0; x < lightmapWidth; x++) {
|
);
|
||||||
lightmap[y][x] = { color: [0, 0, 0] };
|
|
||||||
nextLightmap[y][x] = { color: [0, 0, 0] };
|
const newLightmap = createLightmapArray(lightmapWidth, lightmapHeight);
|
||||||
}
|
const newNextLightmap = createLightmapArray(lightmapWidth, lightmapHeight);
|
||||||
}
|
|
||||||
|
lightmap = newLightmap;
|
||||||
|
nextLightmap = newNextLightmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
function deepCopy(source, target) {
|
function deepCopy(source, target) {
|
||||||
|
|
@ -113,9 +113,9 @@ function propagateLightmap() {
|
||||||
|
|
||||||
nextLightmap[y][x] = {
|
nextLightmap[y][x] = {
|
||||||
color: [
|
color: [
|
||||||
Math.min(Math.max(0, totalColor[0] / neighborCount * 0.8), 255 * 8),
|
Math.min(Math.max(0, totalColor[0] / neighborCount * falloff), 255 * 8),
|
||||||
Math.min(Math.max(0, totalColor[1] / neighborCount * 0.8), 255 * 8),
|
Math.min(Math.max(0, totalColor[1] / neighborCount * falloff), 255 * 8),
|
||||||
Math.min(Math.max(0, totalColor[2] / neighborCount * 0.8), 255 * 8)
|
Math.min(Math.max(0, totalColor[2] / neighborCount * falloff), 255 * 8)
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -172,15 +172,15 @@ function renderLightmap() {
|
||||||
if (!lightmap || !lightmap[0]) return;
|
if (!lightmap || !lightmap[0]) return;
|
||||||
|
|
||||||
var context = canvas.getContext('2d');
|
var context = canvas.getContext('2d');
|
||||||
var width = lightmap[0].length;
|
var _width = lightmap[0].length;
|
||||||
var height = lightmap.length;
|
var _height = lightmap.length;
|
||||||
|
|
||||||
for (var y = 0; y < height; y++) {
|
for (var y = 0; y < _height; y++) {
|
||||||
for (var x = 0; x < width; x++) {
|
for (var x = 0; x < _width; x++) {
|
||||||
var { color } = lightmap[y][x];
|
var { color } = lightmap[y][x];
|
||||||
var [r, g, b] = color;
|
var [r, g, b] = color;
|
||||||
|
|
||||||
if (r > 0 || g > 0 || b > 0) {
|
if (r > 16 || g > 16 || b > 16) {
|
||||||
var [h, s, v] = rgbToHsv(r, g, b);
|
var [h, s, v] = rgbToHsv(r, g, b);
|
||||||
var newColor = hsvToRgb(h, s, 1);
|
var newColor = hsvToRgb(h, s, 1);
|
||||||
var alpha = v;
|
var alpha = v;
|
||||||
|
|
@ -262,7 +262,7 @@ elements.laser.tick = function(pixel) {
|
||||||
var originalFireTick2 = elements.fire.tick;
|
var originalFireTick2 = elements.fire.tick;
|
||||||
elements.fire.tick = function(pixel) {
|
elements.fire.tick = function(pixel) {
|
||||||
originalFireTick2(pixel);
|
originalFireTick2(pixel);
|
||||||
glowColor(pixel, fireColor);
|
glowItsOwnColor(pixel);
|
||||||
};
|
};
|
||||||
|
|
||||||
var originalFlashTick = elements.flash.tick;
|
var originalFlashTick = elements.flash.tick;
|
||||||
|
|
@ -320,13 +320,15 @@ radioactiveElements.forEach(element => {
|
||||||
elements[element].tick = glowRadiationColor;
|
elements[element].tick = glowRadiationColor;
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('load', () => initializeLightmap(width, height));
|
window.addEventListener('load', () => {
|
||||||
|
initializeLightmap(width, height);
|
||||||
|
|
||||||
var originalResizeCanvas = resizeCanvas;
|
var originalResizeCanvas = resizeCanvas;
|
||||||
resizeCanvas = function(newHeight, newWidth, newPixelSize, clear) {
|
resizeCanvas = function(newHeight, newWidth, newPixelSize, clear) {
|
||||||
originalResizeCanvas(newHeight, newWidth, newPixelSize, clear);
|
originalResizeCanvas(newHeight, newWidth, newPixelSize, clear);
|
||||||
initializeLightmap(newHeight, newWidth);
|
initializeLightmap(width, height);
|
||||||
};
|
};
|
||||||
|
});
|
||||||
|
|
||||||
var originalTick = tick;
|
var originalTick = tick;
|
||||||
tick = function() {
|
tick = function() {
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ var nextLightmap = [];
|
||||||
var lightmapWidth, lightmapHeight;
|
var lightmapWidth, lightmapHeight;
|
||||||
var lightmapScale = 2;
|
var lightmapScale = 2;
|
||||||
var pixelSizeQuarter = pixelSizeHalf / 2;
|
var pixelSizeQuarter = pixelSizeHalf / 2;
|
||||||
|
var falloff = 0.8;
|
||||||
|
|
||||||
// Define RGB colors
|
// Define RGB colors
|
||||||
var fireColor = [255, 69, 0];
|
|
||||||
var coldFireColor = [0, 191, 255];
|
var coldFireColor = [0, 191, 255];
|
||||||
var fireflyColor = [240, 255, 70];
|
var fireflyColor = [240, 255, 70];
|
||||||
var radColor = [75, 100, 30];
|
var radColor = [75, 100, 30];
|
||||||
|
|
@ -27,10 +27,8 @@ if (!rgbToArray) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colorString.startsWith('rgb')) {
|
if (colorString.startsWith('rgb')) {
|
||||||
// Handle RGB format
|
|
||||||
return colorString.slice(4, -1).split(',').map(val => parseInt(val.trim()));
|
return colorString.slice(4, -1).split(',').map(val => parseInt(val.trim()));
|
||||||
} else if (colorString.startsWith('#')) {
|
} else if (colorString.startsWith('#')) {
|
||||||
// Handle HEX format
|
|
||||||
let hex = colorString.slice(1);
|
let hex = colorString.slice(1);
|
||||||
|
|
||||||
// Handle shorthand hex (e.g., #03F)
|
// Handle shorthand hex (e.g., #03F)
|
||||||
|
|
@ -59,18 +57,20 @@ function scaleList(numbers, scale) {
|
||||||
return numbers.map(number => number * scale);
|
return numbers.map(number => number * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeLightmap(width, height) {
|
function initializeLightmap(_width, _height) {
|
||||||
lightmapWidth = Math.ceil(width / lightmapScale);
|
const lightmapWidth = Math.ceil(_width / lightmapScale);
|
||||||
lightmapHeight = Math.ceil(height / lightmapScale);
|
const lightmapHeight = Math.ceil(_height / lightmapScale);
|
||||||
|
|
||||||
for (var y = 0; y < lightmapHeight; y++) {
|
const createLightmapArray = (width, height) =>
|
||||||
lightmap[y] = [];
|
Array.from({ length: height }, () =>
|
||||||
nextLightmap[y] = [];
|
Array.from({ length: width }, () => ({ color: [0, 0, 0] }))
|
||||||
for (var x = 0; x < lightmapWidth; x++) {
|
);
|
||||||
lightmap[y][x] = { color: [0, 0, 0] };
|
|
||||||
nextLightmap[y][x] = { color: [0, 0, 0] };
|
const newLightmap = createLightmapArray(lightmapWidth, lightmapHeight);
|
||||||
}
|
const newNextLightmap = createLightmapArray(lightmapWidth, lightmapHeight);
|
||||||
}
|
|
||||||
|
lightmap = newLightmap;
|
||||||
|
nextLightmap = newNextLightmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
function deepCopy(source, target) {
|
function deepCopy(source, target) {
|
||||||
|
|
@ -113,9 +113,9 @@ function propagateLightmap() {
|
||||||
|
|
||||||
nextLightmap[y][x] = {
|
nextLightmap[y][x] = {
|
||||||
color: [
|
color: [
|
||||||
Math.min(Math.max(0, totalColor[0] / neighborCount * 0.8), 255 * 8),
|
Math.min(Math.max(0, totalColor[0] / neighborCount * falloff), 255 * 8),
|
||||||
Math.min(Math.max(0, totalColor[1] / neighborCount * 0.8), 255 * 8),
|
Math.min(Math.max(0, totalColor[1] / neighborCount * falloff), 255 * 8),
|
||||||
Math.min(Math.max(0, totalColor[2] / neighborCount * 0.8), 255 * 8)
|
Math.min(Math.max(0, totalColor[2] / neighborCount * falloff), 255 * 8)
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -172,15 +172,15 @@ function renderLightmap() {
|
||||||
if (!lightmap || !lightmap[0]) return;
|
if (!lightmap || !lightmap[0]) return;
|
||||||
|
|
||||||
var context = canvas.getContext('2d');
|
var context = canvas.getContext('2d');
|
||||||
var width = lightmap[0].length;
|
var _width = lightmap[0].length;
|
||||||
var height = lightmap.length;
|
var _height = lightmap.length;
|
||||||
|
|
||||||
for (var y = 0; y < height; y++) {
|
for (var y = 0; y < _height; y++) {
|
||||||
for (var x = 0; x < width; x++) {
|
for (var x = 0; x < _width; x++) {
|
||||||
var { color } = lightmap[y][x];
|
var { color } = lightmap[y][x];
|
||||||
var [r, g, b] = color;
|
var [r, g, b] = color;
|
||||||
|
|
||||||
if (r > 0 || g > 0 || b > 0) {
|
if (r > 16 || g > 16 || b > 16) {
|
||||||
var [h, s, v] = rgbToHsv(r, g, b);
|
var [h, s, v] = rgbToHsv(r, g, b);
|
||||||
var newColor = hsvToRgb(h, s, 1);
|
var newColor = hsvToRgb(h, s, 1);
|
||||||
var alpha = v;
|
var alpha = v;
|
||||||
|
|
@ -262,7 +262,7 @@ elements.laser.tick = function(pixel) {
|
||||||
var originalFireTick2 = elements.fire.tick;
|
var originalFireTick2 = elements.fire.tick;
|
||||||
elements.fire.tick = function(pixel) {
|
elements.fire.tick = function(pixel) {
|
||||||
originalFireTick2(pixel);
|
originalFireTick2(pixel);
|
||||||
glowColor(pixel, fireColor);
|
glowItsOwnColor(pixel);
|
||||||
};
|
};
|
||||||
|
|
||||||
var originalFlashTick = elements.flash.tick;
|
var originalFlashTick = elements.flash.tick;
|
||||||
|
|
@ -326,7 +326,7 @@ window.addEventListener('load', () => {
|
||||||
var originalResizeCanvas = resizeCanvas;
|
var originalResizeCanvas = resizeCanvas;
|
||||||
resizeCanvas = function(newHeight, newWidth, newPixelSize, clear) {
|
resizeCanvas = function(newHeight, newWidth, newPixelSize, clear) {
|
||||||
originalResizeCanvas(newHeight, newWidth, newPixelSize, clear);
|
originalResizeCanvas(newHeight, newWidth, newPixelSize, clear);
|
||||||
initializeLightmap(newHeight, newWidth);
|
initializeLightmap(width, height);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2321,7 +2321,7 @@ elements.element_filler = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var outlinerVar = 0
|
var outlinerVar = 0
|
||||||
elements.outliner = {
|
elements.inner_outliner = {
|
||||||
color: elements.filler.color,
|
color: elements.filler.color,
|
||||||
category: elements.filler.category,
|
category: elements.filler.category,
|
||||||
excludeRandom: true,
|
excludeRandom: true,
|
||||||
|
|
@ -2578,45 +2578,27 @@ elements.selective_void = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let radiusVar = 0
|
let circleElem = "wood"
|
||||||
let circleElem = 0
|
|
||||||
let circleRep = false
|
|
||||||
elements.scuffed_circle_brush = {
|
elements.scuffed_circle_brush = {
|
||||||
category: "special",
|
category: "special",
|
||||||
color: elements.drag.color,
|
color: elements.drag.color,
|
||||||
excludeRandom: true,
|
excludeRandom: true,
|
||||||
state: "solid",
|
state: "solid",
|
||||||
movable: false,
|
movable: false,
|
||||||
maxSize: 1,
|
|
||||||
onSelect: function(){
|
onSelect: function(){
|
||||||
var answerR = prompt("Radius of the brush. Things above 10 may be laggy.",(radiusVar||undefined));
|
|
||||||
if (!answerR) { return }
|
|
||||||
radiusVar = answerR;
|
|
||||||
var answerE = prompt("Element of the brush.",(circleElem||undefined));
|
var answerE = prompt("Element of the brush.",(circleElem||undefined));
|
||||||
if (!answerE) { return }
|
if (!answerE) { return }
|
||||||
circleElem = answerE;
|
circleElem = mostSimilarElement(answerE);
|
||||||
var answerH = prompt("Replace? True or false. May be laggy.",(circleRep||undefined));
|
|
||||||
if (!answerH) { answerH = false }
|
|
||||||
circleRep = answerH;
|
|
||||||
},
|
},
|
||||||
tick: function(pixel){
|
tick: function(pixel){
|
||||||
var circlec = circleCoords(pixel.x, pixel.y, radiusVar)
|
let radius = mouseSize/2
|
||||||
for (var i = 0; i < circlec.length; i++){
|
//pyhtagoreas time
|
||||||
var coord = circlec[i]
|
if (Math.sqrt(Math.pow(pixel.x-mousePos.x,2)+Math.pow(pixel.y-mousePos.y,2)) < radius) {
|
||||||
var x = coord.x
|
deletePixel(pixel.x, pixel.y)
|
||||||
var y = coord.y
|
createPixel(circleElem, pixel.x, pixel.y)
|
||||||
if (isEmpty(x, y)){
|
} else {
|
||||||
createPixel(circleElem, x, y)
|
deletePixel(pixel.x, pixel.y)
|
||||||
}
|
}
|
||||||
else if (circleRep && !outOfBounds(x, y)){
|
|
||||||
deletePixel(x, y)
|
|
||||||
createPixel(circleElem, x, y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var thisx = pixel.x
|
|
||||||
var thisy = pixel.y
|
|
||||||
deletePixel(thisx, thisy)
|
|
||||||
createPixel(circleElem, thisx, thisy)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function randomIntFromInterval(min, max) { // min and max included
|
function randomIntFromInterval(min, max) { // min and max included
|
||||||
|
|
@ -3399,3 +3381,77 @@ elements.global_heat_conductor = {
|
||||||
category: "solids",
|
category: "solids",
|
||||||
density: 10000,
|
density: 10000,
|
||||||
}
|
}
|
||||||
|
let latticeElem = "wood"
|
||||||
|
elements.lattice_brush = {
|
||||||
|
color: elements.grid_brush.color,
|
||||||
|
behavior: behaviors.WALL,
|
||||||
|
category: "special",
|
||||||
|
onSelect: function(){
|
||||||
|
let ans1 = prompt("Enter the element you want to use for the lattice", latticeElem||"wood")
|
||||||
|
latticeElem = mostSimilarElement(ans1)
|
||||||
|
},
|
||||||
|
tick: function(pixel){
|
||||||
|
let modx = pixel.x%2
|
||||||
|
let mody = pixel.y%2
|
||||||
|
let valid = {
|
||||||
|
1: 0,
|
||||||
|
0: 1
|
||||||
|
}
|
||||||
|
if (valid[modx] == mody){
|
||||||
|
changePixel(pixel, latticeElem)
|
||||||
|
}else {
|
||||||
|
deletePixel(pixel.x, pixel.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elements.spaced_lattice_brush = {
|
||||||
|
color: elements.grid_brush.color,
|
||||||
|
behavior: behaviors.WALL,
|
||||||
|
category: "special",
|
||||||
|
onSelect: function(){
|
||||||
|
let ans1 = prompt("Enter the element you want to use for the lattice", latticeElem||"wood")
|
||||||
|
latticeElem = mostSimilarElement(ans1)
|
||||||
|
},
|
||||||
|
tick: function(pixel){
|
||||||
|
let modx = pixel.x%5
|
||||||
|
let mody = pixel.y%5
|
||||||
|
let valid = {
|
||||||
|
1: 3,
|
||||||
|
2: 0,
|
||||||
|
3: 2,
|
||||||
|
4: 4,
|
||||||
|
0: 1
|
||||||
|
}
|
||||||
|
if (valid[modx] == mody){
|
||||||
|
changePixel(pixel, latticeElem)
|
||||||
|
}else {
|
||||||
|
deletePixel(pixel.x, pixel.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let outlinerElem = "wood"
|
||||||
|
elements.outer_outliner = {
|
||||||
|
color: elements.inner_outliner.color,
|
||||||
|
behavior: behaviors.WALL,
|
||||||
|
category: "special",
|
||||||
|
onSelect: function(){
|
||||||
|
let ans1 = prompt("Enter the element you want to use for the outliner. The outliner will ignore pixels of this type.", outlinerElem||"wood")
|
||||||
|
outlinerElem = mostSimilarElement(ans1)
|
||||||
|
},
|
||||||
|
tick: function(pixel){
|
||||||
|
// this just checks if theres any neighboring coord non-outliner elem pixels. yuh that simple
|
||||||
|
for (var i = 0; i < squareCoords.length; i++) {
|
||||||
|
var x = pixel.x+squareCoords[i][0];
|
||||||
|
var y = pixel.y+squareCoords[i][1];
|
||||||
|
if (!isEmpty(x,y,true)) {
|
||||||
|
var newPixel = pixelMap[x][y];
|
||||||
|
if (newPixel.element != outlinerElem && newPixel.element!= "outer_outliner") {
|
||||||
|
deletePixel(pixel.x, pixel.y)
|
||||||
|
createPixel(outlinerElem, pixel.x, pixel.y)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deletePixel(pixel.x, pixel.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue