Click here to Skip to main content
16,016,537 members
Articles / Web Development / ASP.NET
Article

Pick Color

Rate me:
Please Sign up or sign in to vote.
3.50/5 (9 votes)
13 May 2003 98.7K   1.2K   27   6
A fun color picker in ASP.NET

Sample Image - Pick_Color.jpg

Introduction

This is an amusing way in order to select a color from a page web.

Using the code

As it is knows that the coordinates of a color comes from Red Blue Green (RGB), in order to create the intentional shadings we must convert to Luninosità tone Saturation (HLS). The function is as follows :-

VB.NET
Private Sub Paletta(ByVal TargetForm As String, _
  ByVal PalettaRow As Long, _
  ByVal Saturation As Long)
     Dim RGBColor As String
     Dim Gray As Double
     Dim lum As Double
     Dim sat As Double
     Dim hue As Double
     Dim row As HtmlTableRow
     Dim cell As HtmlTableCell
     Dim RBGcolor As String

     sat = Saturation / 100
     For hue = 0 To 359 Step (360 / PalettaRow)
         row = New HtmlTableRow()
         For lum = 0.1 To 1 Step 0.02
             cell = New HtmlTableCell()
             HlsToRgb(hue, lum, sat, RGBColor)
             cell.BgColor = RGBColor
             cell.Controls.Add(New HyperLink())
             DirectCast(cell.Controls(0), HyperLink).Text = "_"
             DirectCast(cell.Controls(0), HyperLink).ForeColor = _
                 Color.FromArgb(Val("&h" & Mid(RGBColor, 1, 2)), _
                 Val("&h" & Mid(RGBColor, 3, 2)), _
                 Val("&h" & Mid(RGBColor, 5, 2)))
             DirectCast(cell.Controls(0), HyperLink).NavigateUrl = _
                 TargetForm & "?&C=" & RGBColor
             row.Cells.Add(cell)
         Next lum
         Table1.Rows.Add(row)
     Next hue
     row = New HtmlTableRow()
     For Gray = 0 To 255 Step 5.7
         cell = New HtmlTableCell()
         cell.BgColor = Right("00" & Hex(Gray), 2) & _
            Right("00" & Hex(Gray), 2) & Right("00" & Hex(Gray), 2)
         cell.Controls.Add(New HyperLink())
         DirectCast(cell.Controls(0), HyperLink).Text = "_"
         DirectCast(cell.Controls(0), HyperLink).ForeColor = _
            Color.FromArgb(Gray, Gray, Gray)
         DirectCast(cell.Controls(0), HyperLink).NavigateUrl = _
            TargetForm & "?&C=" & Right("00" & Hex(Gray), 2) & _
            Right("00" & Hex(Gray), 2) & Right("00" & Hex(Gray), 2)
         row.Cells.Add(cell)
     Next Gray
     Table1.Rows.Add(row)
 End Sub

 ' Converte HLS in RGB
 Private Sub HlsToRgb(ByVal H As Double, ByVal L As Double, _
       ByVal S As Double, ByRef RGBColor As String)
     Dim p1 As Double
     Dim p2 As Double
     Dim r As Double
     Dim g As Double
     Dim b As Double

     If L <= 0.5 Then
         p2 = L * (1 + S)
     Else
         p2 = L + S - L * S
     End If
     p1 = 2 * L - p2
     If S = 0 Then
         r = Int(L * 255)
         g = Int(L * 255)
         b = Int(L * 255)
     Else
         r = Int(QqhToRgb(p1, p2, H + 120) * 255)
         g = Int(QqhToRgb(p1, p2, H) * 255)
         b = Int(QqhToRgb(p1, p2, H - 120) * 255)
     End If
     RGBColor = Right("00" & Hex(r), 2) & Right("00" & Hex(g), 2) & _
         Right("00" & Hex(b), 2)
 End Sub

The function Paletta previews the page where we give back the result, given the number of lines that composes the table and the brightness (that translates to "full" color or complete gray). After we have printed the table, and have selected the proposed color, the result is collected through :

Request.QueryString("C")

Points of Interest

This code has been translated from my site Web originally in ASP, and served to modify all the elements of the page web (Links, tables, etc.)

History

This is the first version of the Pick Color, but I have some changes already in mind for even more fun... Bye bye :)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Attuale incarico lavorativo
Amministratore di un server Intranet, Programmatore del relativo sito Web (attualmente impengato nel porting da ASP in ASP.NET), Beta Tester, Sviluppo di applicazioni di sicurezza informatica.

Linguaggi e ambienti di programmazione
Windows XP Assembler Intel Pentium (API), Framework.net, Visual C.NET (win32 e MFC), SQL, Visual Basic.NET, VBA, HTML, DHTML, IIS, ASP.NET, ActiveX.
MSDos 6.0 Assembler Intel Pentium (Interrupt e ports), Turbo ASM, Watcom C; Clipper; Basic.

Sistemi Operativi
Windows XP Professional SP1

Software
Sicurezza Softice, Procdump, W32 Dasm, Quaid Analyzer, AFD.
Pacchetti Office 2000 (Winword, Excel, PowerPoint, Access), MSWorks 95.
Grafica CorelDRAW 9, Paint Shop Pro 6.0, Abode Photoshop 6.0, Macromedia Director 8, Cool 3D.
Internet Internet Explorer 5.5, Netscape 6.0, Sam Spade 1.14, NeoTrace 3.01, SpyNet 3.0.
Suono Cool Edit 4.5, AudioCatalyst 2.1.

Skills professionali
Sicurezza Realizzazione di programmi con tecniche stealth e antidebug; blocco temporaneo o totale della macchina; monitoraggio (ed eventuale dirottamento) di tutte le periferiche di I/O; bombe logiche; cifratura con tecnica DES, morphing e PGP; accessi condizionati; rimozione di accessi condizionati, chiavi elettroniche, serial number; debugging; tracing; interfacciamento con SmartCard, inibizione di periferiche, MBR, Boot Sector, directory, file; studio e rimozione di virus (senza programma antivirus).
Recupero dati File cancellati; harddisk formattati; ricostruzione MBR, Boot sector e FAT.
Archivi Database relazionali, connessioni Microsoft Jet 4.0 OLE DB Provider, Microsoft OLE DB Provider for ODBC Drivers (Database di Microsoft Access, Database di Visual FoxPro, dBASE Files, Excel Files); ADO.
Internet Configurazione fisica TCP/IP; manipolazione del protocollo TCP/IP; tracciamento di IP; creazione di pagine web; Telnet; Email; reti intranet e motori di ricerca, Creazione pagine Web dinamiche (ASP.NET).
Grafica Produzion

Comments and Discussions

 
Generalthank you very much Pin
pepepaco18-Jun-08 14:51
pepepaco18-Jun-08 14:51 
QuestionHave you got it in C#? Pin
CAGB11-Mar-04 7:01
CAGB11-Mar-04 7:01 
Questioncool, can you post code of c#? Pin
fengfeng13-Jul-03 20:33
fengfeng13-Jul-03 20:33 
AnswerRe: cool, can you post code of c#? Pin
mrhassell24-Jan-06 11:55
mrhassell24-Jan-06 11:55 
GeneralYou've managed to capture Pin
NormDroid14-May-03 9:04
professionalNormDroid14-May-03 9:04 
GeneralRe: You've managed to capture Pin
Horatiu CRISTEA25-May-03 20:48
Horatiu CRISTEA25-May-03 20:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.