Solved

sass lighten equivalent in c#

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now