Skip to content

Instantly share code, notes, and snippets.

@hyonschu
Created May 15, 2013 05:57
Show Gist options
  • Save hyonschu/5581902 to your computer and use it in GitHub Desktop.
Save hyonschu/5581902 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src = "jquery-1.9.1.min.js"></script>
<body>
<h1>/r/ketogains Macro Calculator</h1>
<div id = "1" style="float:left; width:300px">
<h2>Start Here</h2>
<p><input type ="text" class="weight" value="170.5" size="5"></input> Your weight in lbs</p>
<p><input class = "bodyfat" value="13.0" size="5"></input> Your body fat %</p>
<p><input class = "cardiom" value="30" size="5"></input> Min of Cardio (8 kcal/min est.)</p>
<p><input class = "liftm" value="30" size="5"></input> Min of Lifting (8 kcal/min est.)</p>
<p><button class="calculate" value="calculate">calculate!</button></p>
<h2>Body Comp Breakdown</h2>
<p><strong><text class = "lean calcs">0</text> lbs</strong> lean body mass.</P>
<p><strong><span class="ree calcs">0</span></strong> kcal <a href = "http://www.vacumed.com/293.html" target="_blank">Resting Energy Expend</a></p>
<p><strong><span class="tef calcs">0</span></strong> kcal <a href = "http://en.wikipedia.org/wiki/Thermic_effect_of_food" target="_blank">Thermal Effect of Food</a></p>
<p><strong><span class="cardioc calcs">0</span></strong> cardio kcal burned</p>
<p><strong><span class="liftc calcs">0</span></strong> lifting kcal burned</p>
</div>
<div id = "2" style="float:left; width:300px">
<h2> Rest Day Intake</h2>
<p>Maintenance calories: <strong><span class = "restcal calcs">0</span> calories/ day </strong></p>
<p>Protein Intake: <strong><span class = "proteing calcs">0</span> g of protein/d ay </strong></p>
<p>Fat Intake: <strong><span class = "fatg calcs">0</span> g of fat/ day </strong></p>
<p>Carbs Intake: <strong><span class = "carbg calcs">0</span> g of carbs MAX/ day </strong></p>
<p>&nbsp; </p>
<h2> Workout Day Intake</h2>
<p>Maintenance calories: <strong><span class = "workcal calcs">0</span> calories/ day </strong></p>
<p>Protein Intake: <strong><span class = "wproteing calcs">0</span> g of protein/ day </strong></p>
<p>Fat Intake: <strong><span class = "wfatg calcs">0</span> g of fat/ day </strong></p>
<p>Carbs Intake: <strong><span class = "wcarbg calcs">0</span> g of carbs MAX/ day </strong></p>
</div>
<div id = "3" style="float:left; width:400px">
<h2> Your Macro Breakdowns</h2>
<div width="300"><span class="charts"></span>
<p><button class="breakdown">Break it DOWN!</button></p>
</div>
</div>
<script>
calculated = false
$(document).ready( function() {
$(".calculate").click( function() {
bfp = (1-($(".bodyfat").val()/100));
lean = ($(".weight").val()*bfp).toFixed(2);
ree = (lean*11);
tef = (lean*1.1);
totalcal = (ree+tef);
proteing = (lean*0.8).toFixed(2);
fatg = ((totalcal*(2/3))/9).toFixed(2);
carbg = ((totalcal-(fatg*9)-(proteing*4))/4).toFixed(2);
proteincal = proteing*4;
cardioc = ($(".cardiom").val()*8).toFixed(1);
liftc = ($(".liftm").val()*8).toFixed(1);
wproteing = (lean*1.2).toFixed(2);
workcal= parseInt(totalcal+cardioc+liftc);
wcarbg = ((workcal*0.05)/4);
wfatg = ((workcal-(wproteing*4)-(wcarbg*4))/9).toFixed(2);
$(".calcs").empty();
$(".lean").append(lean);
$(".ree").append(ree);
$(".tef").append(tef);
$(".restcal").prepend(totalcal);
$(".proteing").prepend(proteing);
$(".fatg").prepend(fatg);
$(".carbg").prepend(carbg);
$(".cardioc").prepend(cardioc);
$(".liftc").prepend(liftc);
$(".workcal").prepend(workcal);
$(".wproteing").prepend(wproteing);
$(".wfatg").prepend(wfatg);
$(".wcarbg").prepend(wcarbg);
calculated = true;
});
$(".breakdown").click( function() {
if ( calculated == false )
{ alert("You need to calculate your macros first!"); }
else {
$(".charts").empty();
var fatcal = fatg*9;
var carbcal = carbg*4;
var proteinw = (proteincal/totalcal);
var fatw = (fatcal/totalcal);
var carbw = (carbcal/totalcal);
var wproteinw = ((wproteing*4)/workcal);
var wfatw = ((wfatg*9)/workcal);
var wcarbw = ((wcarbg*4)/workcal);
var barc = "<h4>Calories Breakdown</h4><p><div style='float: left; background-color: yellow; width: "+fatw*400+"px;'><center>"+(fatw*100).toFixed(1)+"</div><div style='float: left; background-color: blue; width: "+proteinw*400+"px;'><center>"+(proteinw*100).toFixed(1)+"</div><div style='float: left; background-color: red; width: "+carbw*400+"px;'><center>"+(carbw*100).toFixed(1)+"</div></p><br><br><h4>Workout Calories Breakdown</h4><div style='float: left; background-color: yellow; width: "+wfatw*400+"px;'><center>"+(wfatw*100).toFixed(1)+"</div><div style='float: left; background-color: blue; width: "+wproteinw*400+"px;'><center>"+(wproteinw*100).toFixed(1)+"</div><div style='float: left; background-color: red; width: "+wcarbw*400+"px;'><center>"+(wcarbw*100).toFixed(1)+"</div></p>";
$(".charts").append(barc).slideDown();}
})
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment