From 295b7651eeff4a2904ba429993ecec54953db9c2 Mon Sep 17 00:00:00 2001 From: CarbonMonoxida <164758530+CarbonMonoxida@users.noreply.github.com> Date: Sat, 14 Sep 2024 09:58:13 +0700 Subject: [PATCH 1/6] aScientistsWish.js 1.8.1 Delete CPU, computer, add some small detail, and fixed bug --- mods/aScientistsWish.js | 105 ++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 68 deletions(-) diff --git a/mods/aScientistsWish.js b/mods/aScientistsWish.js index 64769c97..a955006b 100644 --- a/mods/aScientistsWish.js +++ b/mods/aScientistsWish.js @@ -1,5 +1,12 @@ -//this mod is still on proggres (WIP) you can give feedback or report bug to these discord account. @salmonfishy or @carbon_monoxides6 - +//Hello, this is are a science mod, we're made several things that related to science, examples like...electron, particle accelerator, and of course, carbon monoxide! :D +//We made some things not scientific, so this mod is not too boring. ;) +//we're normal people, who is not as smart as a real scientist. so if you have suggestion, feedback, or criticism, please let us know, so we can make this mod being more accurate. >< +// discord account | +// | +// | +// v +// creator,leader,supervisor,coder,uploader = @carbon_monoxides6 +// co-creator,co-coder,assistant,debugger = @salmonfishy (has exited from this mod project) elements.carbon_monoxide = { color: "#b5b5b5", behavior: behaviors.GAS, @@ -68,39 +75,7 @@ elements.carbon_monoxide_detector = { darkText: true, hardness: 1, }; -elements.cpu = { - color: "#575757", - behavior: behaviors.SOLID, - category: "machines", - state: "solid", - insulate: true, - movable: false, - noMix: true, - density: 75, - tempHigh: 1414, - stateHigh: ["explosion","metal_scrap"], -reactions: { - "virus": { elem1 : null , elem2:"malware", chance:0.9 }, - "metal_scrap": { elem2:"computer" }, - - } -}; -elements.computer = { - color: "#2b2b2a", - behavior: behaviors.SOLID, - category: "machines", - state: "solid", - density: 8908, - insulate: true, - noMix: true, - movable: false, - tempHigh: 1414, - stateHigh: ["explosion","metal_scrap"], -reactions: { - "virus": { elem1 : null , elem2:"malware", chance:0.9 }, - "water": { elem1: null , elem2: "electric" }, - } -} + elements.electrons = { color: "#b80606", behavior: [ @@ -409,19 +384,6 @@ reactions: { } }; -elements.leather = { -behavior: behaviors.SUPPORTPOWDER, -color: ["#3f261d","#664f40",], -state: "powder", -category: "powders", -tempHigh: 200, -stateHigh: "fire", -breakInto: "dust", -burn: 20, -burntime: 200, -burnInto: "ash", -}; - elements.wrinkled_lemon = { behavior: behaviors.POWDER, color: ["#999543","#a6a03a",], @@ -530,7 +492,7 @@ tempLow: -2, stateLow: "frozen_yogurt", stateLowColor: ["#f5f3cb","#f7f5bc"], reactions: { -"bacteria": { elem1: "yogurt", }, +"cell": { elem1: "yogurt", }, } }; @@ -615,11 +577,11 @@ elements.hazmat_head = { color: ["#404040","#1a1a1a","#737373"], category: "life", hidden: true, - density: 1080, + density: 1380, state: "solid", conduct: .05, - temp: 40, - tempHigh: 3500, + temp: 39, + tempHigh: 6500, stateHigh: ["ash","iron",], tempLow: -180, stateLow: "frozen_meat", @@ -686,7 +648,10 @@ elements.hazmat_head = { "mashed_potato": { elem2:null, chance:0.2 }, "sauce": { elem2:null, chance:0.2 }, "pickle": { elem2:null, chance:0.1 }, - "light": { stain1:"#fff154" }, + "sun": { elem1:"cooked_meat" }, + "water": { elem2:"bubble", attr2:{"clone":"water"}, chance:0.001 }, + "salt_water": { elem2:"bubble", attr2:{"clone":"salt_water"}, chance:0.001 }, + "pool_water": { elem2:"bubble", attr2:{"clone":"pool_water"}, chance:0.001 }, }, properties: { dead: false @@ -729,14 +694,14 @@ elements.hazmat_head = { }; elements.hazmat_body = { - color: ["#ffdf4f","#e8c00e","#ffd412"], + color: ["#2c7328","#2db526","#ffc42e","#f5c345","#cf9502",], category: "life", hidden: true, - density: 1570, + density: 1370, state: "solid", conduct: .25, temp: 39, - tempHigh: 3500, + tempHigh: 6500, stateHigh: ["metal_scrap","ash"], tempLow: -180, stateLow: "frozen_meat", @@ -756,6 +721,7 @@ elements.hazmat_body = { "grass_seed": { elem2:null, chance:0.05 }, "gold_coin": { elem2:null, chance:0.05 }, "diamond": { elem2:null, chance:0.05 }, + "sun": { elem1:"molten_tin", }, }, properties: { dead: false, @@ -846,7 +812,6 @@ elements.hazmat_body = { }; elements.hazmat_human = { - // color: ["#404040","#1a1a1a","#737373"], color: ["#404040","#1a1a1a","#737373"], category: "life", properties: { @@ -896,7 +861,6 @@ elements.zombie_head = { "meat": { elem2:null, chance:0.1 }, "cooked_meat": { elem2:null, chance:0.1 }, "cured_meat": { elem2:null, chance:0.1 }, - "light": { stain1:"#45eb2f" }, }, properties: { dead: false @@ -953,8 +917,13 @@ elements.zombie_body = { breakInto: ["infection","rotten_meat","bone","zombie_virus",], forceSaveColor: true, reactions: { - "head": { elem2: "zombie", }, - "body": { elem2: "zombie", }, + "head": { elem2: ["rotten_meat","zombie",], chance:0.8, }, + "body": { elem2: ["rotten_meat","zombie",], chance:0.5, }, + "oxygen": { elem2:"carbon_dioxide", chance:0.5 }, + "rotten_meat": { elem2: null, chance:0.5 }, + "meat": { elem2:null, chance:0.1 }, + "cooked_meat": { elem2:null, chance:0.1 }, + "cured_meat": { elem2:null, chance:0.1 }, }, properties: { @@ -1081,8 +1050,8 @@ elements.zombie_virus = { density: 30, state: "gas", reactions: { - "head": { elem2: ["zombie","rotten_meat",], chance: 0.2, }, - "body": { elem2: ["zombie","rotten_meat",], chance: 0.2, }, + "head": { elem2: ["zombie","rotten_meat",], chance: 0.5, }, + "body": { elem2: ["zombie","rotten_meat",], chance: 0.5, }, } } @@ -1102,7 +1071,7 @@ elements.matter = { elements.particle_accelerator_left = { behavior: behaviors.SOLID, color: ["#363aa3","#858585","#d1d1d1"], - density: 2400, + density: 8200, category: "machines", state: "solid", reactions: { @@ -1112,7 +1081,7 @@ elements.particle_accelerator_left = { elements.particle_accelerator_right = { behavior: behaviors.SOLID, color: ["#363aa3","#858585","#d1d1d1"], - density: 2400, + density: 8200, category: "machines", state: "solid", reactions: { @@ -1132,8 +1101,8 @@ elements.accelerated_matter_left = { category: "energy", density: 2.20, reactions: { - "accelerated_matter_right": { elem1: ["antimatter","pop",], chance: 0.3, }, - "accelerated_matter_left": { elem1: ["antimatter","pop",], chance: 0.3, }, + "accelerated_matter_right": { elem1: ["antimatter","pop",null,], chance: 0.3, }, + "accelerated_matter_left": { elem1: ["antimatter","pop",null,], chance: 0.3, }, "antimatter": { elem1: "pop", chance: 0.01, }, } @@ -1150,8 +1119,8 @@ elements.accelerated_matter_right = { category:"energy", density: 2.20, reactions: { - "accelerated_matter_left": { elem1: ["antimatter","pop",], chance: 0.3, }, - "accelerated_matter_right": { elem1: ["antimatter","pop",], chance: 0.3, }, + "accelerated_matter_left": { elem1: ["antimatter","pop",null,], chance: 0.3, }, + "accelerated_matter_right": { elem1: ["antimatter","pop",null,], chance: 0.3, }, "antimatter": { elem1: "pop", chance: 0.01, }, } From 31286a2d37ccba6e2638f693181fa59c20c6a6ed Mon Sep 17 00:00:00 2001 From: JustAGenericUsername <92590792+JustAGenericUsername@users.noreply.github.com> Date: Sat, 14 Sep 2024 17:39:32 -0400 Subject: [PATCH 2/6] player --- mods/scenexe.js | 169 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 148 insertions(+), 21 deletions(-) diff --git a/mods/scenexe.js b/mods/scenexe.js index 9fa9ac32..3b1b0a28 100644 --- a/mods/scenexe.js +++ b/mods/scenexe.js @@ -19,6 +19,46 @@ polygonColors = function(sides){ return {r: 0, g: 0, b: 0} } } +isKeyDown = { + w: false, + a: false, + s: false, + d: false +} +// when wasd keydown, set isKeyDown to true +document.addEventListener("keydown", (event) => { + if (event.key === "w") { + isKeyDown.w = true; + } + if (event.key === "a") { + isKeyDown.a = true; + } + if (event.key === "s") { + isKeyDown.s = true; + } + if (event.key === "d") { + isKeyDown.d = true + } +}) +// when wasd keyup, set isKeyDown to false +document.addEventListener("keyup", (event) => { + if (event.key === "w") { + isKeyDown.w = false; + } + if (event.key === "a") { + isKeyDown.a = false; + } + if (event.key === "s") { + isKeyDown.s = false; + } + if (event.key === "d") { + isKeyDown.d = false + } +}) +orbitalSpeed = function(sides){ + return 1/(1.00672*Math.pow(0.344151, sides) + 0.000002) +} +shapeNames = ["Triangle", "Square", "Pentagon", "Hexagon", "Heptagon", "Octagon", "Nonagon", "Decagon", "Hendecagon", "Dodecagon", "Triskaidecagon", "Tetrakaidecagon", "Pentakaidecagon", "Hexakaidecagon", "Heptakaidecagon", "Octakaidecagon", "Enneakaidecagon", "Icosagon", "literally just a circle"] function polygonCount(random){ const thresholds = [0, 0.3, 0.68, 0.77, 0.82, 0.86, 0.88, 0.89, 0.895, 0.8975, 0.898, 0.8982, 1]; const values = [3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 3]; @@ -30,7 +70,7 @@ function polygonCount(random){ } } polygonList = [] -zoomLevel = .2 +zoomLevel = 1 polygonSize = function(sides){ return 18 * Math.pow(1.47, sides - 3) } @@ -45,6 +85,7 @@ for (var i = 0; i <= 400; i++){ vy: 0, random: Math.random(), rotation: Math.random() * 2 * Math.PI, + collisionMass: 3+(polygonSize(sides)**2)/6 }) } function drawPolygon(ctx, polygon){ @@ -80,8 +121,24 @@ function drawPolygon(ctx, polygon){ ctx.lineTo(x+20*vx, y+20*vy) ctx.strokeStyle = "rgb(255, 0, 0)" ctx.stroke() + // draw some text to represent mass + ctx.lineWidth = 2 + ctx.fillStyle = "rgb(255, 255, 255)" + ctx.strokeStyle = "rgb(0, 0, 0)" + ctx.font = `bold 30px Helvetica` + ctx.fillText(Math.round(polygon.collisionMass), x, y) + ctx.strokeText(Math.round(polygon.collisionMass), x, y) */ } +function drawPlayer(ctx, player){ + ctx.fillStyle = "rgb(63, 153, 255)" + ctx.strokeStyle = "rgb(33, 123, 225)" + ctx.lineWidth = 5*zoomLevel + ctx.beginPath() + ctx.arc(player.x, player.y, player.radius, 0, 2*Math.PI) + ctx.fill() + ctx.stroke() +} function zoom(ctx, poly, multiplier){ polyreturn = {...poly} polyreturn.x = polyreturn.x * multiplier + ctx.canvas.width/2 @@ -89,56 +146,126 @@ function zoom(ctx, poly, multiplier){ polyreturn.radius = polyreturn.radius * multiplier return polyreturn } +function applyCameraPos(ctx, object, x, y){ + objectreturn = {...object} + objectreturn.x = objectreturn.x + x + objectreturn.y = objectreturn.y + y + return objectreturn +} +function cameraZoom(ctx, object, multiplier, camera){ + objectreturn = {...object} + let x = camera[0] + let y = camera[1] + objectreturn.x = objectreturn.x * multiplier - x + ctx.canvas.width/2 + objectreturn.y = objectreturn.y * multiplier - y + ctx.canvas.height/2 + objectreturn.radius = objectreturn.radius * multiplier + return objectreturn +} +camera = [0, 0] +scenexeplayer = { + x: 0, + y: 0, + vx: 0, + vy: 0, + rotation: 0, + radius: 40, + collisionMass: 520 +} renderPostPixel(function(ctx){ ctx.fillStyle = "rgb(205, 205, 205)" ctx.fillRect(0, 0, canvas.width, canvas.height) ctx.strokeStyle = "rgb(200, 200, 200)" ctx.lineWidth = 5*zoomLevel - for (var i = 0; i < canvas.width; i += canvas.width/30*zoomLevel){ + for (var i = 0; i < canvas.width; i += 20*zoomLevel){ ctx.beginPath() - ctx.moveTo(i, canvas.height) - ctx.lineTo(i, 0) + //ctx.moveTo(i, canvas.height) + //ctx.lineTo(i, 0) + // add offset depending on mod of camera + ctx.moveTo(i-camera[0]%20*zoomLevel, canvas.height) + ctx.lineTo(i-camera[0]%20*zoomLevel, 0) ctx.stroke() } - for (var j = 0; j < canvas.height; j += canvas.width/30*zoomLevel){ + for (var j = 0; j < canvas.height; j += 20*zoomLevel){ ctx.beginPath() - ctx.moveTo(0, j) - ctx.lineTo(canvas.width, j) + //ctx.moveTo(0, j) + //ctx.lineTo(canvas.width, j) + // add offset depending on mod of camera + ctx.moveTo(0, j-camera[1]%20*zoomLevel) + ctx.lineTo(canvas.width, j-camera[1]%20*zoomLevel) ctx.stroke() } //drawPolygon(ctx, Math.round((pixelTicks/20)%13)+3, polygonSize(Math.round((pixelTicks/20)%13)+3), canvas.width/2, canvas.height/2, 0) for (var poly = 0; poly < polygonList.length; poly++){ - drawPolygon(ctx, zoom(ctx, polygonList[poly], zoomLevel)) + drawPolygon(ctx, cameraZoom(ctx, polygonList[poly], zoomLevel, camera)) } - // polygon collision checking - for (var poly = 0; poly < polygonList.length; poly++){ - for (var poly2 = 0; poly2 < polygonList.length; poly2++){ + drawPlayer(ctx, cameraZoom(ctx, scenexeplayer, zoomLevel, camera)) + // collidable collision checking + collideList = [] + collideList = collideList.concat(polygonList) + collideList.push(scenexeplayer) + for (var poly = 0; poly < collideList.length; poly++){ + for (var poly2 = 0; poly2 < collideList.length; poly2++){ if (poly != poly2){ - polygon1 = polygonList[poly] - polygon2 = polygonList[poly2] + polygon1 = collideList[poly] + polygon2 = collideList[poly2] distance = Math.sqrt((polygon1.x - polygon2.x)**2 + (polygon1.y - polygon2.y)**2) - if (distance < polygonSize(polygon1.sides) + polygonSize(polygon2.sides)){ + if (distance < polygon1.radius + polygon2.radius){ //calculate angle of collision angle = Math.atan2(polygon2.y - polygon1.y, polygon2.x - polygon1.x) // update velocity - polygon1.vx -= (Math.cos(angle) * (polygonSize(polygon1.sides) + polygonSize(polygon2.sides) - distance)/2)/(3+polygonSize(polygon1.sides)/9) - polygon1.vy -= (Math.sin(angle) * (polygonSize(polygon1.sides) + polygonSize(polygon2.sides) - distance)/2)/(3+polygonSize(polygon1.sides)/9) + polygon1.vx -= (Math.cos(angle) * (polygon1.radius + polygon2.radius - distance)/2)/(polygon1.collisionMass/polygon2.collisionMass**(1/2.5)) + polygon1.vy -= (Math.sin(angle) * (polygon1.radius + polygon2.radius - distance)/2)/(polygon1.collisionMass/polygon2.collisionMass**(1/2.5)) } } } } // move polygons - for (var poly = 0; poly < polygonList.length; poly++){ - let polygon = polygonList[poly] + for (var poly = 0; poly < collideList.length; poly++){ + let polygon = collideList[poly] if (polygon.vx || polygon.vy){ polygon.x += polygon.vx polygon.y += polygon.vy polygon.vx *= 0.8 polygon.vy *= 0.8 } - polygon.rotation += 1.00672*Math.pow(0.344151, polygon.sides) + 0.000002 + } + // orbit polygons + for (var poly = 0; poly < polygonList.length; poly++){ + let polygon = polygonList[poly] + polygon.rotation += 1/orbitalSpeed(polygon.sides) // add some velocity towards wherever its facing - polygon.vx += Math.sin(polygon.rotation)*(1.00672*Math.pow(0.344151, polygon.sides) + 0.000002)*8 - polygon.vy += Math.cos(polygon.rotation)*(1.00672*Math.pow(0.344151, polygon.sides) + 0.000002)*8 + polygon.vx += Math.sin(polygon.rotation)/orbitalSpeed(polygon.sides)*8 + polygon.vy += Math.cos(polygon.rotation)/orbitalSpeed(polygon.sides)*8 + } + camera[0] += (scenexeplayer.x - camera[0])/10 + camera[1] += (scenexeplayer.y - camera[1])/10 + // add velocity to player depending on which keys are down + if (isKeyDown.w){ + if (isKeyDown.a + isKeyDown.d == 1){ + scenexeplayer.vy -= 1/Math.sqrt(2) + } else{ + scenexeplayer.vy -= 1 + } + } + if (isKeyDown.s){ + if (isKeyDown.a + isKeyDown.d == 1){ + scenexeplayer.vy += 1/Math.sqrt(2) + } else{ + scenexeplayer.vy += 1 + } + } + if (isKeyDown.a){ + if (isKeyDown.w + isKeyDown.s == 1){ + scenexeplayer.vx -= 1/Math.sqrt(2) + } else{ + scenexeplayer.vx -= 1 + } + } + if (isKeyDown.d){ + if (isKeyDown.w + isKeyDown.s == 1){ + scenexeplayer.vx += 1/Math.sqrt(2) + } else{ + scenexeplayer.vx += 1 + } } }) \ No newline at end of file From 6e197ac21bb37519ba4010b0ccbd91e5a67a741f Mon Sep 17 00:00:00 2001 From: JustAGenericUsername <92590792+JustAGenericUsername@users.noreply.github.com> Date: Sat, 14 Sep 2024 17:40:58 -0400 Subject: [PATCH 3/6] d --- mod-list.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod-list.html b/mod-list.html index 4f5b7b1d..00566e31 100644 --- a/mod-list.html +++ b/mod-list.html @@ -375,7 +375,7 @@ randomness_but_tick.jsRandom experimental elements using the tick function featureAlice randomness_but_tool.jsRandom experimental elements using the tool function featureAlice randomness.jsRandom experimental elementsAlice -scenexe.jsWork-in-progress mod, renders and simulates a bunch of polygonsnousernamefound +scenexe.jsWork-in-progress mod, allows you to move through a simulated field of polygonsnousernamefound structure_test_2.jsAnother test for implementing structures into Sandboxels (requires the previous test)Alice structure_test.jsA test for implementing structures into SandboxelsAlice test.jsA test mod that adds mayo :)R74n From 8c9eabe71de04a6deb85cdafe7b4914c25178d0b Mon Sep 17 00:00:00 2001 From: SethanJoseph <99520487+SethanJoseph@users.noreply.github.com> Date: Sun, 15 Sep 2024 16:21:34 -0700 Subject: [PATCH 4/6] Add files via upload --- mods/wine.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 mods/wine.js diff --git a/mods/wine.js b/mods/wine.js new file mode 100644 index 00000000..2b51e8d0 --- /dev/null +++ b/mods/wine.js @@ -0,0 +1,8 @@ + elements.wine = { + color: "#006e05", + behavior: behaviors.LIQUID, + category: "food", + viscosity: 20000, + state: "liquid", + density: 380, +}; \ No newline at end of file From f59830dcd0c04ce86855638c527307a9e78fcba8 Mon Sep 17 00:00:00 2001 From: SethanJoseph <99520487+SethanJoseph@users.noreply.github.com> Date: Sun, 15 Sep 2024 16:47:23 -0700 Subject: [PATCH 5/6] Update wine.js --- mods/wine.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/wine.js b/mods/wine.js index 2b51e8d0..a75f8d0f 100644 --- a/mods/wine.js +++ b/mods/wine.js @@ -1,8 +1,8 @@ elements.wine = { - color: "#006e05", + color: "#89281D", behavior: behaviors.LIQUID, category: "food", viscosity: 20000, state: "liquid", density: 380, -}; \ No newline at end of file +}; From 3bdadbbcbe4f7272d3e789bc33a31a49205b8de3 Mon Sep 17 00:00:00 2001 From: JustAGenericUsername <92590792+JustAGenericUsername@users.noreply.github.com> Date: Mon, 16 Sep 2024 21:19:45 -0400 Subject: [PATCH 6/6] yu --- mod-list.html | 2 +- mods/scenexe.js | 364 ++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 308 insertions(+), 58 deletions(-) diff --git a/mod-list.html b/mod-list.html index 00566e31..82d5e926 100644 --- a/mod-list.html +++ b/mod-list.html @@ -375,7 +375,7 @@ randomness_but_tick.jsRandom experimental elements using the tick function featureAlice randomness_but_tool.jsRandom experimental elements using the tool function featureAlice randomness.jsRandom experimental elementsAlice -scenexe.jsWork-in-progress mod, allows you to move through a simulated field of polygonsnousernamefound +scenexe.jsWork-in-progress mod, allows you to move through and damage a simulated field of polygonsnousernamefound structure_test_2.jsAnother test for implementing structures into Sandboxels (requires the previous test)Alice structure_test.jsA test for implementing structures into SandboxelsAlice test.jsA test mod that adds mayo :)R74n diff --git a/mods/scenexe.js b/mods/scenexe.js index 3b1b0a28..54a2e842 100644 --- a/mods/scenexe.js +++ b/mods/scenexe.js @@ -1,5 +1,6 @@ polygonColors = function(sides){ let baseColors = [ + /* { r: 255, g: 228, b: 107 }, { r: 252, g: 118, b: 118 }, { r: 118, g: 140, b: 252 }, @@ -12,18 +13,104 @@ polygonColors = function(sides){ { r: 64, g: 54, b: 69 }, { r: 237, g: 237, b: 255 }, { r: 0, g: 0, b: 0 }, + */ + "rgb(255, 228, 107)", + "rgb(252, 118, 118)", + "rgb(118, 140, 252)", + "rgb(252, 166, 68)", + "rgb(56, 183, 100)", + "rgb(74, 102, 189)", + "rgb(93, 39, 93)", + "rgb(26, 28, 44)", + "rgb(6, 0, 17)", + "rgb(64, 54, 69)", + "rgb(237, 237, 255)", + "rgb(0, 0, 0)", ] if (sides <= 14 && sides >= 3){ return baseColors[Math.round(sides)-3] } else { - return {r: 0, g: 0, b: 0} + return "rgb(0, 0, 0)" } } isKeyDown = { w: false, a: false, s: false, - d: false + d: false, + i: false, + o: false +} +function HSVtoRGB(h, s, v) { + var r, g, b, i, f, p, q, t; + if (arguments.length === 1) { + s = h.s, v = h.v, h = h.h; + } + i = Math.floor(h * 6); + f = h * 6 - i; + p = v * (1 - s); + q = v * (1 - f * s); + t = v * (1 - (1 - f) * s); + switch (i % 6) { + case 0: r = v, g = t, b = p; break; + case 1: r = q, g = v, b = p; break; + case 2: r = p, g = v, b = t; break; + case 3: r = p, g = q, b = v; break; + case 4: r = t, g = p, b = v; break; + case 5: r = v, g = p, b = q; break; + } + return { + r: Math.round(r * 255), + g: Math.round(g * 255), + b: Math.round(b * 255) + }; +} +function RGBtoHSV(r, g, b) { + if (arguments.length === 1) { + g = r.g, b = r.b, r = r.r; + } + var max = Math.max(r, g, b), min = Math.min(r, g, b), + d = max - min, + h, + s = (max === 0 ? 0 : d / max), + v = max / 255; + + switch (max) { + case min: h = 0; break; + case r: h = (g - b) + d * (g < b ? 6: 0); h /= 6 * d; break; + case g: h = (b - r) + d * 2; h /= 6 * d; break; + case b: h = (r - g) + d * 4; h /= 6 * d; break; + } + + return { + h: h, + s: s, + v: v + }; +} +function colorToObject(color){ + list = color.match(/\d+/g); + list[0] = parseInt(list[0]) + list[1] = parseInt(list[1]) + list[2] = parseInt(list[2]) + return {r: list[0], g: list[1], b: list[2]} +} +function objectToColor(object){ + return "rgb(" + object.r + ", " + object.g + ", " + object.b + ")" +} +function darkenColor(color){ + let colorObject = colorToObject(color) + colorObject.r = Math.max(0, colorObject.r - 30) + colorObject.g = Math.max(0, colorObject.g - 30) + colorObject.b = Math.max(0, colorObject.b - 30) + return objectToColor(colorObject) +} +function makeVisible(color){ + let colorObject = colorToObject(color) + colorObject.r = Math.max(40, colorObject.r) + colorObject.g = Math.max(40, colorObject.g) + colorObject.b = Math.max(40, colorObject.b) + return objectToColor(colorObject) } // when wasd keydown, set isKeyDown to true document.addEventListener("keydown", (event) => { @@ -39,6 +126,12 @@ document.addEventListener("keydown", (event) => { if (event.key === "d") { isKeyDown.d = true } + if (event.key === "i") { + isKeyDown.i = true + } + if (event.key === "o") { + isKeyDown.o = true + } }) // when wasd keyup, set isKeyDown to false document.addEventListener("keyup", (event) => { @@ -54,11 +147,59 @@ document.addEventListener("keyup", (event) => { if (event.key === "d") { isKeyDown.d = false } + if (event.key === "i") { + isKeyDown.i = false + } + if (event.key === "o") { + isKeyDown.o = false + } + if (event.key === "m") { + if (debug){ + debug = false + } else { + debug = true + } + } }) orbitalSpeed = function(sides){ return 1/(1.00672*Math.pow(0.344151, sides) + 0.000002) } -shapeNames = ["Triangle", "Square", "Pentagon", "Hexagon", "Heptagon", "Octagon", "Nonagon", "Decagon", "Hendecagon", "Dodecagon", "Triskaidecagon", "Tetrakaidecagon", "Pentakaidecagon", "Hexakaidecagon", "Heptakaidecagon", "Octakaidecagon", "Enneakaidecagon", "Icosagon", "literally just a circle"] +function shapeNamer(sides) { + const ones = ["hen", "do", "tri", "tetra", "penta", "hexa", "hepta", "octa", "ennea"]; + const tens = ["deca", "icosa", "triaconta", "tetraconta", "pentaconta", "hexaconta", "heptaconta", "octaconta", "enneaconta"]; + const specialCases = { + 4: "square", + 2: "line", + 1: "point", + 3: "triangle", + 9: "nonagon", + 1000: "stop", + 1001: "please", + 1002: "go touch grass", + 1003: "are you serious" + }; + if (sides in specialCases) { + return specialCases[sides]; + } + function rb(v) { + return v ? v : ""; + } + const numberString = sides.toString(); + if (sides < 10) { + return ones[sides - 1] + "gon"; + } else if (sides < 100) { + const tensPlace = Math.floor(sides / 10); + const onesPlace = sides % 10; + return rb(ones[onesPlace - 1]) + tens[tensPlace - 1] + "gon"; + } else if (sides < 1000) { + const hundredsPlace = Math.floor(sides / 100); + const tensPlace = Math.floor((sides % 100) / 10); + const onesPlace = sides % 10; + return ones[hundredsPlace - 1] + "hecta" + rb(tens[tensPlace - 1]) + rb(ones[onesPlace - 1]) + "gon"; + } else { + return "literally just a circle"; + } +} function polygonCount(random){ const thresholds = [0, 0.3, 0.68, 0.77, 0.82, 0.86, 0.88, 0.89, 0.895, 0.8975, 0.898, 0.8982, 1]; const values = [3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 3]; @@ -70,12 +211,8 @@ function polygonCount(random){ } } polygonList = [] -zoomLevel = 1 -polygonSize = function(sides){ - return 18 * Math.pow(1.47, sides - 3) -} -for (var i = 0; i <= 400; i++){ - sides = polygonCount(Math.random()) +zoomLevel = 0.5 +function newPolygon(sides){ polygonList.push({ sides: sides, radius: polygonSize(sides), @@ -85,59 +222,143 @@ for (var i = 0; i <= 400; i++){ vy: 0, random: Math.random(), rotation: Math.random() * 2 * Math.PI, - collisionMass: 3+(polygonSize(sides)**2)/6 + collisionMass: 3+(polygonSize(sides)**2)/6, + maxHealth: 3+(polygonSize(sides)**2)/6, + health: 3+(polygonSize(sides)**2)/6, + type: 0, + bodyDamage: 3, + regenDelay: 20, + regenSpeed: 0.0007, + timeSinceHurt: null, + name: shapeNamer(sides) }) } -function drawPolygon(ctx, polygon){ - let x = polygon.x - let y = polygon.y - let sides = polygon.sides - let radius = polygon.radius - let rotation = polygon.rotation - let vx = polygon.vx - let vy = polygon.vy - ctx.lineJoin = 'round'; - ctx.fillStyle = "rgb(" + polygonColors(sides).r + ", " + polygonColors(sides).g + ", " + polygonColors(sides).b + ")" - ctx.strokeStyle = "rgb(" + Math.max(polygonColors(sides).r - 30, 0) + ", " + Math.max(polygonColors(sides).g - 30, 0) + ", " + Math.max(polygonColors(sides).b - 30, 0) + ")" - ctx.lineWidth = 5*zoomLevel - ctx.beginPath() - ctx.moveTo(Math.sin(rotation)*radius+x, Math.cos(rotation)*radius+y) - for (var i = 0; i <= sides+1; i++){ - ctx.lineTo(Math.sin(rotation+2*Math.PI*i/sides)*radius+x, Math.cos(rotation+2*Math.PI*i/sides)*radius+y) - } - ctx.fill() - ctx.stroke() - // debug - /* - // draw a line to represent angle - ctx.beginPath() - ctx.moveTo(x, y) - ctx.lineTo(Math.sin(rotation)*2*radius+x, Math.cos(rotation)*2*radius+y) - ctx.strokeStyle = "rgb(0, 0, 255)" - ctx.stroke() - // draw a line to represent velocity - ctx.beginPath() - ctx.moveTo(x, y) - ctx.lineTo(x+20*vx, y+20*vy) - ctx.strokeStyle = "rgb(255, 0, 0)" - ctx.stroke() - // draw some text to represent mass - ctx.lineWidth = 2 - ctx.fillStyle = "rgb(255, 255, 255)" - ctx.strokeStyle = "rgb(0, 0, 0)" - ctx.font = `bold 30px Helvetica` - ctx.fillText(Math.round(polygon.collisionMass), x, y) - ctx.strokeText(Math.round(polygon.collisionMass), x, y) - */ +polygonSize = function(sides){ + return 18 * Math.pow(1.47, sides - 3) } +for (var i = 0; i <= 400; i++){ + sides = polygonCount(Math.random()) + newPolygon(sides) +} +function drawPolygon(ctx, polygon, index){ + if (Math.abs(polygonList[index].x-camera[0]-polygon.radius collideList[poly].regenDelay){ + collideList[poly].health += collideList[poly].regenSpeed*collideList[poly].maxHealth + collideList[poly].health = Math.min(collideList[poly].health, collideList[poly].maxHealth) + } } // move polygons for (var poly = 0; poly < collideList.length; poly++){ @@ -236,6 +477,9 @@ renderPostPixel(function(ctx){ // add some velocity towards wherever its facing polygon.vx += Math.sin(polygon.rotation)/orbitalSpeed(polygon.sides)*8 polygon.vy += Math.cos(polygon.rotation)/orbitalSpeed(polygon.sides)*8 + if (polygon.health <= 0){ + polygonList.splice(poly, 1) + } } camera[0] += (scenexeplayer.x - camera[0])/10 camera[1] += (scenexeplayer.y - camera[1])/10 @@ -268,4 +512,10 @@ renderPostPixel(function(ctx){ scenexeplayer.vx += 1 } } + if (isKeyDown.i){ + zoomLevel += 0.02 + } + if (isKeyDown.o){ + zoomLevel -= 0.02 + } }) \ No newline at end of file