cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

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.

            
              <body>
  <div class="container">
    <div id="city-names"></div>
  </div>
</body>
            
          
!
            
              body {
  background-color: #0F0923;
  color: #dd3535;
  display:flex;
  align-items: center;
  flex-direction: column;
  font-size:16px;
  font-family: 'titleFont';
}

#city-names {
  font-size: 9em;
  margin: 0.2em 0;
  line-height: 1em;
  font-weight: normal;
  font-family: 'weatherFont';
}

h2 {
  font-family: 'baseFont';
}

.container {
  width: 90%;
}

#city-names span:nth-of-type(3n-1) {
  color: #fefefe ;
}

#city-names span:nth-of-type(3n-2) {
  color: #36e8ff ;
}
            
          
!
            
              //Try the library here https://app.prototypo.io
// This function takes a city and a callback
// It returns the weather data of the city
function yahooApiQuery(city, callback) {
  if (!city || !callback) {
    throw new Error('$.YQL(): Parameters may not be undefined');
  }
  const encodedQuery = encodeURIComponent(
    `select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='${city}')`.toLowerCase()
  );
  const url = `https://query.yahooapis.com/v1/public/yql?q=${encodedQuery}&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=?`;
  $.getJSON(url, callback);
};

// This takes a city and a PtypoFont object
// It requests the Yahoo weather API and change the params of the font accodingly
function getValueAndChangeFont(city, font) {
  yahooApiQuery(
    city,
    function(data) {
      font.changeParams({
        thickness: parseInt(data.query.results.channel.item.condition.temp) * 2,
        slant: parseInt(data.query.results.channel.wind.speed),
      });
    }
  );
}

const cities = [
  'Marrakech',
  'Moscow',
  'Padova',
  'Lyon',
  'Rennes',
  'Tokyo',
  'Johannesburg',
  'Beijing',
  'San Francisco',
  'Savissivik',
  'Tolhuin',
  'Tignes',
];

// Creates the prototypo font factory
const ptypoFactory = new Ptypo.default();

// For each cities creates a span element styled with the correct font
cities.forEach(function(city, idx) {
  $('#city-names').append(
    `<span style="font-family: ${city}WeatherFont">${city}</span> `
  );
  
  // Creates a font with the same name and call getValueAndChangeFont with the city
  // name and the PtypoFontObject
  ptypoFactory.createFont(
    `${city}WeatherFont`,
    Ptypo.templateNames.ANTIQUE).then(
      function(font) {
        getValueAndChangeFont(city, font);
      }
    ); 
});
            
          
!
999px
Loading ..................

Console