Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Trispace&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script><!-- needed for geolocator -->


<div id="location">Conditions in <span id="youarehere">your area</span></div>
<br>
<div id="data">
    <div class="info">
      <h1>Time & Place</h1>
      <span id="clock">Loading...</span>
      <span id="latlon"></span>
      <span id="zip"></span>
    </div>
    <div class="info">
      <h1>Raw Data</h1>
      <span id="desc">Loading...</span>
      <span id="precip"></span>
      <span id="sunrise"></span>
      <span id="sunset"></span>
      <span id="moon"></span>
      <span id="temp"></span>
    </div>
    <div class="info">
      <h1>Calculations</h1>
      <span>Dawn:&emsp;sunrise ± 1.5</span>
      <span>Dusk:&emsp;sunset ± 1.5</span>
      <span>Day:&emsp;sunrise + 1.5 &ndash; sunset - 1.5</span>
      <span>Night:&emsp;sunset + 1.5 &ndash; sunrise - 1.5</span>
      <span>Full Moon:&emsp;phase 0.5 &plusmn; 0.1</span>
      <span>C&#176; = K&#176; - 273.15</span>
      <span>F&#176; = (K&#176; - 273)*1.8 + 32</span>
    </div>
</div>
      
<!---------------------------------------------------->

<div class="divTable planter-grid" style="margin-top: 32px;">
<div class="divTableHeading">
                                
  <div class="divTableBody">
    <div class="divTableRow" id="herbIMG">
      <div class="divTableCell"><div class="herb" id="waterleaf"><img src="https://2021.amyhollen.com/img/codepen/terraria/gif/waterleaf-closed.gif" alt="waterleaf"></div></div>
      <div class="divTableCell"><div class="herb" id="daybloom"><img src="https://2021.amyhollen.com/img/codepen/terraria/gif/daybloom-closed.gif" alt="daybloom"></div></div>
      <div class="divTableCell"><div class="herb" id="fireblossom"><img src="https://2021.amyhollen.com/img/codepen/terraria/gif/fireblossom-closed.gif" alt="fireblossom"></div></div>
      <div class="divTableCell"><div class="divTableHead herb" id="moonglow"><img src="https://2021.amyhollen.com/img/codepen/terraria/gif/moonglow-closed.gif" alt="moonglow"></div></div>
      <div class="divTableCell"><div class="divTableHead herb" id="deathweed"><img src="https://2021.amyhollen.com/img/codepen/terraria/gif/deathweed-closed.gif" alt="deathweed"></div></div>
      <div class="divTableCell"><div class="divTableHead herb" id="shiverthorn"><img src="https://2021.amyhollen.com/img/codepen/terraria/gif/shiverthorn-closed.gif" alt="shiverthorn"></div></div>
      <div class="divTableCell"><div class="divTableHead herb" id="blinkroot"><img src="https://2021.amyhollen.com/img/codepen/terraria/gif/blinkroot-closed.gif" alt="blinkroot"></div></div>
    </div>
  </div>                                                                                                                                                     
  
  <div class="divTableBody">
    <div class="divTableRow" id="herbName">
      <div class="divTableCell">Waterleaf</div>
      <div class="divTableCell">Daybloom</div>
      <div class="divTableCell">Fireblossom</div>
      <div class="divTableCell">Moonglow</div>
      <div class="divTableCell">Deathweed</div>
      <div class="divTableCell">Shiverthorn</div>
      <div class="divTableCell">Blinkroot</div>
    </div>
  </div>
                               
</div>

<div class="herbHeader">Real Time Bloom Conditions</div>

<div class="divTable planter-grid">
  <div class="divTableRow" id="herbIRL">
    <div class="divTableCell">Rain</div>
    <div class="divTableCell">Dawn <br>&ndash; Sunset</div>
    <div class="divTableCell">Dusk</div>
    <div class="divTableCell">Sunset <br>&ndash; Dawn</div>
    <div class="divTableCell">Full Moon<br><u>AND</u> Night</div>
    <div class="divTableCell">Freezing</div>
    <div class="divTableCell">Random</div>
  </div>

  <div class="divTableRow" id="herbCalc">
    <div class="divTableCell">rain &gt; 0</div>
    <div class="divTableCell">t &ge; sunrise - 1.5 <br>&amp; <br>t &lt; sunset</div>
    <div class="divTableCell">t &ge; sunset - 1.5 <br>&amp; <br>t &lt; sunset + 1.5</div>
    <div class="divTableCell">t &ge; sunset <br>OR <br>t &lt; sunrise - 1.5</div>
    <div class="divTableCell">moon &gt; 0.4 <br>&amp; <br>moon &lt; 0.1 <br>&amp;<br>night = true</div>
    <div class="divTableCell">&le; 273&#176; K <br>&le; 0&#176; C <br>&le; 32&#176; F</div>
    <div class="divTableCell">= 1</div>
  </div>
  

<!--
------ SUN ------
      Twilight Dawn   3 hours   ~ 4:30 AM   ~ 7:29 AM
  ___ sunrise ~ 6:00 AM
  🌞  Day             9 hours   ~ 7:30 AM   ~ 4:29 PM
      Twilight Dusk   3 hours   ~ 4:30 PM   ~ 10:29 PM
  ___ sunset ~ 6:00 PM
  🌙  Night           9 hours   ~ 10:30 PM  ~ 4:29 AM

------ MOON ------
  🌑  1|0   New Moon
  🌒        Waxing Crescent
  🌓  0.25  First Quarter
  🌔        Waxing Gibbous
  🌕  0.5   Full Moon
  🌖        Waning Gibboous
  🌗  0.75  Last Quarter
  🌘        Waning Crescent
-->
  
  <div class="divTableRow" id="herbData">
    <div class="divTableCell"><p id="rain"></p></p></div>
    <div class="divTableCell"><p id="day"></p></div>
    <div class="divTableCell"><p id="dusk"></p></div>
    <div class="divTableCell"><p id="night"></p></div>
    <div class="divTableCell"><p id="moonphase"></p></div>
    <div class="divTableCell"><p id="freeze"></p></div>
    <div class="divTableCell"><p id="blink"></p></div>
  </div>
</div>

<div class="herbHeader">In-Game Bloom Conditions</div>

<div class="divTable planter-grid">
  <div class="divTableRow" id="herbGame">
    <div class="divTableRow">
      <div class="divTableCell">Rain</div>
      <div class="divTableCell">4:30am - 7:29pm</div>
      <div class="divTableCell">3:45pm - 7:30pm</div>
      <div class="divTableCell">7:30pm - 4:29am</div>
      <div class="divTableCell">Full moon @ 7:30pm - 4:29am</div>
      <div class="divTableCell">After enough time passed, then ∞</div>
      <div class="divTableCell">Random</div>
    </div>
    <div class="divTableRow">
      <div class="divTableCell">
        <img src="https://2021.amyhollen.com/img/codepen/terraria/img/waterleaf-closed.png" style="width:40px"><img src="https://2021.amyhollen.com/img/codepen/terraria/img/waterleaf-bloom.png" style="width:40px"></div>
      <div class="divTableCell">
        <img src="https://2021.amyhollen.com/img/codepen/terraria/img/daybloom-closed.png" style="width:40px"><img src="https://2021.amyhollen.com/img/codepen/terraria/img/daybloom-bloom.png" style="width:40px"></div>
      <div class="divTableCell">
        <img src="https://2021.amyhollen.com/img/codepen/terraria/img/fireblossom-closed.png" style="width:40px"><img src="https://2021.amyhollen.com/img/codepen/terraria/img/fireblossom-bloom.png" style="width:40px"></div>
      <div class="divTableCell">
        <img src="https://2021.amyhollen.com/img/codepen/terraria/img/moonglow-closed.png" style="width:40px"><img src="https://2021.amyhollen.com/img/codepen/terraria/img/moonglow-bloom.png" style="width:40px"></div>
      <div class="divTableCell">
        <img src="https://2021.amyhollen.com/img/codepen/terraria/img/deathweed-closed.png" style="width:40px"><img src="https://2021.amyhollen.com/img/codepen/terraria/img/deathweed-bloom.png" style="width:40px"></div>
      <div class="divTableCell">
        <img src="https://2021.amyhollen.com/img/codepen/terraria/img/shiverthorn-closed.png" style="width:40px"><img src="https://2021.amyhollen.com/img/codepen/terraria/img/shiverthorn-bloom.png" style="width:40px"></div>
      <div class="divTableCell">
        <img src="https://2021.amyhollen.com/img/codepen/terraria/img/blinkroot-closed.png" style="width:40px"><img src="https://2021.amyhollen.com/img/codepen/terraria/img/blinkroot-bloom.png" style="width:40px"></div>
     </div>
   </div>
 </div>
              
            
!

CSS

              
                *{
  margin:0;
  padding: 0;
  box-sizing: border-box;
}


body {
  background-color: #B6CC92;
}

a {
  color: #DD367A;
}

@import url('https://fonts.googleapis.com/css2?family=Trispace:wght@500&display=swap');

/*---------------*/


.close{
  float: right;
  margin-top: -2px;
  cursor: pointer;
  margin-right: 20px;
}





/*---------------*/


.planter-grid {
  width: 896px;
  margin:0 auto;"
  border-collapse: collapse;
  font-family: 'Arial';
}

.planter-grid p {
  color: #DD367A;
  text-weight: bold;
}

.divTable {display: table; margin-bottom: 16px;}
.divTableRow {display: table-row;}
.divTableHeading {display: table-header-group;}
.divTableCell, .divTableHead {display: table-cell;}
.divTableHeading {display: table-header-group;}
.divTableFoot {display: table-footer-group;}
.divTableBody {display: table-row-group;}


#location {
  text-align: center;
  font-size: 1.25em;
  font-weight: bold;
  font-family: 'Arial';
  color: #336600;
  padding: 2em 0 1em 0;
  position: relative;
}

#data {
  display: table;
  margin: 0 auto;
  font-size: 1em;
  font-weight: normal;
  font-family: 'Arial';
  color: #336600;
  padding: 0.5em 0 1em 0;
  position: relative;
}

.info {
  display: table-cell;
  padding: 0 1em;
}

.info h1 {
  font-size: 1em;
  padding: 1em 2em 0.5em 0;
  border-bottom: 2px solid #ffffff;
}

.info span {
  display: block;
  text-alight: left;
  padding: 0.5em 0 0 0;
}

hr {
  border-top: 3px dashed #AAC16C;
  border-bottom: 0px;
  border-left: 0px;
  border-right: 0px;
  margin: 0.5em 0;
}

#youarehere {
  text-align: center;
  font-size: 1.75em;
  font-weight: bold;
  font-family: 'Trispace', sans-serif;
}

.herb, .herb img {
  display: inline-block;
  padding: 0;
  margin: 0;
}

#herbName div {
  text-align: center;
  font-size: 0.9em;
  font-weight: bold;
  font-family: 'Trispace', sans-serif;
  color: #336600;
  padding: 32px 0 16px 0;
}

#herbCalc div {
  font-size: 0.75em;
}

.herbHeader {
  text-align: center;
  font-size: 0.8em;
  font-weight: bold;
  font-family: 'Arial';
  padding: 10px;
  width: 896px;
  margin:0 auto;
  background-color: #AAC16C;
}

#herbIRL div, #herbCalc div, #herbData div, #herbSource div, #herbGame div {
  text-align: left;
  padding: 10px;
  width: 128px;
}

/*---------------*/
              
            
!

JS

              
                // geolocator
$.ajax({
  url: "https://geolocation-db.com/jsonp",
  jsonpCallback: "callback",
  dataType: "jsonp",
  success: function (location) {
    console.log("Location data:", location);

    const lat = location.latitude;
    const lon = location.longitude;
    const city = location.city || "Unknown";
    const postal = location.postal || "Unknown";

    if (lat && lon) {
      console.log(`Latitude: ${lat}, Longitude: ${lon}, City: ${city}, Postal: ${postal}`);
      document.getElementById("youarehere").innerHTML = `${city}`;
      fetchWeatherData(lat, lon);
    } else {
      console.error("Location data is incomplete.");
      document.getElementById("youarehere").innerHTML = "Could not determine your location.";
    }
  },
  error: function (xhr, status, error) {
    console.error("Error fetching location data:", status, error);
    document.getElementById("youarehere").innerHTML = "Error fetching your location.";
  }
});

function fetchWeatherData(lat, lon) {
  const apiKey = "ba831721c720f526fc5ad726bb03faa3";
  const weatherUrl = `https://api.openweathermap.org/data/2.5/onecall?lat=${lat}&lon=${lon}&appid=${apiKey}`;

  fetch(weatherUrl)
    .then(response => {
      console.log("Response Status:", response.status);
      if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`);
      }
      return response.json();
    })
    .then(data => {
      console.log("Weather data:", data);

      const { current, daily, hourly } = data;

      const descValue = hourly[0].weather[0].main;
      const rainValue = daily[0].rain || 0;
      const snowValue = daily[0].snow || 0;
      const sunriseValue = new Date(current.sunrise * 1000).toLocaleTimeString([], { hourCycle: 'h23', hour: '2-digit', minute: '2-digit' });
      const sunsetValue = new Date(current.sunset * 1000).toLocaleTimeString([], { hourCycle: 'h23', hour: '2-digit', minute: '2-digit' });
      const moonValue = daily[0].moon_phase;
      const tempValueC = Math.round(current.temp - 273);
      const tempValueF = Math.round((current.temp - 273) * 1.8 + 32);
      const time = new Date().toLocaleTimeString([], { hourCycle: 'h23', hour: '2-digit', minute: '2-digit' });

      // Display weather data
      document.getElementById("desc").innerHTML = `Conditions: ${descValue}`;
      document.getElementById("precip").innerHTML = `Rain: ${rainValue} mm/h | Snow: ${snowValue} mm/h`;
      document.getElementById("sunrise").innerHTML = `Sunrise: ${sunriseValue}`;
      document.getElementById("sunset").innerHTML = `Sunset: ${sunsetValue}`;
      document.getElementById("moon").innerHTML = `Moon Phase: ${moonValue}`;
      document.getElementById("temp").innerHTML = `Temperature: ${tempValueC}°C | ${tempValueF}°F`;

      // Display herb bloom conditions
      if (rainValue > 0) {
        document.getElementById("waterleaf").innerHTML = '<img src="https://amyhollen.com/sites/default/files/gallery/codepen/terraria/gif/waterleaf-bloom.gif">';
      } else {
        document.getElementById("waterleaf").innerHTML = '<img src="https://amyhollen.com/sites/default/files/gallery/codepen/terraria/gif/waterleaf-closed.gif">';
      }

      if (time >= sunriseValue && time < sunsetValue) {
        document.getElementById("daybloom").innerHTML = '<img src="https://amyhollen.com/sites/default/files/gallery/codepen/terraria/gif/daybloom-bloom.gif">';
      } else {
        document.getElementById("daybloom").innerHTML = '<img src="https://amyhollen.com/sites/default/files/gallery/codepen/terraria/gif/daybloom-closed.gif">';
      }

      if (time >= sunsetValue) {
        document.getElementById("fireblossom").innerHTML = '<img src="https://amyhollen.com/sites/default/files/gallery/codepen/terraria/gif/fireblossom-bloom.gif">';
      } else {
        document.getElementById("fireblossom").innerHTML = '<img src="https://amyhollen.com/sites/default/files/gallery/codepen/terraria/gif/fireblossom-closed.gif">';
      }

      if (time >= sunsetValue || time < sunriseValue) {
        document.getElementById("moonglow").innerHTML = '<img src="https://amyhollen.com/sites/default/files/gallery/codepen/terraria/gif/moonglow-bloom.gif">';
      } else {
        document.getElementById("moonglow").innerHTML = '<img src="https://amyhollen.com/sites/default/files/gallery/codepen/terraria/gif/moonglow-closed.gif">';
      }

      if (moonValue > 0.4 && moonValue < 0.6) {
        document.getElementById("deathweed").innerHTML = '<img src="https://amyhollen.com/sites/default/files/gallery/codepen/terraria/gif/deathweed-bloom.gif">';
      } else {
        document.getElementById("deathweed").innerHTML = '<https://amyhollen.com/sites/default/files/gallery/codepen/terraria/gif/deathweed-closed.gif">';
      }

      if (tempValueC < 0) {
        document.getElementById("shiverthorn").innerHTML = '<img src="https://amyhollen.com/sites/default/files/gallery/codepen/terraria/gif/shiverthorn-bloom.gif">';
      } else {
        document.getElementById("shiverthorn").innerHTML = '<img src="https://amyhollen.com/sites/default/files/gallery/codepen/terraria/gif/shiverthorn-closed.gif">';
      }

      // Blinkroot random bloom
      let ran = Math.floor(Math.random() * 2);
      if (ran === 1) {
        document.getElementById("blinkroot").innerHTML = '<img src="https://amyhollen.com/sites/default/files/gallery/codepen/terraria/gif/blinkroot-bloom.gif">';
      } else {
        document.getElementById("blinkroot").innerHTML = '<img src="https://amyhollen.com/sites/default/files/gallery/codepen/terraria/gif/blinkroot-closed.gif">';
      }

    })
    .catch(err => {
      console.error("Error fetching weather data:", err);
      document.getElementById("temp").innerHTML = "Error fetching weather data.";
    });
}

              
            
!
999px

Console