Routine Spectre des couleurs Style Windows

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
GallyHC
Messages : 1708
Inscription : lun. 17/déc./2007 12:44

Routine Spectre des couleurs Style Windows

Message par GallyHC »

Bonjour,

Voici un petit code pour avoir le spectre des couleurs dans le style à MSPaint de windows. Code sans aucune prétention encore une fois lollll.

Une petite capture :
Image

Et le code :

Code : Tout sélectionner

; +======================================================+
; |    ROUTINE DE SELECTION DE COULEUR STYLE MSPAINT.    |
; +------------------------------------------------------+
; | COPYRIGHT(C)2007-2012, ALL RIGHT RESERVED KOAKDESIGN |
; +--------------+---------------------------------------+
; | Program type | PUREBASIC 4.60                        |
; +--------------+---------------------------------------+
; | VER & REV    | 0.0.1                                 |
; +--------------+---------------------------------------+
; | Program name | main.pb                               |
; +======================================================+

; +======================================================+
; | Original Version: 0.0.1 RC0                          |
; +--------------+---------------------------------------+
; | Created by   | GallyHomeCorp                         |
; | Graphix by   | GallyHomeCorp                         |
; +--------------+---------------------------------------+
; | Comments:    |                                       |
; +--------------+                                       |
; |                                                      |
; |                                                      |
; |                                                      |
; +======================================================+

; +======================================================+
; | Système d'Exploitation                               |
; +--------------+---------------------------------------+
; | Window       | Oui                                   |
; | Linux        | Oui                                   |
; | MacOS        | Oui                                   |
; +======================================================+

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

; +--------------------------------------------------------------------------+
; |                                                                          |
; +--------------------------------------------------------------------------+
;- INITIALISATION DES DIRECTIVES COMPILEUR.

DisableASM
EnableExplicit

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

; +--------------------------------------------------------------------------+
; |                                                                          |
; +--------------------------------------------------------------------------+
;- DECLARATION DES VARIABLES (GLOBALE).

;{ - ENUMERATION
Enumeration
   #Window_main
EndEnumeration
Enumeration
   #Canvas_0
   #Canvas_1
   #Text_0
   #Text_1
   #Text_2
   #Text_3
   #Text_4
   #Text_5
   #Text_6
   #Text_7
   #String_0
   #String_1
   #String_2
   #String_3
   #String_4
   #String_5
   #String_6
EndEnumeration
;} 
;{ - CONSTANTE
 #COLOR_SPECTRUM_SIZE_MAX = 255
;}
;{ - GLOBAL
Global lCH.l = 0
Global lCS.l = 0
Global lCL.l = 127
Global lImage.l
;} 

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

; +--------------------------------------------------------------------------+
; |                                                                          |
; +--------------------------------------------------------------------------+

Procedure GetWindowBackgroundColor()
; DONNE LA COULEUR DE FOND DU SYSTEME.
  Define BackgroundColor.l

  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      BackgroundColor = GetSysColor_(#COLOR_3DFACE)
    CompilerCase #PB_OS_Linux
      BackgroundColor = RGB(237,235,236)  
    CompilerCase #PB_OS_MacOS
      BackgroundColor = RGB(237,235,236)  
  CompilerEndSelect
  ProcedureReturn BackgroundColor

EndProcedure

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

; +--------------------------------------------------------------------------+
; |                                                                          |
; +--------------------------------------------------------------------------+

Procedure RGBToHLS(lCR.l, lCG.l, lCB.l, *lCH.l, *lCL.l, *lCS.l)
; ROUTINE DE CONSERTION DU RGB EN HLS.
  Define fCH.f
  Define fCS.f
  Define fCL.f
  Define lMin.l
  Define lMax.l
  Define lDif.l
  Define lSum.l
  Define lNmR.l
  Define lNmG.l
  Define lNmB.l

  If lCR < lCG
    If lCR < lCB
      lMin = lCR
    Else
      lMin = lCB
    EndIf
  Else
    If lCG < lCB
      lMin = lCG
    Else
      lMin = lCB
    EndIf
  EndIf
  If lCR > lCG
    If lCR > lCG
      lMax = lCR
    Else
      lMax = lCB
    EndIf
  Else
    If lCG > lCB
      lMax = lCG
    Else
      lMax = lCB
    EndIf
  EndIf
  lDif = lMax - lMin
  lSum = lMax + lMin
  fCL = lSum / 510
  If lMax = lMin
    fCH = 0
    fCS = 0
  Else
    lNmR = (lMax - lCR) / lDif
    lNmG = (lMax - lCG) / lDif
    lNmB = (lMax - lCB) / lDif
    If fCL <= 0.5
      fCS = lDif / lSum
    Else
      fCS = lDif / (510 - lSum)
    EndIf
    If lCR = lMax
      fCH = 60 * (6 + lNmB - lNmG)
    EndIf
    If lCG = lMax
      fCH = 60 * (2 + lNmR - lNmB)
    EndIf
    If lCB = lMax
      fCH = 60 * (4 + lNmG - lNmR)
    EndIf
  EndIf
  If fCH = 360
   fCH = 0
  EndIf
  fCH = (fCH / 360 *  #COLOR_SPECTRUM_SIZE_MAX)
  fCL = fCL *  #COLOR_SPECTRUM_SIZE_MAX
  fCS = fCS *  #COLOR_SPECTRUM_SIZE_MAX
  PokeL(*lCH, Int(fCH))
  PokeL(*lCL, Int(fCL))
  PokeL(*lCS, Int(fCS))

EndProcedure

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

; +--------------------------------------------------------------------------+
; |                                                                          |
; +--------------------------------------------------------------------------+

Procedure.l ConvertRM(fM1.f, fM2.f, fCH.f)
; ROUTINE DE CALCUL DE LA COMPOSENTE DE COULEUR.
  If fCH > 360
    fCH - 360
  EndIf
  If fCH < 0
    fCH + 360
  EndIf

  If fCH < 60
    fM1 = fM1 + (fM2 - fM1) * fCH / 60
  Else
    If fCH < 180
      fM1 = fM2
    Else
      If fCH < 240
        fM1 = fM1 + (fM2 - fM1) * (240 - fCH) / 60
      EndIf
    EndIf
  EndIf
  ProcedureReturn fM1 * 255

EndProcedure

Procedure HLSToRGB(fCH.f, fCL.f, fCS.f, *lCR.l, *lCG.l, *lCB.l)
; ROUTINE DE CONSERTION DU HLS EN RGB.
  Define fM1.f
  Define fM2.f

  fCH = fCH * 360 /  #COLOR_SPECTRUM_SIZE_MAX
  fCL = fCL /  #COLOR_SPECTRUM_SIZE_MAX
  fCS = fCS /  #COLOR_SPECTRUM_SIZE_MAX

  If fCS = 0
    PokeL(*lCR, fCL * 255)
    PokeL(*lCG, fCL * 255)
    PokeL(*lCB, fCL * 255)
  Else
    If fCL <= 0.5
      fM2 = fCL + fCL * fCS
    Else
      fM2 = fCL + fCS - fCL * fCS
    EndIf
    fM1 = 2 * fCL - fM2
    PokeL(*lCR, ConvertRM(fM1, fM2, fCH + 120))
    PokeL(*lCG, ConvertRM(fM1, fM2, fCH))
    PokeL(*lCB, ConvertRM(fM1, fM2, fCH - 120))
  EndIf

EndProcedure

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

; +--------------------------------------------------------------------------+
; |                                                                          |
; +--------------------------------------------------------------------------+

Procedure setDrawCross(lX.l, lY.l)
; ROUTINE DE TRACAGE DE LA CROIX DU SPECTRE.
  If lX <  #COLOR_SPECTRUM_SIZE_MAX
    lX + 1
  EndIf
  If lY <  #COLOR_SPECTRUM_SIZE_MAX
    lY + 1
  EndIf
  Box(lX - 1, lY - 9, 3, 5, $000000)
  Box(lX - 1, lY + 5, 3, 5, $000000)
  Box(lX - 9, lY - 1, 5, 3, $000000)
  Box(lX + 5, lY - 1, 5, 3, $000000)

EndProcedure

Procedure setGenerateStectre()
; ROUTINE DE PRECALCUL DU SPECTRE DE COULEUR.
  Define lH.l
  Define lS.l
  Define lCR.l
  Define lCG.l
  Define lCB.l

  lImage = CreateImage(#PB_Any,  #COLOR_SPECTRUM_SIZE_MAX + 2,  #COLOR_SPECTRUM_SIZE_MAX + 2)
  If lImage <> 0
    If StartDrawing(ImageOutput(lImage))
      Box(0, 0,  #COLOR_SPECTRUM_SIZE_MAX + 2,  #COLOR_SPECTRUM_SIZE_MAX + 2, $000000)
      For lS = 1 To  #COLOR_SPECTRUM_SIZE_MAX
        For lH = 1 To  #COLOR_SPECTRUM_SIZE_MAX
          HLSToRGB(lH,  #COLOR_SPECTRUM_SIZE_MAX / 2, lS, @lCR, @lCG, @lCB)
          Plot(lH, ( #COLOR_SPECTRUM_SIZE_MAX - lS) + 1, RGB(lCR, lCG, lCB))
        Next lH
      Next lS
      StopDrawing()
    EndIf
  EndIf

EndProcedure

Procedure setDrawSpectre()
; ROUTINE D'AFFICHAGE DU SPECTRE ET CROIX.
  Define lH.l
  Define lS.l
  Define lCR.l
  Define lCG.l
  Define lCB.l

  If StartDrawing(CanvasOutput(#Canvas_0))
    If lImage <> 0
      DrawAlphaImage(ImageID(lImage), 0, 0)
    EndIf
    setDrawCross(lCH,  #COLOR_SPECTRUM_SIZE_MAX - lCS)
    HLSToRGB(lCH, lCL, lCS, @lCR, @lCG, @lCB)
    SetGadgetColor(#Text_0, #PB_Gadget_BackColor, RGB(lCR, lCG, lCB))
    StopDrawing()
  EndIf

EndProcedure

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

; +--------------------------------------------------------------------------+
; |                                                                          |
; +--------------------------------------------------------------------------+

Procedure setDrawArrow(lX.l, lY.l)
; ROUTINE DE TRACAGE DE LA BARRE DE PROGRESSION.
  Define x1.l
  Define y1.l
  Define x2.l
  Define y2.l
  Define xm.l

  If lY =<  5
    lY = 5
  EndIf
  If lY =>  #COLOR_SPECTRUM_SIZE_MAX - 5
    lY = #COLOR_SPECTRUM_SIZE_MAX - 5
  EndIf
  ;Box(lX, lY, 8, 3, $000000)
  Line(lX, lY, 5, -5, $000000)
  Line(lX, lY, 5, 5 , $000000)
  LineXY(lX + 5, lY - 5, lX + 5,  lY + 5 , $000000)
  FillArea(lX + 2, lY, 0, 0)

EndProcedure

Procedure setDrawLum()
; ROUTINE DE TRACAGE DE LA BARRE LUMIERE.
  Define i.l
  Define lCR.l
  Define lCG.l
  Define lCB.l
   
  If StartDrawing(CanvasOutput(#Canvas_1))
    Box(0, 0,  #COLOR_SPECTRUM_SIZE_MAX + 2,  #COLOR_SPECTRUM_SIZE_MAX + 2, GetWindowBackgroundColor())
    Box(0, 0, 20,  #COLOR_SPECTRUM_SIZE_MAX + 2, $000000)
    For i = 1 To  #COLOR_SPECTRUM_SIZE_MAX
      HLSToRGB(lCH, i, lCS, @lCR, @lCG, @lCB)
      LineXY(1,( #COLOR_SPECTRUM_SIZE_MAX - i) + 1, 18,( #COLOR_SPECTRUM_SIZE_MAX - i) + 1, RGB(lCR, lCG, lCB))
    Next i
    setDrawArrow(22,  #COLOR_SPECTRUM_SIZE_MAX - lCL)
    HLSToRGB(lCH, lCL, lCS, @lCR, @lCG, @lCB)
    SetGadgetColor(#Text_0, #PB_Gadget_BackColor, RGB(lCR, lCG, lCB))
    StopDrawing()
  EndIf

EndProcedure

Procedure DrawHSLText()
; ROUTINE D'AFFICHAGE DES INFOS HSL.
  SetGadgetText(#String_0, Str(lCH))
  SetGadgetText(#String_1, Str(lCS))
  SetGadgetText(#String_2, Str(lCL))

EndProcedure

Procedure DrawRGBText()
; ROUTINE D'AFFICHAGE DES INFOS RGB.
  Define lCR.l
  Define lCG.l
  Define lCB.l

  HLSToRGB(lCH, lCL, lCS, @lCR, @lCG, @lCB)
  SetGadgetText(#String_3, Str(lCR))
  SetGadgetText(#String_4, Str(lCG))
  SetGadgetText(#String_5, Str(lCB))
  SetGadgetText(#String_6, "#" + RSet(Hex(lCR), 2, "0") + RSet(Hex(lCG), 2, "0") + RSet(Hex(lCB), 2, "0"))

EndProcedure

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

; +--------------------------------------------------------------------------+
; |                                                                          |
; +--------------------------------------------------------------------------+

Define event.l
Define evenp.l
Define eveng.l
Define lMosX.l
Define lMosY.l
Define lMosP.l
Define Retour_H.l
Define Retour_S.l
Define Retour_L.l
Define Retour_R.l
Define Retour_G.l
Define Retour_B.l
Define hWnd.l = OpenWindow(#Window_main, 0, 0,  #COLOR_SPECTRUM_SIZE_MAX + 46,  #COLOR_SPECTRUM_SIZE_MAX + 110, "Spectre de couleurs", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

If hWnd <> 0
  SmartWindowRefresh(#Window_main, 1)
  CanvasGadget(#Canvas_0, 5, 5,  #COLOR_SPECTRUM_SIZE_MAX + 2,  #COLOR_SPECTRUM_SIZE_MAX + 2)
  CanvasGadget(#Canvas_1, 270, 5, 28,  #COLOR_SPECTRUM_SIZE_MAX + 2)
  TextGadget(#Text_0, 5, 270, 100, 64, "", #PB_Text_Border)
  TextGadget(#Text_1, 122, 274, 40, 20, "Teinte", #PB_Text_Right)
  TextGadget(#Text_2, 122, 295, 40, 20, "Satur", #PB_Text_Right)
  TextGadget(#Text_3, 122, 316, 40, 20, "Lum", #PB_Text_Right)
  StringGadget(#String_0, 170, 270, 33, 20, "")
  StringGadget(#String_1, 170, 291, 33, 20, "")
  StringGadget(#String_2, 170, 312, 33, 20, "")
  TextGadget(#Text_4, 210, 274, 40, 20, "Rouge", #PB_Text_Right)
  TextGadget(#Text_5, 210, 295, 40, 20, "Vert", #PB_Text_Right)
  TextGadget(#Text_6, 210, 316, 40, 20, "Bleu", #PB_Text_Right)
  StringGadget(#String_3, 258, 270, 33, 20, "")
  StringGadget(#String_4, 258, 291, 33, 20, "")
  StringGadget(#String_5, 258, 312, 33, 20, "")
  TextGadget(#Text_7, 140, 344, 80, 20, "Couleur Web", #PB_Text_Right)
  StringGadget(#String_6, 231, 340, 63, 20, "")

  setGenerateStectre()
  setDrawSpectre()
  setDrawLum()
  DrawHSLText()
  DrawRGBText()  
  Retour_H = Val(GetGadgetText(#String_0))
  Retour_S = Val(GetGadgetText(#String_1))
  Retour_L = Val(GetGadgetText(#String_2))
  Retour_R = Val(GetGadgetText(#String_3))
  Retour_G = Val(GetGadgetText(#String_4))
  Retour_B = Val(GetGadgetText(#String_5))

  Repeat
    event = WaitWindowEvent(20)
    evenp = EventType()
    eveng = EventGadget()

    If event = #PB_Event_Gadget
      Select eveng
        Case #Canvas_0
          If evenp = #PB_EventType_LeftButtonDown Or (evenp = #PB_EventType_MouseMove And GetGadgetAttribute(#Canvas_0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
            lMosX.l = GetGadgetAttribute(#Canvas_0, #PB_Canvas_MouseX)
            lMosY.l = GetGadgetAttribute(#Canvas_0, #PB_Canvas_MouseY)
            If lMosX < 0
              lMosX = 0
            Else
              If lMosX >  #COLOR_SPECTRUM_SIZE_MAX
                lMosX =  #COLOR_SPECTRUM_SIZE_MAX
              EndIf
          EndIf
          If lMosY < 0
            lMosY = 0
          Else
            If lMosY >  #COLOR_SPECTRUM_SIZE_MAX
              lMosY =  #COLOR_SPECTRUM_SIZE_MAX
            EndIf
          EndIf
          lCH = lMosX
          lCS =  #COLOR_SPECTRUM_SIZE_MAX - lMosY
          setDrawSpectre()
          setDrawLum()
          DrawHSLText()
          DrawRGBText()
          Retour_H = Val(GetGadgetText(#String_0))
          Retour_S = Val(GetGadgetText(#String_1))
          Retour_L = Val(GetGadgetText(#String_2))
          Retour_R = Val(GetGadgetText(#String_3))
          Retour_G = Val(GetGadgetText(#String_4))
          Retour_B = Val(GetGadgetText(#String_5))
        EndIf
        Case #Canvas_1
          If evenp = #PB_EventType_LeftButtonDown Or (evenp = #PB_EventType_MouseMove And GetGadgetAttribute(#Canvas_1, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
            lMosY.l = GetGadgetAttribute(#Canvas_1, #PB_Canvas_MouseY)
            If lMosY < 0
              lMosY = 0
            Else
              If lMosY >  #COLOR_SPECTRUM_SIZE_MAX
                lMosY =  #COLOR_SPECTRUM_SIZE_MAX
              EndIf
            EndIf
            lCL =  #COLOR_SPECTRUM_SIZE_MAX - lMosY
            setDrawLum()
            DrawHSLText()
            DrawRGBText()
            Retour_H = Val(GetGadgetText(#String_0))
            Retour_S = Val(GetGadgetText(#String_1))
            Retour_L = Val(GetGadgetText(#String_2))
            Retour_R = Val(GetGadgetText(#String_3))
            Retour_G = Val(GetGadgetText(#String_4))
            Retour_B = Val(GetGadgetText(#String_5))
          EndIf
        Case #String_0
          If evenp = #PB_EventType_Change
            Retour_H = Val(GetGadgetText(#String_0))
            If Retour_H < 0
              Retour_H = 0
            ElseIf Retour_H > 255
              Retour_H = 255
            EndIf
            lCH = Retour_H
            setDrawSpectre()
            setDrawLum()
            DrawRGBText()
          ElseIf evenp = #PB_EventType_LostFocus
            SetGadgetText(#String_0, Str(Retour_H))
          EndIf
        Case #String_1
          If evenp = #PB_EventType_Change
            Retour_S = Val(GetGadgetText(#String_1))
            If Retour_S < 0
              Retour_S = 0
            ElseIf Retour_S > 255
              Retour_S = 255
            EndIf
            lCS = Retour_S
            setDrawSpectre()
            setDrawLum()
            DrawRGBText()
          ElseIf evenp = #PB_EventType_LostFocus
            SetGadgetText(#String_1, Str(Retour_S))
          EndIf
        Case #String_2
          If evenp = #PB_EventType_Change
            Retour_H = Val(GetGadgetText(#String_2))
            If Retour_H < 0
              Retour_H = 0
            EndIf
            If Retour_H > 255
              Retour_H = 255
            EndIf
            lCL = Retour_H
            setDrawSpectre()
            setDrawLum()
            DrawRGBText()
          ElseIf evenp = #PB_EventType_LostFocus
            SetGadgetText(#String_2, Str(Retour_L))
          EndIf
        Case #String_3
          If evenp = #PB_EventType_Change
            Retour_R = Val(GetGadgetText(#String_3))
            If Retour_R < 0
              Retour_R = 0
            ElseIf Retour_R > 255
              Retour_R = 255
            EndIf
            RGBToHLS(Retour_R, Retour_G, Retour_B, @lCH, @lCL, @lCS)
            setDrawSpectre()
            setDrawLum()
            DrawHSLText()
          ElseIf evenp = #PB_EventType_LostFocus
            SetGadgetText(#String_3, Str(Retour_R))
          EndIf
        Case #String_4
          If evenp = #PB_EventType_Change
            Retour_G = Val(GetGadgetText(#String_4))
            If Retour_G < 0
              Retour_G = 0
            ElseIf Retour_G > 255
              Retour_G = 255
            EndIf
            RGBToHLS(Retour_R, Retour_G, Retour_B, @lCH, @lCL, @lCS)
            setDrawSpectre()
            setDrawLum()
            DrawHSLText()
          ElseIf evenp = #PB_EventType_LostFocus
            SetGadgetText(#String_4, Str(Retour_G))
          EndIf
        Case #String_5
          If evenp = #PB_EventType_Change
            Retour_B = Val(GetGadgetText(#String_5))
            If Retour_B < 0
              Retour_B = 0
            ElseIf Retour_B > 255
              Retour_B = 255
            EndIf
            RGBToHLS(Retour_R, Retour_G, Retour_B, @lCH, @lCL, @lCS)
            setDrawSpectre()
            setDrawLum()
            DrawHSLText()
          ElseIf evenp = #PB_EventType_LostFocus
            SetGadgetText(#String_5, Str(Retour_B))
          EndIf
      EndSelect
    EndIf
  Until event = #PB_Event_CloseWindow
  FreeImage(lImage)
EndIf
End
En fait ce code est toujours pour mon logiciel de contrôle DMX pour le changement des couleur RGB en live :)

Cordialement,
GallyHC
Dernière modification par GallyHC le jeu. 04/août/2016 9:33, modifié 13 fois.
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: Routine Spectre des couleurs Style Windows

Message par Kwai chang caine »

Merci 8)
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Guimauve
Messages : 1015
Inscription : mer. 11/févr./2004 0:32
Localisation : Québec, Canada

Re: Routine Spectre des couleurs Style Windows

Message par Guimauve »

Bonjour,

Ça l'air bon, il manque peut-être un petit curseur afin de retourner la couleur présente à sa position pour avoir un sélecteur de couleur.

J'aime ça.

A+
Guimauve
Avatar de l’utilisateur
GallyHC
Messages : 1708
Inscription : lun. 17/déc./2007 12:44

Re: Routine Spectre des couleurs Style Windows

Message par GallyHC »

Je suis aussi sur le petit selecteur et qu'il indique sur le spectre et sur le selectionneur le niveau :) Par contre je ne sais pas comment je vais faire pour mettre une croix pour le selection.

Cordialement,
GallyHC
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
Guimauve
Messages : 1015
Inscription : mer. 11/févr./2004 0:32
Localisation : Québec, Canada

Re: Routine Spectre des couleurs Style Windows

Message par Guimauve »

Re-Bonjour,

Il faudrait peut-être dessiner deux couches, une pour le spectre de couleur qui ne changera pas en cours de route et une autre avec uniquement le curseur et pour l'affichage final on écrase les deux couches ensembles en temps réel avec un DrawAlphaImage() pour le curseur. Et pour le curseur lui-même une simple croix (4 petits bouts de ligne) fait l'affaire.

En passant il est également possible de faire un PokeL() au lieu d'un CopyMemory()

Code : Tout sélectionner

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Nom du projet : Exemple de procédure à retour multiple
; Nom du fichier : Exemple retour multiple.pb
; Version du fichier : 1.0.0
; Programmation : OK
; Programmé par : Guimauve
; Date : 16-02-2012
; Mise à jour : 16-02-2012
; Code PureBasic : 4.60
; Plateforme : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Procedure MultipleReturn(ParamA.l, ParamB.l,ParamC.l, *ReturnA.i, *ReturnB.i)
  
  PokeL(*ReturnA, ParamA + ParamB + ParamC)
  PokeL(*ReturnB, ParamA * ParamB * ParamC)  
  
EndProcedure

MultipleReturn(25,35,45, @VarA.l, @VarB.l)

Debug "25 + 35 + 45 = " + Str(25 + 35 + 45) + " = " + Str(VarA)
Debug "25 * 35 * 45 = " + Str(25 * 35 * 45) + " = " + Str(VarB)

; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< FIN DU FICHIER <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<
A+
Guimauve
Avatar de l’utilisateur
GallyHC
Messages : 1708
Inscription : lun. 17/déc./2007 12:44

Re: Routine Spectre des couleurs Style Windows

Message par GallyHC »

Bonjour,

Et le mieu entre un PokeL() et un CopyMemory() c'est quoi en fait. J'avous ne pas savoir alors j'attend vos reponses :)

Cordialement,
GallyHC
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
Guimauve
Messages : 1015
Inscription : mer. 11/févr./2004 0:32
Localisation : Québec, Canada

Re: Routine Spectre des couleurs Style Windows

Message par Guimauve »

Au lieu de créer une variable locale à la procédure puis copier le contenu dans la variable indiqué en paramètre, on écrit directement dans la variable indiqué en paramètre.
C'est plus simple au point de vue du code et enlève les variables inutiles

Code : Tout sélectionner

Procedure ToRGB(fCH.f, fCL.f, fCS.f, *lCR.l, *lCG.l, *lCB.l) 
  ; 
  Define fM1.f 
  Define fM2.f 
  
  fCH = fCH * 360 / #Color_spectre_XY 
  fCL = fCL / #Color_spectre_XY 
  fCS = fCS / #Color_spectre_XY 
  
  If fCS = 0 
    PokeL(*lCR, fCL * 255)
    PokeL(*lCG, fCL * 255)
    PokeL(*lCB, fCL * 255)
  Else 
    If fCL <= 0.5  
      fM2 = fCL + fCL * fCS  
    Else 
      fM2 = fCL + fCS - fCL * fCS 
    EndIf 
    fM1 = 2 * fCL - fM2 
    PokeL(*lCR, ConvertRm(fM1, fM2, fCH + 120))
    PokeL(*lCG, ConvertRm(fM1, fM2, fCH))
    PokeL(*lCB, ConvertRm(fM1, fM2, fCH - 120))
  EndIf 

EndProcedure
A+
Guimauve
Avatar de l’utilisateur
GallyHC
Messages : 1708
Inscription : lun. 17/déc./2007 12:44

Re: Routine Spectre des couleurs Style Windows

Message par GallyHC »

Bonjour,

Je n'utilise pas encore deux claque mais je note bien l'idée qui est très bonne. Voila j'ai mis a jour le code (premier message du Topic) avec la 2eme barre et on peu changer la couleur dans le Spectre des couleur.

Merci Guimauve, code mis a jour aussi :).

Cordialement,
GallyHC
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
dayvid
Messages : 1242
Inscription : mer. 11/nov./2009 18:17
Localisation : Poitiers (Vienne)

Re: Routine Spectre des couleurs Style Windows

Message par dayvid »

C'est bien !

Cependant sa RAM beaucoup trop !!!

C'est pas encore au point mais c'est bien déjà

Ce qui serais superbe se serais de faire un truc similaire a paint !

En plus cella me serais utile a moi !

En plus ça me permettrait de voir comment on calcule les divers
trucs pour savoir:

La teinte d'une couleur
La luminosité d'une couleur
La saturation d'une couleur

en faite ce que j'aurais besoin, c'est trois fonction que je ne sais pas faire, exemple:

GetTeintureColor(Color.l)
GetBrightnessColor(Color.l)
GetSaturationColor(Color.l)

Et plus si infinité ! :)
La vie, C'est comme, Une boitte, De startis, On en voie, De toutes, Les couleurs !

Mon forum http://purebasic.forumphp3.com/index.php
Avatar de l’utilisateur
GallyHC
Messages : 1708
Inscription : lun. 17/déc./2007 12:44

Re: Routine Spectre des couleurs Style Windows

Message par GallyHC »

Il est normal que cela rame, je suis sur le fait de comprendre et d'appliquer apres je vais optimiser. Pour les divers infos je vais les ajouter.

J'ai mis a jour le code avec le niveau aussi, vais bientot pouvoir essayer d'optimiser :)

Cordialement,
GallyHC
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
Avatar de l’utilisateur
GallyHC
Messages : 1708
Inscription : lun. 17/déc./2007 12:44

Re: Routine Spectre des couleurs Style Windows

Message par GallyHC »

Code mis a jour est plus rapide :)
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
Avatar de l’utilisateur
GallyHC
Messages : 1708
Inscription : lun. 17/déc./2007 12:44

Re: Routine Spectre des couleurs Style Windows

Message par GallyHC »

Mise à jour de la capture et du code.

J'ai test ce code aussi en y ajoutant la partie pour le controleur de type Velleman et un Par Led et cela fonctionne nikel en ce qui me concerne.

Cordialement,
GallyHC
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
dayvid
Messages : 1242
Inscription : mer. 11/nov./2009 18:17
Localisation : Poitiers (Vienne)

Re: Routine Spectre des couleurs Style Windows

Message par dayvid »

Excelent :o

Trop bien GallyHC :D

GallyHC est un dieu, love GallyHC

Merci beaucoup GallyHC :D

Edit:

Heu...

Dit moi GallyHC, t'es sur que t'as pas tirer un peut sur la bouteille là ? :?
Non j'dit ça moi mais j'dit rien hein :lol:

Pourquoi les deux résulta sons t-il différent ? :|
Ya une erreur queque par là 8O

Autre chose si tu veut bien:
Il serais bien que quand tu change une valeur que la couleur soit mis a jour, enfin tous quoi ! :wink:

Et aussi si ça te dérange pas:
Remplace le trais par une flèche noir comme dans paint ou une flèche plus sympatoche ! :wink:

Voilà ! bon courrage :)
Dernière modification par dayvid le jeu. 16/févr./2012 21:35, modifié 1 fois.
La vie, C'est comme, Une boitte, De startis, On en voie, De toutes, Les couleurs !

Mon forum http://purebasic.forumphp3.com/index.php
Avatar de l’utilisateur
GallyHC
Messages : 1708
Inscription : lun. 17/déc./2007 12:44

Re: Routine Spectre des couleurs Style Windows

Message par GallyHC »

Encore une petite Maj
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
dayvid
Messages : 1242
Inscription : mer. 11/nov./2009 18:17
Localisation : Poitiers (Vienne)

Re: Routine Spectre des couleurs Style Windows

Message par dayvid »

Bien, Tu met a jour si ont change une valeur !
Mais ya soucis quand même car tu voie
il faut que le programme prenne en compte ce qu'ont met et que le cursseur se mette a la fin et nom au debut :)
La vie, C'est comme, Une boitte, De startis, On en voie, De toutes, Les couleurs !

Mon forum http://purebasic.forumphp3.com/index.php
Répondre