Avatar

andrew

8 public vals
Joined December 16, 2022
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { fetch } from "https://esm.town/v/std/fetch";
import process from "node:process";
export const upscaleThisUrl = async (req, res) => {
const authToken = process.env.REPLICATE_API_TOKEN;
const url = "https://api.replicate.com/v1/predictions";
const jobId = req.body?.jobId;
const imageUrl = req.body?.imageUrl;
if (!jobId && !imageUrl) {
res.status(400).json({
error:
"You must pass either a jobId or an imageUrl. You did not pass either.",
});
}
if (jobId && imageUrl) {
res.status(400).json({
error:
"You must pass either a jobId or an imageUrl. You cannot pass both.",
});
}
if (imageUrl) {
const body = {
version:
"660d922d33153019e8c263a3bba265de882e7f4f70396546b6c9c8f9d47a021a",
input: {
image: imageUrl,
},
};
const result = await fetch(url, {
method: "POST",
headers: {
"Authorization": `Token ${authToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
const json = await result.json();
res.send(json);
}
if (jobId) {
const result = await fetch(url + "/" + jobId, {
method: "GET",
headers: {
"Authorization": `Token ${authToken}`,
"Content-Type": "application/json",
},
});
const json = await result.json();
res.send(json);
}
};
// Forked from @liamdanielduffy.upscaleThisUrl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// let's just focus on the state for a single player
// imagining that this is a single player game against the computer
export const CastleWarsState = () => {
interface Card {
name: string;
}
interface Zone {
cards: Card[]; // cards[0] is the top or left, cards[n] is the bottom or right
}
interface Deck extends Zone {
}
interface Hand extends Zone {
}
interface DiscardPile extends Zone {
}
interface GameState {
// if health goes to 0, you lose
health: Number;
// you can build your wall to block
wall: Number;
// use soldiers to play attacks, and barracks create soldiers
soldiers: Number;
barracks: Number;
// use materials to build infrastructure/wall, and builders create materials
materials: Number;
builders: Number;
// use magic to cast spells + enhance cards, wizards create magic
magic: Number;
wizards: Number;
// use food to grow population, farms create food
food: Number;
farms: Number;
// use money to buy + remove cards bankers create money
money: Number;
bankers: Number;
}
return;
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export const ValMMO_Diary =
"Is it possible to build an MMORPG on Valtown? Let's see...";
// Game Design:
// 1. It is a Card Game
// 2. OOOH, what if it is that Castle Wars game that I played as a kid. I loved that game, I bet I could recreate a modern version...
// 3. Maybe you build up your castle state over time, ala. Clash of Clans, and it's an async game?
// 4. But then when you're playing maybe you can either raid other players, or go on adventures // PvM.
// 5. I really love raids + big bosses, I wonder how you can make that a core part of the game?
// 6. Monster Hunter has no PvP, and it's still really good. Maybe it can be Castle Wars, but only PvM?
// 7. Then I can focus on PvM mechanics like raiding, cooperation, strategy, etc -- and balance isn't as big of a deal
// 8. I love the idea that you can slowly build up your economy, or... collect equipment + set synergies ala Diablo or MTG?
// 9. Inspo: Circadian Dice, Castle Wars, Diablo, Slay the Spire, MTG, Across the Obelisk
// 10. I don't want to get ahead of myself, though, so maybe start w/ Castle Wars, because it's easy to render, lmaoo.
// Entities:
// - Cards
// - Players
// - Characters?
// - Decks
// - CardCollections
// - Games
// - GameState
// - Steps + Phases -> Triggers -> GameState updates
// - Is it real-time? If so, we need ticks / time steps. The cool thing about a PvM card game is that it doesn't need to be real-time.
// - Equipment // Relics
// - Leveling Up?
// - Hardcore?
// Players have
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
export function percentLiftGasNeededSTP(
liftForce,
totalVolume,
molarMassLiftGas,
molarMassHeavyGas
) {
// Calculate the percent mix you need at STP of liftGas vs. heavyGas
const g = 9.81; // Acceleration due to gravity in m/s^2
const density_air = 1.225; // Density of air in kg/m^3 at sea level and at 15 °C
const molarVolume = 0.0224; // Molar volume in m^3/mol at STP
// Calculate the density of hydrogen and xenon at STP in kg/m^3
const densityLift = molarMassLiftGas / molarVolume;
const densityHeavyGas = molarMassHeavyGas / molarVolume;
// Calculate the density of the gas mixture required to generate the lift force in kg/m^3
const densityMix = density_air - liftForce / (totalVolume * g);
// Calculate the molar fraction of hydrogen required in the gas mixture
let liftFraction =
(densityMix - densityHeavyGas) / (densityLift - densityHeavyGas);
// Check if the calculated fraction is within the valid range
if (liftFraction < 0 || liftFraction > 1) {
console.error(
"Error: The calculated hydrogen fraction is outside the valid range. It's not possible to achieve the desired lift force with the given total volume of gas and the available gases (hydrogen and xenon)."
);
return null;
}
console.log(
`Percentage of hydrogen required in the gas mixture: ${liftFraction * 100}%`
);
return liftFraction;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { percentLiftGasNeededSTP } from "https://esm.town/v/andrew/percentLiftGasNeededSTP";
import { vMaxFillBalloon } from "https://esm.town/v/andrew/vMaxFillBalloon";
export const SO2_Balloon_Napkin_Math = (() => {
// How much Lifty SO2/H2 mixture can we send up 25000m to the stratosphere?
// Variables you might want to change
const dBurst = 9.44; // 9.44m burst diameter on a weather balloon (1500g)
const hBurst = 10000; // 25000m
const costBalloon = 25; // $
const unitCostH2 = 5; // $/kg
const unitCostSO2 = 0; // $/kg
// Constants
const lift = 1.6; // 1.6N lift needed to lift 1500g balloon + 100g extra
const molarMassHydrogen = 2.01588 / 1000; // in kg/mol
const molarMassSO2 = 64.07 / 1000; // in kg/mol
const densityH2 = 0.08988; // kg/m^3
const densitySO2 = 2.926; // kg/m^3
// how much gas can we fill the balloon with at STP, given burst diameter/height?
const maxFill = vMaxFillBalloon(dBurst, hBurst);
console.log(
`The maxFill is about ${maxFill.toPrecision(2)} m^3 of gas at STP.`
);
const percentHydrogen = percentLiftGasNeededSTP(
1.6,
maxFill,
molarMassHydrogen,
molarMassSO2
);
const totalH2 = percentHydrogen * maxFill;
const totalSO2 = (1 - percentHydrogen) * maxFill;
const costH2 = totalH2 * densityH2 * unitCostH2;
const costSO2 = totalSO2 * densitySO2 * unitCostSO2;
const totalCost = costH2 + costSO2 + costBalloon;
const unitCostPerSO2 = totalCost / totalSO2;
console.log(
`The cost of hydrogen is $${costH2.toPrecision(
2
)} for ${totalH2.toPrecision(2)} m^3 at STP.`
);
console.log(
`The cost of SO2 is $${costSO2.toPrecision(2)} for ${totalSO2.toPrecision(
2
)} m^3 at STP.\n`
);
console.log(
`The TOTAL UNIT COST is $${unitCostPerSO2.toPrecision(
2
)} per cubic meter of SO2 released at ${hBurst}m`
);
return unitCostPerSO2;
})();
1
2
3
4
export function vSphere(radius: number) {
const V = (4 / 3) * Math.PI * Math.pow(radius, 3);
return V;
}
1
2
3
4
5
6
import { newRSSItems } from "https://esm.town/v/stevekrouse/newRSSItems?v=6";
export const RSSFeed = newRSSItems({
url: "https://inkandswitch.com/index.xml",
lastRunAt: "January 01, 2020",
});
1
2
3
import { hnTopStory } from "https://esm.town/v/stevekrouse/hnTopStory?v=3";
export const hnTopStoryExample = hnTopStory();
Next