Solved

sass lighten equivalent in c#

Posted on 2014-04-07
5
289 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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