?
Solved

sass lighten equivalent in c#

Posted on 2014-04-07
5
Medium Priority
?
323 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
  • 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

862 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