Solved

sass lighten equivalent in c#

Posted on 2014-04-07
5
283 Views
Last Modified: 2014-05-05
I am using SASS in a project and use the "lighten" and "darken" functions in the scss file.

I need to dynamically create a stylesheet (a small subset actually) that uses a different starting colour and then produces the necessary "lighten" and "darken" colours.

The starting colour will be set by a user in the website CMS so I cannot use SASS to generate the css file.

I have tried various methods in C# to recreate the "lighten" and "darken" functions but I can't get the same results as produced by SASS.

For example, for a starting colour of #c640db, SASS gives "lighten(#c640db, 10%)" as #d36be3.

I have tried adjusting the luminance, also the RGB values and neither methods get me the same result as above.

Does anyone know exactly what the SASS function does and/or how to recreate it in C#?
0
Comment
Question by:ascendinternet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 39982964
Sass is an extension language specifically off of CSS
you cannot recreate it in C#
0
 

Author Comment

by:ascendinternet
ID: 39983001
I didn't ask how to recreate SASS in C# - I want to know how the Lighten and Darken functions work (i.e. specifically how do they adjust colour values) so that I can do the same thing and get the same result in C#
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 39983104
the functions have a pretty big library of colors and from what I was reading a pretty big math algorythim that was written in Ruby  that will lighten and darken based of color and the algor will lighten or darken the shades from it color likbrary
0
 

Accepted Solution

by:
ascendinternet earned 0 total points
ID: 39983238
I have found this and it gives reasonably close results ...

http://richnewman.wordpress.com/about/code-listings-and-diagrams/hslcolor-class/

to which I added a "lighten" and "darken" function:

        
        public HSLColour Darken(double darkenAmount)
        {
            var hslColor = this;
            hslColor.Luminosity -= darkenAmount; // 0 to 1
            return hslColor;
        }

        public HSLColour Lighten(double lightenAmount)
        {
            var hslColor = this;
            hslColor.luminosity += lightenAmount; // 0 to 1
            return hslColor;
        }

Open in new window

0
 

Author Closing Comment

by:ascendinternet
ID: 40041620
No other solutions were offered and my comment was an acceptable solution / resolution to the problem.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question