HTML to QB Colors

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
DDastardly71
Coder
Posts: 22
Joined: Fri Oct 17, 2008 6:56 pm
Location: U.S.A.

HTML to QB Colors

Post by DDastardly71 »

Does anybody know how to convert HTML colors (i.e. #FF0000 Red) to QB's SCREEN 0 colors?

I tried using the PALETTE command which has a range of (0-63) but the HTML RGB colors has a range of (0-255).

Is there a formula for this conversion?
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Since HTML values are 4 times what QB color values are, convert from Hex to decimal and divide by 4. (255 \ 4 = 63). Use Integer division or it will round up!

That should get you close.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
DDastardly71
Coder
Posts: 22
Joined: Fri Oct 17, 2008 6:56 pm
Location: U.S.A.

Post by DDastardly71 »

Thanks, that works great.

The only thing is that I can't get it to work on SCREEN 0, only on SCREEN 12.
What I'm trying to do is to display a text starting with black and slowly increasing in intensity until it reaches maximum color. I guess PALETTE doesn't work well on SCREEN 0. SCREEN 12 it is then. Thanks again.
angros47
Veteran
Posts: 79
Joined: Mon Sep 08, 2008 12:52 pm
Contact:

Post by angros47 »

Here is an old program i wrote, to convert HTM files to ANSI TXT files (it needs ANSI.SYS loaded in dos)

I hope it could help

Code: Select all

' HTML to TXT filter
Comm$ = RTRIM$(LTRIM$(COMMAND$))
M = INSTR(Comm$, " ")
IF M = 0 THEN PRINT "Please enter input and output files": END
In$ = LEFT$(Comm$, M)
Out$ = MID$(Comm$, M + 1)
CS$ = "40"
CT$ = "37": Testo = 0

OPEN In$ FOR INPUT AS #1
OPEN Out$ FOR OUTPUT AS #2
S = 1
DO
  P$ = ""
 
  IF EOF(1) THEN PRINT #2, CHR$(27) + "[0;37;40m": END
 
  LINE INPUT #1, a$
  M = 0
  FOR I = 1 TO LEN(a$)
    M = M + 1
    V$ = MID$(a$, M): R$ = LEFT$(V$, 1)
    IF LCASE$(LEFT$(V$, 6)) = """ THEN R$ = CHR$(34): M = M + 5
    IF LCASE$(LEFT$(V$, 8)) = "è" THEN R$ = "?": M = M + 7
    IF LCASE$(LEFT$(V$, 8)) = "é" THEN R$ = "?": M = M + 7
    IF LCASE$(LEFT$(V$, 8)) = "à" THEN R$ = "?": M = M + 7
    IF LCASE$(LEFT$(V$, 8)) = "ò" THEN R$ = "?": M = M + 7
    IF LCASE$(LEFT$(V$, 8)) = "ù" THEN R$ = "?": M = M + 7
    IF LCASE$(LEFT$(V$, 5)) = "&" THEN R$ = "&": M = M + 4
    IF LCASE$(LEFT$(V$, 4)) = "<" THEN R$ = "<": M = M + 3
    IF LCASE$(LEFT$(V$, 4)) = ">" THEN R$ = ">": M = M + 3
   
    IF LCASE$(LEFT$(V$, 4)) = "<hr>" THEN R$ = STRING$(80, "-"): M = M + 3
    IF LCASE$(LEFT$(V$, 5)) = "<font" THEN Font = 1
    IF LCASE$(LEFT$(V$, 7)) = "</font>" THEN R$ = CHR$(27) + "[0;" + CS$ + ";" + CT$ + "m": M = M + 6
    IF LCASE$(LEFT$(V$, 4)) = "<li>" THEN R$ = "?": M = M + 3
    IF LCASE$(LEFT$(V$, 3)) = "<b>" THEN R$ = CHR$(27) + "[1;" + CS$ + ";" + CT$ + "m": M = M + 2
    IF LCASE$(LEFT$(V$, 4)) = "</b>" THEN R$ = CHR$(27) + "[0;" + CS$ + ";" + CT$ + "m": M = M + 3
    IF LCASE$(LEFT$(V$, 7)) = "<blink>" THEN R$ = CHR$(27) + "[5;" + CS$ + ";" + CT$ + "m": M = M + 6
    IF LCASE$(LEFT$(V$, 8)) = "</blink>" THEN R$ = CHR$(27) + "[0;" + CS$ + ";" + CT$ + "m": M = M + 7

    IF S = 0 THEN
      IF LCASE$(LEFT$(V$, 10)) = "bgcolor=" + CHR$(34) + "#" THEN
        C$ = MID$(V$, 11, 6): Red = 0: Green = 0: Blue = 0
        IF MID$(C$, 1, 1) <> "0" AND VAL(MID$(C$, 1, 1)) = 0 THEN Blue = 1
        IF MID$(C$, 3, 1) <> "0" AND VAL(MID$(C$, 3, 1)) = 0 THEN Green = 1
        IF MID$(C$, 5, 1) <> "0" AND VAL(MID$(C$, 5, 1)) = 0 THEN Red = 1
        Colore = Blue * 4 + Green * 2 + Red * 1: IF Testo = 0 AND Colore = 7 THEN Testo = 1: CT$ = "30"
        CS$ = MID$(STR$(40 + Colore), 2)
        P$ = P$ + CHR$(27) + "[0;" + CS$ + ";" + CT$ + "m"
      END IF
      IF LCASE$(LEFT$(V$, 7)) = "text=" + CHR$(34) + "#" THEN
        C$ = MID$(V$, 11, 6): Red = 0: Green = 0: Blue = 0
        IF MID$(C$, 1, 1) <> "0" AND VAL(MID$(C$, 1, 1)) = 0 THEN Blue = 1
        IF MID$(C$, 3, 1) <> "0" AND VAL(MID$(C$, 3, 1)) = 0 THEN Green = 1
        IF MID$(C$, 5, 1) <> "0" AND VAL(MID$(C$, 5, 1)) = 0 THEN Red = 1
        Colore = Blue * 4 + Green * 2 + Red * 1
        CT$ = MID$(STR$(30 + Colore), 2)
        P$ = P$ + CHR$(27) + "[0;" + CT$ + ";" + CS$ + "m"
      END IF
      IF LCASE$(LEFT$(V$, 8)) = "color=" + CHR$(34) + "#" AND Font THEN
        C$ = MID$(V$, 11, 6): Red = 0: Green = 0: Blue = 0
        IF MID$(C$, 1, 1) <> "0" AND VAL(MID$(C$, 1, 1)) = 0 THEN Blue = 1
        IF MID$(C$, 3, 1) <> "0" AND VAL(MID$(C$, 3, 1)) = 0 THEN Green = 1
        IF MID$(C$, 5, 1) <> "0" AND VAL(MID$(C$, 5, 1)) = 0 THEN Red = 1
        Colore = Blue * 4 + Green * 2 + Red * 1
        P$ = P$ + CHR$(27) + "[0;" + MID$(STR$(30 + Colore), 2) + ";" + CS$ + "m"
      END IF

    END IF
   
    IF R$ = CHR$(10) THEN R$ = CHR$(13)
    IF R$ = "<" THEN S = 0
    IF S THEN P$ = P$ + R$
    IF R$ = ">" THEN S = 1: Font = 0
  NEXT
  'PRINT A$
  PRINT #2, P$
 
  'SLEEP 1

LOOP

User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Some screen modes like 0, 7 and 9 use DAC color assignments. Some of those settings may be different than the default attribute settings in screen 12 and 13.

There is a way to convert DAC to default, but it involves setting all DAC values to normal attribute values and then restoring all default settings or Pallette settings to new RGB values.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply