I made this fully responsive dynamic HSL colour controller with express.js and pug - a template engine for Node.
I used the W3Color JavaScript Library to convert the HSL values to RGB and HEX.
The HSL values are controlled by the range inputs which update CSS variables, which in turn display the colour and values in real time.
The colours
object, in views/index.pug
is used to render the range inputs
colours = {
h: { prop:'h', name: 'Hue', max: 360 },
s: { prop:'s', name: 'Saturation', max: 100 },
l: { prop:'l', name: 'Lightness', max: 100 }};
}
Here is how to iterate through the object to render each input. Notice the indentation which is necessary for pug to work:
each key in Object.keys(colours)
div.v-center
h3.m-5 #{colours[key].name}
input(
type='range'
class='slider'
name=`--${colours[key].prop}`
value=`${colours[key].max / 2}`
max=`${colours[key].max}`
min="0"
)
label #{colours[key].max / 2}
Links 🔗
Further reading
- A great article from css-tricks.com:
HSL() / HSLa() is great for programmatic color control - A useful colours tutorial from w3schools.com
Wow! now I can finally get the hang of the colors in my java codes...
Nice @RolandJLevy
Hey @LingWu1, thanks!
how did you get pug?
Wow!! Awesome!!
@Coder100 thanks!
np!
Btw a suggestion: style the range input, it kind of goes out of line with the theme if you know what I mean @RolandJLevy
@Coder100 I see what you mean. Good idea. I'll give it a try tomorrow. Thanks for the suggestion!
@RolandJLevy np! Good luck!
Hey @Coder100, I've styled the sliders as you suggested :)
Cool! But I think you made a mistake in your title since this is named "Weather App"
@DynamicSquid ah, well spotted. This was from one of my other pug projects I forked from. Thanks for pointing it out. I've updated it now