3D Printing Cost Calculator
3D printing is a popular hobby enjoyed by many. Filament and electricity are the 2 main consumables used by one of these machines. To estimate a budget for a 3D printing project, I made a calculator using html.
Code:
function calculate() {
var filament = document.getElementById("filament").value;
var accuracy = document.getElementById("accuracy").value;
var ptime = document.getElementById("ptime").value;
var filcost = document.getElementById("filcost").value / 1000; // Dollars per gram. Dividing the price of 1kg of filament by 1000 returns the price for 0.001kg; or 1g.
var eleccost = document.getElementById("eleccost").value * 0.29; // Dollars per hour. Electricity cost divided by 1000 gives the price per watt-hour. The Snapmaker A350 system uses 290 watts every hour. Multiplying the Wh cost by 290 returns the cost of electricty for every hour of print time.
var cost = (Number(ptime) * Number(eleccost)) + (Number(filament) * Number(filcost)); // ptime * elceccost = time multiplied by the cost of 1 hour of electricity. Grams of filament multiplied by the cost per gram.
document.getElementById("cost").innerHTML = (Math.floor(cost * 100) / 100).toFixed(Number(accuracy)); // Truncates the cost to an amount specified by the user.
}
Full code availible at https://raw.githubusercontent.com/LinuxNinja99/3dprintercostcalc/main/index.html.