Older Version Newer Version

JanetTerra JanetTerra Aug 26, 2010

==Multi-Colored Text== ===Add a Little More Pizzaz to Graphics Text=== [[user:JanetTerra]] You can define the color of your graphics text with the graphics COLOR command. There are these 16 defined colors and then Buttonface, the default background color. ---------- //**[[http://www.libertybasic.com|Liberty BASIC's]] 16 Named Colors**// > Yellow > Brown > Red > Darkred > Pink > Darkpink > Blue > Darkblue > Green > Darkgreen > Cyan > Darkcyan > White > Black > Lightgray (also called Palegray) > Darkgray The COLOR command works with a //**Graphics Window**// or //**Graphicbox**//. [[code format="vb"]] Open "My Graphics" for Graphics as #g [[code]] ---------- //**The COLOR Command Using a Named Color**// [[code format="vb"]] Print #g, "Color Blue" [[code]] or [[code format="vb"]] hue$ = "Blue" Print #g, "Color ";hue$ [[code]] ---------- //**The COLOR Command Using an RGB Color**// Beyond the named colors are the RGB colors. RGB colors are composites of Red, Green and Blue. Each of the three colors can hold values of 0 - 255. [[code format="vb"]] Print #g, "Color 128 0 255" [[code]] or [[code format="vb"]] redHue = 128 greenHue = 0 blueHue = 255 Print #g, "Color ";redHue;" ";greenHue;" ";blueHue [[code]] or [[code format="vb"]] hue$ = "128 0 255" Print #g, "Color ";hue$ [[code]] ---------- Only one color can be used at a time, but, by layering colors, some very interesting effects can be achieved. The following demo # Gets a bitmap of the entire graphics window (pic1) # Selects a new color for the text # Draws the text in the new color # Gets a bitmap of a portion of the graphics window (pic) # Draws pic1 # Overlays pic1 with pic2 # Begins again with Step 1 This loop continues for the height of the text. All drawing is **DISCARD**ed until the final drawing is captured with the **GETBMP** command, displayed with the **DRAWBMP** command and **FLUSH**ed to conserve memory. Memory is further conserved with a combination of **SEGMENT** and **DELSEGMENT** commands. [[code format="vb"]] Nomainwin WindowWidth = 757 WindowHeight = 554 UpperLeftX = Int((DisplayWidth - WindowWidth) /2) UpperLeftY = Int((DisplayHeight - WindowHeight) /2) Menu #demo, "&Options", "E&xit", MenuExit Graphicbox #demo.gb1, 0, 0, 750, 500 Open "Rainbow Text" for Window as #demo #demo,#demo "Trapclose TrapExit" #demo.gb1, #demo.gb1 "Down; Fill Lightgray; Flush" #demo.gb1, #demo.gb1 "Getbmp pic 0 0 750 500" Call RainbowText "Rainbow Colors", "Verdana 32 Bold", 80, 100 Call VarigatedText "Varigated Blue", "Courier_New 54 Bold Italic", 70, 200 Wait Sub TrapExit handle$ Close #handle$ End End Sub Sub MenuExit Call TrapExit "#demo" End Sub Sub RainbowText text$, textFont$, textLLX, textLLY Unloadbmp "pic" #demo.gb1, "Font ";textFont$ FontHeight = FontHeight(textFont$) yUpper = textLLY - FontHeight yLower = textLLY + Int(FontHeight / 2) For y = yLower to yUpper Step -3 #demo.gb1,#demo.gb1 "Getbmp pic1 0 0 750 500" redHue = Int(Rnd(1) * 256) greenHue = Int(Rnd(1) * 256) blueHue = Int(Rnd(1) * 256) #demo.gb1,#demo.gb1 "Backcolor Lightgray" #demo.gb1, #demo.gb1 "Color ";redHue;" ";greenHue;" ";blueHue #demo.gb1, #demo.gb1 "Place ";textLLX;" ";textLLY #demo.gb1, #demo.gb1 "\";text$ #demo.gb1, #demo.gb1 "Getbmp pic2 0 0 750 ";y #demo.gb1, #demo.gb1 "Drawbmp pic1 0 0" #demo.gb1, #demo.gb1 "Drawbmp pic2 0 0" #demo.gb1, #demo.gb1 "Discard" Next y #demo.gb1,#demo.gb1 "Getbmp pic 0 0 750 500" #demo.gb1, #demo.gb1 "Drawbmp pic 0 0" #demo.gb1, #demo.gb1 "Segment segID" #demo.gb1, #demo.gb1 "Flush" #demo.gb1, #demo.gb1 "Delsegment ";segID - 1 End Sub Sub VarigatedText text$, textFont$, textLLX, textLLY Unloadbmp "pic" FontHeight = FontHeight(textFont$) #demo.gb1, "Font ";textFont$ yUpper = textLLY - FontHeight - 2 yLower = textLLY + Int(FontHeight / 2) hueInc = Int(256 / FontHeight) * 2 blueHue = 0 For y = yLower to yUpper Step -2 #demo.gb1,#demo.gb1 "Getbmp pic1 0 0 750 500" blueHue = Min(255, blueHue + hueInc) #demo.gb1,#demo.gb1 "Backcolor Lightgray" #demo.gb1, #demo.gb1 "Color 0 0 ";blueHue #demo.gb1, #demo.gb1 "Place ";textLLX;" ";textLLY #demo.gb1, #demo.gb1 "\";text$ #demo.gb1, #demo.gb1 "Getbmp pic2 0 0 750 ";y #demo.gb1, #demo.gb1 "Drawbmp pic1 0 0" #demo.gb1, #demo.gb1 "Drawbmp pic2 0 0" #demo.gb1, #demo.gb1 "Discard" Next y #demo.gb1,#demo.gb1 "Getbmp pic 0 0 750 500" #demo.gb1, #demo.gb1 "Drawbmp pic 0 0" #demo.gb1, #demo.gb1 "Segment segID" #demo.gb1, #demo.gb1 "Flush" #demo.gb1, #demo.gb1 "Delsegment ";segID - 1 End Sub Function FontHeight(textFont$) n = 1 While Val(Word$(textFont$, n)) = 0 n = n + 1 Wend FontHeight = Val(Word$(textFont$, n)) End Function [[code]] ---------- If the graphics window becomes obscured by another window or lies offscreen, **DRAWBMP** will not capture the full drawing. This can be prevented by using the [[http://lbpe.wikispaces.com/Stylebits+-+Windows|stylebits]] **WS_EX_TOPMOST** prior to opening the window.