FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

DRAWING

Mix colours


Here's some code I use to average 2 colors when the colored regions overlap. It has the effect of darkening. This code was adopted from an example in the FBII Handbook.

Charlie Dickman

CLEAR LOCAL
LOCAL FN AvgPaint4DRgn(face1, rgn1H&, face2, rgn2H&)
  DIM red&, green&, blue&, rgbRed, rgbGreen, rgbBlue, rgnH&
  DIM red1&, red2&, green1&, green2&, blue1&, blue2&
  rgnH& = FN NEWRGN
  CALL SECTRGN(rgn1H&, rgn2H&, rgnH&)
  red1& = VAL(UNS$(gColor.red%(face1))) : red2& = VAL(UNS$(gColor.red%(face2)))
  red& = (red1& + red2&) / 2&
  green1& = VAL(UNS$(gColor.green%(face1))) : green2& =
  VAL(UNS$(gColor.green%(face2)))
  green& = (green1& + green2&) / 2&
  blue1& = VAL(UNS$(gColor.blue%(face1))) : blue2& =
  VAL(UNS$(gColor.blue%(face2)))
  blue& = (blue1& + blue2&) / 2&
  FN AvgRGB(red&, green&, blue&, @rgbRed, @rgbGreen, @rgbBlue)
  LONG COLOR rgbBlue, rgbGreen, rgbRed
  CALL PAINTRGN(rgnH&)
  DEF DISPOSEH(rgnH&)
END FN


I've got a little FN that does this, it's part of my Progress bar code.

You pass it any color in RGB-HTML format(Ie, "FFFFFF" for white, "FF0000" for red, etc.)

the calling convention for this is simple:

myhtmlcolor$=PSTR$(FN MIXCOLORS("FFFFFF","FF0000")) and myhtmlcolor$ will turn out "hot pink", because we mixed white and red. Also, as I recall, mixing Red and Green will give you an olive brown, like you'd expect. Mixing yellow and blue will turn it green, too. :-)

Here we go:

LOCAL FN MIXCOLORS(argeebee1$,argeebee2$)
  r1$="&H"+MID$(argeebee1$,1,2)
  r2$="&H"+MID$(argeebee2$,1,2)
  g1$="&H"+MID$(argeebee1$,3,2)
  g2$="&H"+MID$(argeebee2$,3,2)
  b1$="&H"+MID$(argeebee1$,5,2)
  b2$="&H"+MID$(argeebee2$,5,2)

  rr1%=VAL(r1$)
  rr2%=VAL(r2$)
  gg1%=VAL(g1$)
  gg2%=VAL(g2$)
  bb1%=VAL(b1$)
  bb2%=VAL(b2$)

  rr& = (rr1%+rr2%)/2
  gg& = (gg1%+gg2%)/2
  bb& = (bb1%+bb2%)/2

  t1$="00"+HEX$(rr&)
  t2$="00"+HEX$(gg&)
  t3$="00"+HEX$(bb&)
  myargeebee$=RIGHT$(t1$,2)+RIGHT$(t2$,2)+RIGHT$(t3$,2)
END FN = @myargeebee$

And then, all you have to do to set this color as current:

LOCAL FN LONGERCOLOR(argeebee$)
'send this an RRGGBB value in hexadecimal, like HTML does
'(Neat idea, hmm?)
  DIM newcolor.6
  r1$="&H"+MID$(argeebee$,1,2)
  g1$="&H"+MID$(argeebee$,3,2)
  b1$="&H"+MID$(argeebee$,5,2)

  rr%=VAL(r1$)
  gg%=VAL(g1$)
  bb%=VAL(b1$)

'code below makes the whole routine worthwhile.
  newcolor.red = rr%*256+rr%
  newcolor.green = gg%*256+gg%
  newcolor.blue = bb%*256+bb%

  CALL RGBFORECOLOR(#@newcolor)
END FN