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 lightmapScale = 3;
|
||||
var pixelSizeQuarter = pixelSizeHalf / 2;
|
||||
var falloff = 0.7;
|
||||
|
||||
// Define RGB colors
|
||||
var fireColor = [255, 69, 0];
|
||||
var coldFireColor = [0, 191, 255];
|
||||
var fireflyColor = [240, 255, 70];
|
||||
var radColor = [75, 100, 30];
|
||||
|
|
@ -27,10 +27,8 @@ if (!rgbToArray) {
|
|||
}
|
||||
|
||||
if (colorString.startsWith('rgb')) {
|
||||
// Handle RGB format
|
||||
return colorString.slice(4, -1).split(',').map(val => parseInt(val.trim()));
|
||||
} else if (colorString.startsWith('#')) {
|
||||
// Handle HEX format
|
||||
let hex = colorString.slice(1);
|
||||
|
||||
// Handle shorthand hex (e.g., #03F)
|
||||
|
|
@ -59,18 +57,20 @@ function scaleList(numbers, scale) {
|
|||
return numbers.map(number => number * scale);
|
||||
}
|
||||
|
||||
function initializeLightmap(width, height) {
|
||||
lightmapWidth = Math.ceil(width / lightmapScale);
|
||||
lightmapHeight = Math.ceil(height / lightmapScale);
|
||||
function initializeLightmap(_width, _height) {
|
||||
const lightmapWidth = Math.ceil(_width / lightmapScale);
|
||||
const lightmapHeight = Math.ceil(_height / lightmapScale);
|
||||
|
||||
for (var y = 0; y < lightmapHeight; y++) {
|
||||
lightmap[y] = [];
|
||||
nextLightmap[y] = [];
|
||||
for (var x = 0; x < lightmapWidth; x++) {
|
||||
lightmap[y][x] = { color: [0, 0, 0] };
|
||||
nextLightmap[y][x] = { color: [0, 0, 0] };
|
||||
}
|
||||
}
|
||||
const createLightmapArray = (width, height) =>
|
||||
Array.from({ length: height }, () =>
|
||||
Array.from({ length: width }, () => ({ color: [0, 0, 0] }))
|
||||
);
|
||||
|
||||
const newLightmap = createLightmapArray(lightmapWidth, lightmapHeight);
|
||||
const newNextLightmap = createLightmapArray(lightmapWidth, lightmapHeight);
|
||||
|
||||
lightmap = newLightmap;
|
||||
nextLightmap = newNextLightmap;
|
||||
}
|
||||
|
||||
function deepCopy(source, target) {
|
||||
|
|
@ -113,9 +113,9 @@ function propagateLightmap() {
|
|||
|
||||
nextLightmap[y][x] = {
|
||||
color: [
|
||||
Math.min(Math.max(0, totalColor[0] / neighborCount * 0.8), 255 * 8),
|
||||
Math.min(Math.max(0, totalColor[1] / neighborCount * 0.8), 255 * 8),
|
||||
Math.min(Math.max(0, totalColor[2] / neighborCount * 0.8), 255 * 8)
|
||||
Math.min(Math.max(0, totalColor[0] / neighborCount * falloff), 255 * 8),
|
||||
Math.min(Math.max(0, totalColor[1] / neighborCount * falloff), 255 * 8),
|
||||
Math.min(Math.max(0, totalColor[2] / neighborCount * falloff), 255 * 8)
|
||||
]
|
||||
};
|
||||
}
|
||||
|
|
@ -172,15 +172,15 @@ function renderLightmap() {
|
|||
if (!lightmap || !lightmap[0]) return;
|
||||
|
||||
var context = canvas.getContext('2d');
|
||||
var width = lightmap[0].length;
|
||||
var height = lightmap.length;
|
||||
var _width = lightmap[0].length;
|
||||
var _height = lightmap.length;
|
||||
|
||||
for (var y = 0; y < height; y++) {
|
||||
for (var x = 0; x < width; x++) {
|
||||
for (var y = 0; y < _height; y++) {
|
||||
for (var x = 0; x < _width; x++) {
|
||||
var { color } = lightmap[y][x];
|
||||
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 newColor = hsvToRgb(h, s, 1);
|
||||
var alpha = v;
|
||||
|
|
@ -262,7 +262,7 @@ elements.laser.tick = function(pixel) {
|
|||
var originalFireTick2 = elements.fire.tick;
|
||||
elements.fire.tick = function(pixel) {
|
||||
originalFireTick2(pixel);
|
||||
glowColor(pixel, fireColor);
|
||||
glowItsOwnColor(pixel);
|
||||
};
|
||||
|
||||
var originalFlashTick = elements.flash.tick;
|
||||
|
|
@ -320,13 +320,15 @@ radioactiveElements.forEach(element => {
|
|||
elements[element].tick = glowRadiationColor;
|
||||
});
|
||||
|
||||
window.addEventListener('load', () => initializeLightmap(width, height));
|
||||
window.addEventListener('load', () => {
|
||||
initializeLightmap(width, height);
|
||||
|
||||
var originalResizeCanvas = resizeCanvas;
|
||||
resizeCanvas = function(newHeight, newWidth, newPixelSize, clear) {
|
||||
originalResizeCanvas(newHeight, newWidth, newPixelSize, clear);
|
||||
initializeLightmap(newHeight, newWidth);
|
||||
};
|
||||
var originalResizeCanvas = resizeCanvas;
|
||||
resizeCanvas = function(newHeight, newWidth, newPixelSize, clear) {
|
||||
originalResizeCanvas(newHeight, newWidth, newPixelSize, clear);
|
||||
initializeLightmap(width, height);
|
||||
};
|
||||
});
|
||||
|
||||
var originalTick = tick;
|
||||
tick = function() {
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ var nextLightmap = [];
|
|||
var lightmapWidth, lightmapHeight;
|
||||
var lightmapScale = 2;
|
||||
var pixelSizeQuarter = pixelSizeHalf / 2;
|
||||
var falloff = 0.8;
|
||||
|
||||
// Define RGB colors
|
||||
var fireColor = [255, 69, 0];
|
||||
var coldFireColor = [0, 191, 255];
|
||||
var fireflyColor = [240, 255, 70];
|
||||
var radColor = [75, 100, 30];
|
||||
|
|
@ -27,10 +27,8 @@ if (!rgbToArray) {
|
|||
}
|
||||
|
||||
if (colorString.startsWith('rgb')) {
|
||||
// Handle RGB format
|
||||
return colorString.slice(4, -1).split(',').map(val => parseInt(val.trim()));
|
||||
} else if (colorString.startsWith('#')) {
|
||||
// Handle HEX format
|
||||
let hex = colorString.slice(1);
|
||||
|
||||
// Handle shorthand hex (e.g., #03F)
|
||||
|
|
@ -59,18 +57,20 @@ function scaleList(numbers, scale) {
|
|||
return numbers.map(number => number * scale);
|
||||
}
|
||||
|
||||
function initializeLightmap(width, height) {
|
||||
lightmapWidth = Math.ceil(width / lightmapScale);
|
||||
lightmapHeight = Math.ceil(height / lightmapScale);
|
||||
function initializeLightmap(_width, _height) {
|
||||
const lightmapWidth = Math.ceil(_width / lightmapScale);
|
||||
const lightmapHeight = Math.ceil(_height / lightmapScale);
|
||||
|
||||
for (var y = 0; y < lightmapHeight; y++) {
|
||||
lightmap[y] = [];
|
||||
nextLightmap[y] = [];
|
||||
for (var x = 0; x < lightmapWidth; x++) {
|
||||
lightmap[y][x] = { color: [0, 0, 0] };
|
||||
nextLightmap[y][x] = { color: [0, 0, 0] };
|
||||
}
|
||||
}
|
||||
const createLightmapArray = (width, height) =>
|
||||
Array.from({ length: height }, () =>
|
||||
Array.from({ length: width }, () => ({ color: [0, 0, 0] }))
|
||||
);
|
||||
|
||||
const newLightmap = createLightmapArray(lightmapWidth, lightmapHeight);
|
||||
const newNextLightmap = createLightmapArray(lightmapWidth, lightmapHeight);
|
||||
|
||||
lightmap = newLightmap;
|
||||
nextLightmap = newNextLightmap;
|
||||
}
|
||||
|
||||
function deepCopy(source, target) {
|
||||
|
|
@ -113,9 +113,9 @@ function propagateLightmap() {
|
|||
|
||||
nextLightmap[y][x] = {
|
||||
color: [
|
||||
Math.min(Math.max(0, totalColor[0] / neighborCount * 0.8), 255 * 8),
|
||||
Math.min(Math.max(0, totalColor[1] / neighborCount * 0.8), 255 * 8),
|
||||
Math.min(Math.max(0, totalColor[2] / neighborCount * 0.8), 255 * 8)
|
||||
Math.min(Math.max(0, totalColor[0] / neighborCount * falloff), 255 * 8),
|
||||
Math.min(Math.max(0, totalColor[1] / neighborCount * falloff), 255 * 8),
|
||||
Math.min(Math.max(0, totalColor[2] / neighborCount * falloff), 255 * 8)
|
||||
]
|
||||
};
|
||||
}
|
||||
|
|
@ -172,15 +172,15 @@ function renderLightmap() {
|
|||
if (!lightmap || !lightmap[0]) return;
|
||||
|
||||
var context = canvas.getContext('2d');
|
||||
var width = lightmap[0].length;
|
||||
var height = lightmap.length;
|
||||
var _width = lightmap[0].length;
|
||||
var _height = lightmap.length;
|
||||
|
||||
for (var y = 0; y < height; y++) {
|
||||
for (var x = 0; x < width; x++) {
|
||||
for (var y = 0; y < _height; y++) {
|
||||
for (var x = 0; x < _width; x++) {
|
||||
var { color } = lightmap[y][x];
|
||||
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 newColor = hsvToRgb(h, s, 1);
|
||||
var alpha = v;
|
||||
|
|
@ -262,7 +262,7 @@ elements.laser.tick = function(pixel) {
|
|||
var originalFireTick2 = elements.fire.tick;
|
||||
elements.fire.tick = function(pixel) {
|
||||
originalFireTick2(pixel);
|
||||
glowColor(pixel, fireColor);
|
||||
glowItsOwnColor(pixel);
|
||||
};
|
||||
|
||||
var originalFlashTick = elements.flash.tick;
|
||||
|
|
@ -326,7 +326,7 @@ window.addEventListener('load', () => {
|
|||
var originalResizeCanvas = resizeCanvas;
|
||||
resizeCanvas = function(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
|
||||
elements.outliner = {
|
||||
elements.inner_outliner = {
|
||||
color: elements.filler.color,
|
||||
category: elements.filler.category,
|
||||
excludeRandom: true,
|
||||
|
|
@ -2578,45 +2578,27 @@ elements.selective_void = {
|
|||
}
|
||||
}
|
||||
}
|
||||
let radiusVar = 0
|
||||
let circleElem = 0
|
||||
let circleRep = false
|
||||
let circleElem = "wood"
|
||||
elements.scuffed_circle_brush = {
|
||||
category: "special",
|
||||
color: elements.drag.color,
|
||||
excludeRandom: true,
|
||||
state: "solid",
|
||||
movable: false,
|
||||
maxSize: 1,
|
||||
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));
|
||||
if (!answerE) { return }
|
||||
circleElem = answerE;
|
||||
var answerH = prompt("Replace? True or false. May be laggy.",(circleRep||undefined));
|
||||
if (!answerH) { answerH = false }
|
||||
circleRep = answerH;
|
||||
circleElem = mostSimilarElement(answerE);
|
||||
},
|
||||
tick: function(pixel){
|
||||
var circlec = circleCoords(pixel.x, pixel.y, radiusVar)
|
||||
for (var i = 0; i < circlec.length; i++){
|
||||
var coord = circlec[i]
|
||||
var x = coord.x
|
||||
var y = coord.y
|
||||
if (isEmpty(x, y)){
|
||||
createPixel(circleElem, x, 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)
|
||||
let radius = mouseSize/2
|
||||
//pyhtagoreas time
|
||||
if (Math.sqrt(Math.pow(pixel.x-mousePos.x,2)+Math.pow(pixel.y-mousePos.y,2)) < radius) {
|
||||
deletePixel(pixel.x, pixel.y)
|
||||
createPixel(circleElem, pixel.x, pixel.y)
|
||||
} else {
|
||||
deletePixel(pixel.x, pixel.y)
|
||||
}
|
||||
}
|
||||
}
|
||||
function randomIntFromInterval(min, max) { // min and max included
|
||||
|
|
@ -3398,4 +3380,78 @@ elements.global_heat_conductor = {
|
|||
behavior: behaviors.WALL,
|
||||
category: "solids",
|
||||
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