Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Color Display Applet

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Manuel Valdes
    replied
    Small improvement; the color is shown as background of the focused item in the scrolling menu.

    Code:
     
    #COMPILE EXE
    #CONSOLE OFF  'Comment to compile with PBWin9
    DEFLNG a-z
    GLOBAL CLR$(),O$,HC$
    GLOBAL CarH,CarW,xm,ym AS DOUBLE
    GLOBAL hwin,hven,hvin,I,flg,IE,IP,P,KA,TC(),RC,GC,BC,FG,clk AS LONG
    FUNCTION PBMAIN () AS LONG
     LOCAL WAV AS DOUBLE
     hvin=1
     caption$="Color Display"
     GRAPHIC WINDOW caption$,0,0,433,183 TO hwin
     GRAPHIC ATTACH hwin,0,REDRAW
     GRAPHIC CLEAR %WHITE
     GRAPHIC SET LOC 100,100
     FONT NEW "Courier New",10,0,0,0,0 TO fnt1
     GRAPHIC SET FONT fnt1
     GRAPHIC CHR SIZE TO CarW,CarH
     REDIM CLR$(140)
     REDIM TC&(140)
     KA=0
     FOR I=1 TO 279 STEP 2
      INCR KA
      CLR(KA)= READ$(I)
      TC(KA)= VAL(READ$(I+1))
     NEXT
     GRAPHIC BOX(182,3)-(198,180),,%GRAY,-2
     GRAPHIC LINE(182,19)-(198,19),%GRAY
     GRAPHIC LINE(182,163)-(198,163),%GRAY
     GRAPHIC COLOR %RED
     GRAPHIC LINE(186,13)-(190,7)
     GRAPHIC LINE(193,13)-(190,7)
     GRAPHIC LINE(186,168)-(190,174)
     GRAPHIC LINE(193,168)-(190,174)
     DO
      CALL THISONE
      IF hvin=0 THEN EXIT LOOP
      GRAPHIC BOX(201,3)-(430,180),,%WHITE,TC(IE+IP),-1
       GRAPHIC COLOR FG,TC(IE+IP)
      GRAPHIC SET POS(215,35)
      GRAPHIC PRINT "%RGB_"+CLR$(IE+IP)
      CLIPBOARD RESET,E&
      GRAPHIC SET POS(215,65)
      GRAPHIC PRINT "DEC: "+USING$("######",TC(IE+IP))
      GRAPHIC SET POS(215,95)
      GRAPHIC PRINT "HEX: &H"+HC$
      GRAPHIC SET POS(215,125)
      GRAPHIC PRINT "RGB("+USING$("###",RC)+CHR$(44)+USING$("###",GC)+CHR$(44)+USING$("###",BC)+")"
      GRAPHIC REDRAW
      'CLIPBOARD SET TEXT "%RGB_"+CLR$(IE+IP),E&
      'CLIPBOARD SET TEXT USING$("######",TC(IE+IP)),E&
      CLIPBOARD SET TEXT "&H"+HC$,E&
      'CLIPBOARD SET TEXT "RGB("+USING$("###",RC)+CHR$(44)+USING$("###",GC)+CHR$(44)+USING$("###",BC)+")",E&
      IF O$=CHR$(27) THEN EXIT LOOP
     LOOP
     GRAPHIC WINDOW END
     DATA INDIANRED,6053069,LIGHTCORAL,8421616,SALMON,7504122,DARKSALMON,8034025,LIGHTSALMON ,8036607,CRIMSON,3937500,RED,255,FIREBRICK,2237106,DARKRED,139,PINK,13353215
     DATA LIGHTPINK,12695295,HOTPINK,11823615,DEEPPINK,9639167,MEDIUMVIOLETRED,8721863,PALEVIOLETRED,9662683,LIGHTSALMON,8036607,CORAL,5275647,TOMATO,4678655,ORANGERED,17919,DARKORANGE,36095
     DATA ORANGE,42495,GOLD,55295,YELLOW,65535,LIGHTYELLOW,14745599,LEMONCHIFFON,13499135,LIGHTGOLDENRODYELLOW,13826810,PAPAYAWHIP,14020607,MOCCASIN,11920639,PEACHPUFF,12180223,PALEGOLDENROD,11200750
     DATA KHAKI,9234160,DARKKHAKI,7059389,LAVENDER,16443110,THISTLE,14204888,PLUM,14524637,VIOLET,15631086,ORCHID,14053594,MAGENTA,16711935,MEDIUMORCHID,13850042,MEDIUMPURPLE,14381203
     DATA BLUEVIOLET,14822282,DARKVIOLET,13828244,DARKORCHID,13382297,DARKMAGENTA,9109643,PURPLE,8388736,INDIGO,8519755,SLATEBLUE,13458026,DARKSLATEBLUE,9125192,MEDIUMSLATEBLUE,15624315,GREENYELLOW,3145645
     DATA CHARTREUSE,65407,LAWNGREEN,64636,LIME,65280,LIMEGREEN,3329330,PALEGREEN,10025880,LIGHTGREEN,9498256,MEDIUMSPRINGGREEN,10156544,SPRINGGREEN,8388352,MEDIUMSEAGREEN,7451452,SEAGREEN,5737262
     DATA FORESTGREEN,2263842,GREEN,32768,DARKGREEN,25600,YELLOWGREEN,3329434,OLIVEDRAB,2330219,OLIVE,32896,DARKOLIVEGREEN,3107669,MEDIUMAQUAMARINE,11193702,DARKSEAGREEN,9419919,LIGHTSEAGREEN,11186720
     DATA DARKCYAN,9145088,TEAL,8421376,CYAN,16776960,LIGHTCYAN,16777184,PALETURQUOISE,15658671,AQUAMARINE,13959039,TURQUOISE,13688896,MEDIUMTURQUOISE,13422920,DARKTURQUOISE,13749760,CADETBLUE,10526303
     DATA STEELBLUE,11829830,LIGHTSTEELBLUE,14599344,POWDERBLUE,15130800,LIGHTBLUE,15128749,SKYBLUE,15453831,LIGHTSKYBLUE,16436871,DEEPSKYBLUE,16760576,DODGERBLUE,16748574,CORNFLOWERBLUE,15570276,MEDIUMSLATEBLUE,15624315
     DATA ROYALBLUE,14772545,BLUE,16711680,MEDIUMBLUE,13434880,DARKBLUE,9109504,NAVY,8388608,MIDNIGHTBLUE,7346457,CORNSILK,14481663,BLANCHEDALMOND,13495295,BISQUE,12903679,NAVAJOWHITE,11394815
     DATA WHEAT,11788021,BURLYWOOD,8894686,TAN,9221330,ROSYBROWN,9408444,SANDYBROWN,6333684,GOLDENROD,2139610,DARKGOLDENROD,755384,PERU,4163021,CHOCOLATE,1993170,SADDLEBROWN,1262987
     DATA SIENNA,2970272,BROWN,2763429,MAROON,128,WHITE,16777215,SNOW,16448255,HONEYDEW,15794160,MINTCREAM,16449525,AZURE,16777200,ALICEBLUE,16775408,GHOSTWHITE,16775416
     DATA WHITESMOKE,16119285,SEASHELL,15660543,BEIGE,14480885,OLDLACE,15136253,FLORALWHITE,15792895,IVORY,15794175,ANTIQUEWHITE,14150650,LINEN,15134970,LAVENDERBLUSH,16118015,MISTYROSE,14804223
     DATA GAINSBORO,14474460,LIGHTGRAY,13882323,SILVER,12632256,DARKGRAY,11119017,GRAY,8421504,DIMGRAY,6908265,LIGHTSLATEGRAY,10061943,SLATEGRAY,9470064,DARKSLATEGRAY,5197615,BLACK,0
    END FUNCTION
    SUB THISONE
     IF IE=0 THEN IE=1
     O$=""
     DO
      GRAPHIC GET DC TO hvin
      IF hvin = 0  THEN EXIT LOOP
      FOR B=0 TO 10
       IF B=IP THEN
        HC$=RIGHT$(STRING$(6,48)+HEX$(TC(IE+IP)),6)
        BC=16*VAL("&H"+MID$(HC$,1,1))+VAL("&H"+MID$(HC$,2,1))
        GC=16*VAL("&H"+MID$(HC$,3,1))+VAL("&H"+MID$(HC$,4,1))
        RC=16*VAL("&H"+MID$(HC$,5,1))+VAL("&H"+MID$(HC$,6,1))
        WAV=(BC+2*GC+RC)/4
        IF WAV<156 THEN
         FG=&HFFFFE0
        ELSE
         FG=%BLACK
        END IF
        GRAPHIC COLOR FG&,TC(IE+B)
       ELSE
        GRAPHIC COLOR %BLACK,%WHITE
       END IF
       GRAPHIC SET POS(3,3+CarH*B)
       GRAPHIC PRINT LEFT$(CHR$(32)+CLR$(B+IE)+STRING$(22,32),22)
      NEXT B
      GRAPHIC BOX(183,20)-(197,163),,%WHITE,-1
      GRAPHIC BOX(183,20)-(197,20+143*((IE+IP)/KA)),,RGB(110,120,180),-1
      GRAPHIC REDRAW
      GRAPHIC WINDOW CLICK TO clk,xm,ym
      GRAPHIC INKEY$ TO O$
      IF clk THEN
       IF (xm>182 AND xm<198) AND (ym>20 AND ym<162) THEN
        IE=(KA-IP)*((ym-20)/142)
       ELSEIF (xm>182 AND xm<198) AND (ym>3 AND ym<20)THEN
        O$=CHR$(0,72)
       ELSEIF (xm>182 AND xm<198) AND (ym<180 AND ym>162)THEN
        O$=CHR$(0,80)
       ELSEIF (xm>3 AND xm<182) AND (ym<180 AND ym>3) THEN
        IP=(ym-3)\CarH
        IF clk=2 THEN O$=CHR$(13)
       END IF
      END IF
      SELECT CASE O$
       CASE CHR$(27)
        EXIT LOOP
       CASE CHR$(0,80)
        IF IP<10 THEN
         INCR IP
        ELSE
         IF IE<KA-10 THEN INCR IE
        END IF
       CASE CHR$(0,72)
        IF IP>0 THEN
         DECR IP
        ELSE
         IF IE>1 THEN DECR IE
        END IF
       CASE CHR$(0,73)
        IE=IE-10
        IP=0
       CASE CHR$(0,81)
        IE=IE+10
        IP=10
       CASE CHR$(0,79)
        IE=KA-10
        IP=10
       CASE CHR$(0,71)
        IE=1
        IP=0
       CASE CHR$(13)
        ARC$=CLR$(IE+IP)
        EXIT LOOP
      END SELECT
      IF IE>KA-10 THEN IE=KA-10
      IF IE<1 THEN IE=1
     LOOP
     GRAPHIC REDRAW
    END SUB
    Last edited by Manuel Valdes; 20 Jul 2009, 08:31 AM.

    Leave a comment:


  • Manuel Valdes
    started a topic PBWin/PBCC Color Display Applet

    Color Display Applet

    The code below compiles as a small Color Display Applet (36.5K). It can be compiled either with PBCC5 or PBWIN9, and can be controlled with the mouse or the keyboard. The code of the chosen color is put in the clipboard to be pasted in your program or text, in the format of your choice, Predefined Equates, Decimal, Hex or RGB, by commenting and un-commenting the proper lines.

    Code:
    [FONT=Courier New][/FONT]
    [FONT=Courier New][/FONT] 
    [FONT=Courier New]#COMPILE EXE
    #CONSOLE OFF  'Comment to compile with PBWin9
    DEFLNG a-z[/FONT]
    [FONT=Courier New]GLOBAL CLR$(),O$
    GLOBAL CarH,CarW,xm,ym AS DOUBLE
    GLOBAL hwin,hven,hvin,I,flg,IE,IP,P,KA,ATC(),clk AS LONG[/FONT]
    [FONT=Courier New]FUNCTION PBMAIN () AS LONG
     LOCAL WAV AS DOUBLE
     hvin=1
     caption$="Color Display"
     GRAPHIC WINDOW caption$,0,0,433,183 TO hwin
     GRAPHIC ATTACH hwin,0,REDRAW
     GRAPHIC CLEAR %WHITE
     GRAPHIC SET LOC 100,100
     FONT NEW "Courier New",10,0,0,0,0 TO fnt1
     GRAPHIC SET FONT fnt1
     GRAPHIC CHR SIZE TO CarW,CarH
     REDIM CLR$(140)
     REDIM TC&(140)
     KA=0
     FOR I=1 TO 279 STEP 2
      INCR KA
      CLR(KA)= READ$(I)
      TC(KA)= VAL(READ$(I+1))
     NEXT
     GRAPHIC BOX(182,3)-(198,180),,%GRAY,-2
     GRAPHIC LINE(182,19)-(198,19),%GRAY
     GRAPHIC LINE(182,163)-(198,163),%GRAY
     GRAPHIC COLOR %RED
     GRAPHIC LINE(186,13)-(190,7)
     GRAPHIC LINE(193,13)-(190,7)
     GRAPHIC LINE(186,168)-(190,174)
     GRAPHIC LINE(193,168)-(190,174)
     DO
      CALL THISONE
      IF hvin=0 THEN EXIT LOOP
      GRAPHIC BOX(201,3)-(430,180),,%WHITE,TC(IE+IP),-1
      HC$=RIGHT$(STRING$(6,48)+HEX$(TC(IE+IP)),6)
      BC=16*VAL("&H"+MID$(HC$,1,1))+VAL("&H"+MID$(HC$,2,1))
      GC=16*VAL("&H"+MID$(HC$,3,1))+VAL("&H"+MID$(HC$,4,1))
      RC=16*VAL("&H"+MID$(HC$,5,1))+VAL("&H"+MID$(HC$,6,1))
      WAV=(BC+2*GC+RC)/4
      IF WAV<156 THEN
       GRAPHIC COLOR %WHITE,TC(IE+IP)
      ELSE
       GRAPHIC COLOR %BLACK,TC(IE+IP)
      END IF
      GRAPHIC SET POS(215,35)
      GRAPHIC PRINT "%RGB_"+CLR$(IE+IP)
      CLIPBOARD RESET,E&
      GRAPHIC SET POS(215,65)
      GRAPHIC PRINT "DEC: "+USING$("######",TC(IE+IP))
      GRAPHIC SET POS(215,95)
      GRAPHIC PRINT "HEX: &H"+HC$
      GRAPHIC SET POS(215,125)
      GRAPHIC PRINT "RGB("+USING$("###",RC)+CHR$(44)+USING$("###",GC)+CHR$(44)+USING$("###",BC)+")"
      GRAPHIC REDRAW
      'CLIPBOARD SET TEXT "%RGB_"+CLR$(IE+IP),E&
      'CLIPBOARD SET TEXT USING$("######",TC(IE+IP)),E&
      CLIPBOARD SET TEXT "&H"+HC$,E&
      'CLIPBOARD SET TEXT "RGB("+USING$("###",RC)+CHR$(44)+USING$("###",GC)+CHR$(44)+USING$("###",BC)+")",E&
      IF O$=CHR$(27) THEN EXIT LOOP
     LOOP
     GRAPHIC WINDOW END
     DATA INDIANRED,6053069,LIGHTCORAL,8421616,SALMON,7504122,DARKSALMON,8034025,LIGHTSALMON ,8036607,CRIMSON,3937500,RED,255,FIREBRICK,2237106,DARKRED,139,PINK,13353215
     DATA LIGHTPINK,12695295,HOTPINK,11823615,DEEPPINK,9639167,MEDIUMVIOLETRED,8721863,PALEVIOLETRED,9662683,LIGHTSALMON,8036607,CORAL,5275647,TOMATO,4678655,ORANGERED,17919,DARKORANGE,36095
     DATA ORANGE,42495,GOLD,55295,YELLOW,65535,LIGHTYELLOW,14745599,LEMONCHIFFON,13499135,LIGHTGOLDENRODYELLOW,13826810,PAPAYAWHIP,14020607,MOCCASIN,11920639,PEACHPUFF,12180223,PALEGOLDENROD,11200750
     DATA KHAKI,9234160,DARKKHAKI,7059389,LAVENDER,16443110,THISTLE,14204888,PLUM,14524637,VIOLET,15631086,ORCHID,14053594,MAGENTA,16711935,MEDIUMORCHID,13850042,MEDIUMPURPLE,14381203
     DATA BLUEVIOLET,14822282,DARKVIOLET,13828244,DARKORCHID,13382297,DARKMAGENTA,9109643,PURPLE,8388736,INDIGO,8519755,SLATEBLUE,13458026,DARKSLATEBLUE,9125192,MEDIUMSLATEBLUE,15624315,GREENYELLOW,3145645
     DATA CHARTREUSE,65407,LAWNGREEN,64636,LIME,65280,LIMEGREEN,3329330,PALEGREEN,10025880,LIGHTGREEN,9498256,MEDIUMSPRINGGREEN,10156544,SPRINGGREEN,8388352,MEDIUMSEAGREEN,7451452,SEAGREEN,5737262
     DATA FORESTGREEN,2263842,GREEN,32768,DARKGREEN,25600,YELLOWGREEN,3329434,OLIVEDRAB,2330219,OLIVE,32896,DARKOLIVEGREEN,3107669,MEDIUMAQUAMARINE,11193702,DARKSEAGREEN,9419919,LIGHTSEAGREEN,11186720
     DATA DARKCYAN,9145088,TEAL,8421376,CYAN,16776960,LIGHTCYAN,16777184,PALETURQUOISE,15658671,AQUAMARINE,13959039,TURQUOISE,13688896,MEDIUMTURQUOISE,13422920,DARKTURQUOISE,13749760,CADETBLUE,10526303
     DATA STEELBLUE,11829830,LIGHTSTEELBLUE,14599344,POWDERBLUE,15130800,LIGHTBLUE,15128749,SKYBLUE,15453831,LIGHTSKYBLUE,16436871,DEEPSKYBLUE,16760576,DODGERBLUE,16748574,CORNFLOWERBLUE,15570276,MEDIUMSLATEBLUE,15624315
     DATA ROYALBLUE,14772545,BLUE,16711680,MEDIUMBLUE,13434880,DARKBLUE,9109504,NAVY,8388608,MIDNIGHTBLUE,7346457,CORNSILK,14481663,BLANCHEDALMOND,13495295,BISQUE,12903679,NAVAJOWHITE,11394815
     DATA WHEAT,11788021,BURLYWOOD,8894686,TAN,9221330,ROSYBROWN,9408444,SANDYBROWN,6333684,GOLDENROD,2139610,DARKGOLDENROD,755384,PERU,4163021,CHOCOLATE,1993170,SADDLEBROWN,1262987
     DATA SIENNA,2970272,BROWN,2763429,MAROON,128,WHITE,16777215,SNOW,16448255,HONEYDEW,15794160,MINTCREAM,16449525,AZURE,16777200,ALICEBLUE,16775408,GHOSTWHITE,16775416
     DATA WHITESMOKE,16119285,SEASHELL,15660543,BEIGE,14480885,OLDLACE,15136253,FLORALWHITE,15792895,IVORY,15794175,ANTIQUEWHITE,14150650,LINEN,15134970,LAVENDERBLUSH,16118015,MISTYROSE,14804223
     DATA GAINSBORO,14474460,LIGHTGRAY,13882323,SILVER,12632256,DARKGRAY,11119017,GRAY,8421504,DIMGRAY,6908265,LIGHTSLATEGRAY,10061943,SLATEGRAY,9470064,DARKSLATEGRAY,5197615,BLACK,0
    END FUNCTION[/FONT]
    [FONT=Courier New]SUB THISONE
     IF IE=0 THEN IE=1
     O$=""
     DO
      GRAPHIC GET DC TO hvin
      IF hvin = 0  THEN EXIT LOOP
      FOR B=0 TO 10
       IF B=IP THEN
        GRAPHIC COLOR %WHITE,RGB(110,120,180)
       ELSE
        GRAPHIC COLOR %BLACK,%WHITE
       END IF
       GRAPHIC SET POS(3,3+CarH*B)
       GRAPHIC PRINT LEFT$(CHR$(32)+CLR$(B+IE)+STRING$(22,32),22)
      NEXT B
      GRAPHIC BOX(183,20)-(197,163),,%WHITE,-1
      GRAPHIC BOX(183,20)-(197,20+143*((IE+IP)/KA)),,RGB(110,120,180),-1
      GRAPHIC REDRAW
      GRAPHIC WINDOW CLICK TO clk,xm,ym
      GRAPHIC INKEY$ TO O$
      IF clk THEN
       IF (xm>182 AND xm<198) AND (ym>20 AND ym<162) THEN
        IE=(KA-IP)*((ym-20)/142)
       ELSEIF (xm>182 AND xm<198) AND (ym>3 AND ym<20)THEN
        O$=CHR$(0,72)
       ELSEIF (xm>182 AND xm<198) AND (ym<180 AND ym>162)THEN
        O$=CHR$(0,80)
       ELSEIF (xm>3 AND xm<182) AND (ym<180 AND ym>3) THEN
        IP=(ym-3)\CarH
        IF clk=2 THEN O$=CHR$(13)
       END IF
      END IF
      SELECT CASE O$
       CASE CHR$(27)
        EXIT LOOP
       CASE CHR$(0,80)
        IF IP<10 THEN
         INCR IP
        ELSE
         IF IE<KA-10 THEN INCR IE
        END IF
       CASE CHR$(0,72)
        IF IP>0 THEN
         DECR IP
        ELSE
         IF IE>1 THEN DECR IE
        END IF
       CASE CHR$(0,73)
        IE=IE-10
        IP=0
       CASE CHR$(0,81)
        IE=IE+10
        IP=10
       CASE CHR$(0,79)
        IE=KA-10
        IP=10
       CASE CHR$(0,71)
        IE=1
        IP=0
       CASE CHR$(13)
        ARC$=CLR$(IE+IP)
        EXIT LOOP
      END SELECT
      IF IE>KA-10 THEN IE=KA-10
      IF IE<1 THEN IE=1
     LOOP
     GRAPHIC REDRAW
    END SUB
     [/FONT]
    [FONT=Courier New][/FONT]
Working...
X