Solved

sass lighten equivalent in c#

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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