REBOL

 

RGB-TO-HTML - Source Code

REBOL COLOR PICKER
Author: Rebolien
File size: 11K
Return to index

 

REBOL [ auteur: "BOUMEDIENNE Antar"
    title: "RGB color v1.3"
    version: "1.3"
    commentaire: {"correction du bug de la fonction Fonction-HEXA"}
]
j: 0
menu1: ["Fichier" "Quitter          (Echap)"]
menu2: ["Option" "Couleurs REBOL " ]
menu3: ["?" "A propos" "Raccourcis (CTRL+R)" ]
stylize/master: [
but-n: button 21x21 edge [size: 0x0]
btP: button 20x25 edge [size: 2x6 type: 'zbevel color: 72.0.90] "+" crimson
btM: button 20x25 edge [size: 2x6 type: 'zbevel color: 72.0.90] "-" crimson
btn0: btn 40x21
lab: label center coffee 250x30 font-size 15 shadow 0x0
tLabel: label 45x25 
gLabel: label 75x25 middle 
gfield: field 100x50 center edge [size: 0x0]
esp0: label 10x10
esp: label 10x25
esp2: label 25x25
fond: backdrop effect [gradient 0x1 164.200.255 180.180.250]
]
fonction-HEXA: func [
    Rouge [string!] "Valeur de la teinte ROUGE (de 0 à 255)"
    Vert [string!] "Valeur de la teinte ROUGE (de 0 à 255)"
    Bleu [string!] "Valeur de la teinte ROUGE (de 0 à 255)"
    ]
    [
    R: to-hex to-integer Rouge  
    G: to-hex to-integer Vert
    B: to-hex to-integer Bleu
    r: to-string parse to-string r "#"
    g: to-string parse to-string g "#"
    b: to-string parse to-string b "#"
    r1: to-string pick r 7
    r2: to-string pick r 8
    g1: to-string pick g 7
    g2: to-string pick g 8
    b1: to-string pick b 7
    b2: to-string pick b 8
    clear r
    clear g
    clear b
    r: to-string reduce [r1 r2]
    g: to-string reduce [g1 g2]
    b: to-string reduce [b1 b2]
    liste-Hexa: []
    clear liste-hexa
    liste-Hexa: reduce ["#" r g b]
    liste-hexa: to-string liste-hexa
    return liste-hexa
    unset 'r
    unset 'r1
    unset 'r2
    unset 'g
    unset 'g1
    unset 'g2
    unset 'b
    unset 'b1
    unset 'b2
]
fonction-RGB: func ["Fonction qui renvoie un tuple RGB (string!)" 
    Rouge [string!] "Valeur de la teinte ROUGE (de 0 à 255)"
    Vert [string!] "Valeur de la teinte VERTE (de 0 à 255)"
    Bleu [string!] "Valeur de la teinte BLEUE (de 0 à 255)"
    ]
    [
    tuple-RGB: []
    clear tuple-RGB
    insert tuple-RGB reduce [Rouge "." Vert "." Bleu]
    tuple-RGB: to-string tuple-RGB
    return tuple-RGB
]
parse-RGB: func [
        couleur [string!]
        ]
        [
        liste-RGB: copy []
        clear liste-RGB
        liste-RGB: parse couleur "."
        return liste-RGB
]
proc-clear: does [ChoixRouge/text: "255" ChoixVert/text: "255" ChoixBleu/text: "255" show ChoixVert show ChoixBleu show ChoixRouge]
proc-Afficher: does [
            if/else any [((to-integer ChoixBleu/text) > 255) ((to-integer ChoixBleu/text) < 0)
                        ((to-integer ChoixVert/text) > 255) ((to-integer ChoixVert/text) < 0)
                        ((to-integer ChoixRouge/text) > 255) ((to-integer ChoixRouge/text) < 0)
                        ] [ 
                        proc-clear
                        alert "Le chiffre doit être compris entre 0 et 255: RECOMMENCEZ"][ 
                        ch-reb/text: fonction-RGB ChoixRouge/text ChoixVert/text ChoixBleu/text
                        ch-hex/text: fonction-HEXA ChoixRouge/text ChoixVert/text ChoixBleu/text
                        ch-PerlTK/text: mold (fonction-HEXA ChoixRouge/text ChoixVert/text ChoixBleu/text)
                        boite/color: to-tuple (fonction-RGB ChoixRouge/text ChoixVert/text ChoixBleu/text)
                        show ch-reb
                        show ch-hex
                        show ch-PerlTK
                        show boite
]
]
liste-tuples: [["aqua" 40.100.130]["bar-color" 180.180.250]["base-color" 143.127.111]["beige" 255.228.196]["black" 0.0.0]["blue" 0.0.255]["brick" 178.34.34]["brown" 139.69.19]["button-color" 44.80.132]["coal" 64.64.64]["coffee" 76.26.0]["crimson" 220.20.60]["cyan" 0.255.255]["forest" 0.48.0]["gold" 255.205.40]["gray" 128.128.128]["green" 0.255.0]["ivory" 255.255.240]["khaki" 179.179.126]["leaf" 0.128.0]["linen" 250.240.230]["magenta" 255.0.255]["main-color" 175.155.120]["maroon" 128.0.0]["mint" 100.136.116]["navy" 0.0.128]["oldrab" 72.72.16]["olive" 128.128.0]["orange" 255.150.10]["over-color" 44.80.132]["papaya" 255.80.37]["pewter" 170.170.170]["pink" 255.164.200]["purple" 128.0.128]["reblue" 38.58.108]["rebolor" 142.128.110]["red" 255.0.0]["sienna" 160.82.45]["silver" 192.192.192]["sky" 164.200.255]["snow" 240.240.240]["tan" 222.184.135]["teal" 0.128.128]["violet" 72.0.90]["water" 80.108.142]["wheat" 245.222.129]["white" 255.255.255]["yellow" 255.255.0]]

fen-col: [backdrop effect [gradient 0x1 164.200.255 180.180.250] space 0x0 across origin 0x0  esp0 return]
foreach element liste-tuples [
        j: j + 1 
        if/else ((type? j / 4) = integer!) [
                    insert tail fen-col reduce compose/deep [
                            'label 80x25 (uppercase/part element/1 1) 'right 'shadow none (black) 'bold 'bold 'bold
                            'btn 25x25 (element/2) [boite2/color: (element/2) show boite2 Champ/text: (element/2) show Champ nom-Coul/text: (element/1) show nom-Coul]
                            'esp0
                            'return
                            
                            ]
                        ][
                        insert tail fen-col reduce compose/deep [
                                'label 80x25 (uppercase/part element/1 1) 'right 'shadow none (black) 'bold 'bold 'bold
                                'btn 25x25 (element/2) [boite2/color: (element/2) show boite2 Champ/text: (element/2) show Champ nom-Coul/text: (element/1) show nom-Coul]
                                ]
                        ]
]
insert tail fen-col reduce compose/deep [
    'return
    'label 'right 'middle 80x30 "NOM" 'underline
    'esp0
    'label 'center 'middle 80x30 "APPERCU" 'underline
    'esp0
    'label 'center 'middle 80x30 "VALEUR RGB" 'underline
    'return
    to-set-word "nom-Coul" 'label 'right 'middle 80x30 "White" navy 
    'esp0
    to-set-word "boite2" 'box 80x30 white 'edge [ color: 220.20.60 effect: 'ibezel size: 4x2 ]
    'esp0
    to-set-word "Champ" 'info 80x30 "255.255.255" 255.205.40 'center 'middle 'bold 'bold 'bold 'edge [color: 255.80.37  effect: 'bevel size: 6x3]
    'esp0
    'btn 70x30 "Selection" "SELECTION" bar-color * 2  #"^M" [selection: to-string Champ/text unview fen-col
                            ChoixRouge/text: pick parse-RGB selection 1
                            ChoixVert/text: pick parse-RGB selection 2
                            ChoixBleu/text: pick parse-RGB selection 3
                            show ChoixRouge
                            show ChoixVert
                            show ChoixBleu
                            proc-Afficher
                            ]
    'esp0
    'btn 60x30 "Retour" "RETOUR" brick * 2 'keycode [#"^[" #"q" #"Q"] [unview fen-col] 
    'return
    'esp0
]   
fen-col: center-face layout fen-col
fen-purpose: center-face layout [
size 160x125
backdrop effect [gradient 0x1 164.200.255 180.180.250]
space 0x0
across
origin 0x0
code 160x20 "NOM: RGB-color" center middle 
return
code 160x20 "VERSION: 1.3" center middle 
return
code 160x20 "AUTEUR: Antar B." center middle
return
vtext 160x20 "LIEN: Site de REBOL" center middle navy underline
return
vtext 160x20 "www.rebolfrance.net" center middle crimson [browse http://www.rebolfrance.net]
return
label 60x20 btn keycode [#"^[" #"o" #"O"] crimson teal "OK" 40x22 font-color 255.255.255 [unview fen-purpose]
]
fen-raccourcis:  center-face layout [
    size 200x150
    fond 
    across 
    space 0x0
    origin 0x0
    label 200x25 crimson "RACCOURCIS :" center underline
    return
    label 200x20 navy "-Echap- : pour quitter" left
    return
    label 200x20 navy "-Entree- : pour afficher les valeurs" left
    return
    label 200x10 navy "------------------------------------" center
    return
    esp0
    return
    label 200x44 BLACK Gold CENTER "CLIQUER SUR LA FLÊCHE POUR ENVOYER LA VALEUR DANS LE PRESSE-PAPIERS"
    key keycode [#"q" #"Q" #"^["][unview fen-raccourcis]
]   
fen-quit: center-face layout [
    fond
    across 
    space 0x0
    origin 0x0
    label 5x5
    return  
    lab "ÊTES VOUS SÛR DE"
    return
    lab "VOULOIR QUITTER ?"
    return
    label 5x5
    return
    label 100x20
    btn0 reblue over-color keycode [#"o" #"O" #"q" #"Q"] "Oui" "OK" font [colors: [250.240.230 255.205.40]] [quit] 
    label 20x20
    btn0 brick crimson keycode [#"n" #"N" #"^[" ] "Non" "OK" font [colors: [250.240.230 255.205.40]] [unview fen-quit]
    return
    label 5x5
]
menu-fichiers: does [
    option: parse CFichier/text none 
    switch first option [
    "Quitter" [view/new fen-quit]
    ]
    ; premier item du menu
    CFichier/text: pick CFichier/texts 1
    show CFichier
    ]
    
menu-options: does [
    option: parse COption/text none 
    switch first option [
    "Couleurs" [view/new fen-col]
            ]
    ; premier item du menu
    COption/text: pick COption/texts 1
    show COption
    ]
menu-aides: does [
    option: parse CAide/text none 
    switch first option [
    "A" [view/new fen-purpose]
    "Raccourcis" [view/new fen-raccourcis]
    ]
    ; premier item du menu
    CAide/text: pick CAide/texts 1
    show CAide
    ]
toile: layout [
size 390x280
fond
across 
space 0x0
origin 0x0
style stylmenu1 choice  130 left 250.240.230 font [size: 11 shadow: none colors: [0.0.0 220.20.60]] effect [gradient 0x1 250.240.230 ] edge [color: 0.0.128 size: 0x1]
CFichier: stylmenu1 data menu1 [menu-fichiers]
COption: stylmenu1 data menu2 [menu-options]
CAide: stylmenu1 data menu3 [menu-aides]
return
esp2
return
    esp2
    tLabel Red "Rouge:" right
    esp
    btM [
    Re1: to-integer ChoixRouge/text
    if/else (Re1 = 0) [ChoixRouge/text: "255" show ChoixRouge][Red: subtract Re1 1 ChoixRouge/text: to-string Red show ChoixRouge]
    proc-Afficher
        ] 
    esp
    ChoixRouge: field 50x25 "255" center
    esp
    btP [
    Re1: to-integer ChoixRouge/text
    if/else (Re1 = 255) [ChoixRouge/Text: "0" show ChoixRouge][Red: add Re1 1 ChoixRouge/text: to-string Red show ChoixRouge]
    proc-Afficher
    ] 
return
esp0
return
    esp2
    tLabel Green "Vert:" right
    esp
    btM [
    Re1: to-integer ChoixVert/text
    if/else (Re1 = 0)[ChoixVert/text: "255" show ChoixVert][Red: subtract Re1 1 ChoixVert/text: to-string Red show ChoixVert]
    proc-Afficher
        ]
    esp
    ChoixVert: field 50x25  "255" center
    esp 
    btP [
    Re1: to-integer ChoixVert/text
    if/else (Re1 = 255) [ChoixVert/Text: "0" show ChoixVert][Red: add Re1 1 ChoixVert/text: to-string Red show ChoixVert]
    proc-Afficher
        ] 
return
esp0
return
    esp2
    tLabel Blue "Bleu:" right
    esp
    btM [
    Re1: to-integer ChoixBleu/text
    if/else (Re1 = 0) [ChoixBleu/Text: "255" show ChoixBleu][Red: subtract Re1 1 ChoixBleu/text: to-string Red show ChoixBleu]
    proc-Afficher
        ]
    esp
    ChoixBleu: field 50x25 "255" center
    esp
    btP [
    Re1: to-integer ChoixBleu/text
    if/else (Re1 = 255) [ChoixBleu/Text: "0" show ChoixBleu][Red: add Re1 1 ChoixBleu/text: to-string Red show ChoixBleu]
    proc-Afficher
        ] 
return
esp2
return
glabel "REBOL: " papaya right underline ch-REB: glabel coffee "255.255.255" center edge [size: 0x0]
esp
arrow 25x25 right ivory [write clipboard:// ch-reb/text]
return
esp0
return 
glabel "HTML: " papaya right underline ch-HEX: glabel coffee "#FFFFFF" center edge [size: 0x0]
esp
arrow 25x25 right ivory [write clipboard:// ch-HEX/text]
label 80x25
btn papaya beige 80x25 "Afficher" "AFFICHER" #"^M" [proc-Afficher] font [colors: [0.0.0 0.255.255]]
return
esp0
return 
glabel "PERL/TK" papaya right underline ch-PerlTK: glabel coffee {"#FFFFFF"} center edge [size: 0x0]
esp
arrow 25x25 right ivory [write clipboard:// ch-PerlTK/text]
label 80x25
btn Beige papaya 80x25 "Clear" "CLEAR" keycode [f5 " "] [proc-clear proc-Afficher]
at 225x30 label NAVY 150x25 center bottom "APPERCU" underline
at 225x60 boite: box white 150x130 edge [color: 220.20.60 effect: 'ibezel size: 6x3 ]
key keycode [#"q" #"Q" #"^["][view/new fen-quit]
key keycode [#"^R" #"R" #"r"][view/new fen-raccourcis]
do [CFichier/colors: COption/colors: CAide/colors: [250.240.230 220.20.60]]
]
view center-face toile