Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 308
» Latest member: Donaldvem
» Forum threads: 1,741
» Forum posts: 17,901

Full Statistics

Latest Threads
The QB64 IDE shell
Forum: Utilities
Last Post: JasonPag
09-16-2024, 05:37 PM
» Replies: 9
» Views: 762
Importance regarding Ches...
Forum: Utilities
Last Post: JasonPag
09-01-2024, 06:34 PM
» Replies: 0
» Views: 31
Chess and Analysis and En...
Forum: Utilities
Last Post: JasonPag
08-28-2024, 02:37 PM
» Replies: 0
» Views: 32
DAY 009:_PutImage
Forum: Keyword of the Day!
Last Post: grymmjack
09-02-2023, 02:57 PM
» Replies: 54
» Views: 2,033
Fall Banner Contest?
Forum: Site Suggestions
Last Post: grymmjack
08-31-2023, 11:50 PM
» Replies: 36
» Views: 1,261
ColorPicker - Function th...
Forum: Dav
Last Post: Dav
08-31-2023, 11:04 PM
» Replies: 3
» Views: 315
Goals(1) = New Tile()
Forum: Works in Progress
Last Post: RhoSigma
08-31-2023, 09:45 PM
» Replies: 3
» Views: 127
micro(A)v11
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 09:14 PM
» Replies: 90
» Views: 3,589
Updating The Single Most ...
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 09:13 PM
» Replies: 7
» Views: 254
QBJS Image Question
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 05:49 PM
» Replies: 5
» Views: 155

 
  Just Some Maths
Posted by: TarotRedhand - 05-03-2022, 10:29 PM - Forum: One Hit Wonders - No Replies

Just a few things I created back in the late 1990s. First a few constants that you may or may not find useful -

Code: (Select All)
REM ******************************************************************
REM * A number of maths constants that have been pre-calculated in  *
REM * order to save execution time.                                  *
REM ******************************************************************

CONST PI# = 3.14159265358979323846              'PI

CONST PITimes2# = 6.28318530717959              'PI * 2
CONST PITimes3# = 9.42477796076938              'PI * 3
CONST PITimes4# = 12.5663706143592              'PI * 4
CONST PITimes5# = 15.707963267949                'PI * 5
CONST PITimes6# = 18.8495559215388              'PI * 6

CONST PIDividedBy2# = 1.57079632679489661923    'PI / 2
CONST PIDividedBy3# = 1.04719755119659774615    'PI / 3
CONST PIDividedBy4# = 0.78539816339744830962    'PI / 4
CONST PIDividedBy5# = 0.628318530717959          'PI / 5
CONST PIDividedBy6# = 0.52359877559829887308    'PI / 6

CONST PISquared# = 9.86960440108936              'PI * PI
CONST PICubed#  = 31.0062766802998              'PI * PI * PI
CONST SQROfPI#  = 1.77245385090552              'SQR(PI)
CONST ReciprocalOfPI# = 0.31830988618379067154  '1 / PI

CONST TwoDividedByPI#  = 0.63661977236758134308 '2 / PI
CONST ThreeDividedByPI# = 0.954929658551372      '3 / PI
CONST FourDividedByPI#  = 1.27323954473516      '4 / PI
CONST FiveDividedByPI#  = 1.59154943091895      '5 / PI
CONST SixDividedByPI#  = 1.90985931710274      '6 / PI

CONST FourThirdsOfPI#  = 4.18879020478639      '4 / 3 * PI

CONST TheConstantE# = 2.71828182845905

CONST SquareOfE# = 7.38905609893065              'E * E
CONST SQROfE# = 1.64872127070013                'SQR(E)
CONST ReciprocalOfE# = 0.367879441171442        '1 / E

CONST LOG3DividedBy2# = 0.54930614433405484570  'LOG(3) / 2

CONST SQROfPnt5# = 0.70710678118654752440        'SQR(0.5)
CONST SQROf2# = 1.41421356227309504880          'SQR(2)
CONST SQROf3# = 1.73205080756887729353          'SQR(3)
CONST TwoMinusSQROf3# = 0.26794919243112270647  '2 - SQR(3)
CONST TwelthRootOf2# = 1.059463094              '12th root of 2

CONST FeigenbaumConstant# = 4.6692016090

REM ******************************************************************
REM * Distance travelled by light in 1 second, minute, hour, day,    *
REM * year.  Measured in Miles (approximately).                      *
REM ******************************************************************

CONST LightSecondInMiles# = 186271.0
CONST LightMinuteInMiles# = 11176260.0
CONST LightHourInMiles# = 670575600.0
CONST LightDayInMiles# = 16093814400.0
CONST LightYearInMiles# = 5797796637600.0

REM ******************************************************************
REM * Distance travelled by light in 1 second, minute, hour, day,    *
REM * year.  Measured in KiloMeters (approximately).                *
REM ******************************************************************

CONST LightSecondInKiloMeters# = 299774.0
CONST LightMinuteInKiloMeters# = 17986440.0
CONST LightHourInKiloMeters# = 1079186400.0
CONST LightDayInKiloMeters# = 25900473600.0
CONST LightYearInKiloMeters# = 9330645614400.0

Then there is this library of a number maths routines. First the documentation (comments also included in the code) -

Code: (Select All)
REM ******************************************************************
REM * The following routines are entirely devoted to logarithms for  *
REM * bases other than e, which is the base used by QB.  The base    *
REM * used in a particular routine is denoted by the number which    *
REM * suffixes Log in the name of the function, with the exception  *
REM * of LogX where the user supplies the base.                      *
REM ******************************************************************

FUNCTION Log2#(x AS DOUBLE)
FUNCTION Log8#(x AS DOUBLE)
FUNCTION Log10#(x AS DOUBLE)
FUNCTION Log16#(x AS DOUBLE)
FUNCTION LogX#(x AS DOUBLE, LogBase AS DOUBLE)

FUNCTION AntiLog2#(x AS DOUBLE)
FUNCTION AntiLog8#(x AS DOUBLE)
FUNCTION AntiLog10#(x AS DOUBLE)
FUNCTION AntiLog16#(x AS DOUBLE)
FUNCTION AntiLogX#(x AS DOUBLE, LogBase AS DOUBLE)

REM ******************************************************************
REM * Finds the y'th root of x.                                      *
REM ******************************************************************

FUNCTION Root#(x AS DOUBLE, y AS DOUBLE)

REM ******************************************************************
REM * Raise x to the power of y.                                    *
REM ******************************************************************

FUNCTION Power#(x AS DOUBLE, y AS DOUBLE)

REM ******************************************************************
REM * Returns x' = x * (x - 1) * (x - 2) ... * 1.  Non-recursive!    *
REM ******************************************************************

FUNCTION Factorial#(x AS DOUBLE)

REM ******************************************************************
REM * Returns the arithmetic mean (average) and the sample standard  *
REM * deviation of the values held in the array In.                  *
REM ******************************************************************

SUB MeanDeviation(Mean AS DOUBLE, StandardDeviation AS DOUBLE, In#())

REM ******************************************************************
REM * Returns a random number that is constrained to have a          *
REM * greater probability of falling within the centre of upper and  *
REM * lower bounds.                                                  *
REM ******************************************************************

FUNCTION GaussianRnd#(DesiredMean#, DesiredDeviation#)

Finally the code -

Code: (Select All)
OPTION BASE 0

REM ******************************************************************
REM * Pre-calculated constants for use by the logarithmic functions  *
REM ******************************************************************

CONST LOGOf2# = 0.6931471805599453094172321      'LOG(2)
CONST LOGOf8# = 2.07944154167984                  'LOG(8)
CONST LOGOf10# = 2.30258509299405                'LOG(10)
CONST LOGOf16# = 2.77258872223978                'LOG(16)

CONST Log2E# = 1.4426950408889634074              '1/LOG(2)
CONST Log8E# = 0.480898346962988                  '1/LOG(8)
CONST Log10E# = 0.43429448190325182765            '1/LOG(10.0)
CONST Log16E# = 0.360673760222241                '1/LOG(16)

REM ******************************************************************
REM * The following routines are entirely devoted to logarithms for  *
REM * bases other than e, which is the base used by QB.  The base    *
REM * used in a particular routine is denoted by the number which    *
REM * suffixes Log in the name of the function, with the exception  *
REM * of LogX where the user supplies the base.                      *
REM ******************************************************************

FUNCTION Log2#(x AS DOUBLE)
    IF x < 0.0 THEN
        Log2# = 0.0
    ELSE
        Log2# = LOG(x) * Log2E#
    END IF
END FUNCTION

FUNCTION Log8#(x AS DOUBLE)
    IF x < 0.0 THEN
        Log8# = 0.0
    ELSE
        Log8# = Log(x) * Log8E#
    END IF
END FUNCTION

FUNCTION Log10#(x AS DOUBLE)
    IF x < 0.0 THEN
        Log10# = 0.0
    ELSE
        Log10# = Log(x) * Log10E#
    END IF
END FUNCTION

FUNCTION Log16#(x AS DOUBLE)
    IF x < 0.0 THEN
        Log16# = 0.0
    ELSE
        Log16# = Log(x) * Log16E#
    END IF
END FUNCTION

FUNCTION LogX#(x AS DOUBLE, LogBase AS DOUBLE)
    IF ((x < 0.0) OR (LogBase <= 0.0)) THEN
        LogX# = 0.0
    ELSE
        LogX# = Log(x) / Log(LogBase)
    END IF
END FUNCTION

FUNCTION AntiLog2#(x AS DOUBLE)
    AntiLog2# = EXP(LOGOf2# * x)
END FUNCTION

FUNCTION AntiLog8#(x AS DOUBLE)
    AntiLog8# = EXP(LOGOf8# * x)
END FUNCTION

FUNCTION AntiLog10#(x AS DOUBLE)
    AntiLog10# = EXP(LOGOf10# * x)
END FUNCTION

FUNCTION AntiLog16#(x AS DOUBLE)
    AntiLog16# = EXP(LOGOf16# * x)
END FUNCTION

FUNCTION AntiLogX#(x AS DOUBLE, LogBase AS DOUBLE)
    IF ((x <= 0.0) OR (LogBase <= 0.0)) THEN
        AntiLogX# = 0.0
    ELSE
        AntiLogX# = EXP(Log(LogBase) * x)
    END IF
END FUNCTION

REM ******************************************************************
REM * Finds the y'th root of x.                                      *
REM ******************************************************************

FUNCTION Root#(x AS DOUBLE, y AS DOUBLE)
    IF ((x <= 0.0) OR (y = 0.0)) THEN
        Root# = 0.0
    ELSE
        Root# = EXP(LOG(x) / y)
    END IF
END FUNCTION

REM ******************************************************************
REM * Raise x to the power of y.                                    *
REM ******************************************************************

FUNCTION Power#(x AS DOUBLE, y AS DOUBLE)
    IF ((x <= 0.0) OR (y = 0.0)) THEN
        Power# = 0.0
    ELSE
        Power# = EXP(LOG(x) * y)
    END IF
END FUNCTION

REM ******************************************************************
REM * Returns x' = x * (x - 1) * (x - 2) ... * 1.  Non-recursive!    *
REM ******************************************************************

FUNCTION Factorial#(x AS DOUBLE)
    WorkingValue# = 2.0
    ReturnValue# = 1.0
    DO WHILE (WorkingValue# <= x)
        ReturnValue# = ReturnValue# * WorkingValue#
        WorkingValue# = WorkingValue# + 1.0
    LOOP
    Factorial# = ReturnValue#
END FUNCTION

REM ******************************************************************
REM * Returns the arithmetic mean (average) and the sample standard  *
REM * deviation of the values held in the array In.                  *
REM ******************************************************************

SUB MeanDeviation(Mean AS DOUBLE, StandardDeviation AS DOUBLE, In#())
    Sum# = 0.0#
    SumOfSquares# = 0.0#
    StartIndex% = LBOUND(In#)
    NumberOfValues% = UBOUND(In#)
    FOR Index% = StartIndex% TO NumberOfValues%
        Sum# = Sum# + In#(Index%)
        SumOfSquares# = SumOfSquares# + In#(Index%) * In#(Index%)
    NEXT Index%
    Mean = Sum# / NumberOfValues
    StandardDeviation = SQR(SumOfSquares# - Sum# * Sum# / NumberOfValues) / (NumberOfValues - 1.0)
END SUB

REM ******************************************************************
REM * Returns a random number that is constrained to have a          *
REM * greater probability of falling within the centre of upper and  *
REM * lower bounds.                                                  *
REM ******************************************************************

FUNCTION GaussianRnd#(DesiredMean#, DesiredDeviation#)
    RandomSum# = 0#
    FOR x% = 1 TO 12
        RandomSum# = RandomSum# + RND
    NEXT x%
    GausianRnd# = (RandomSum# - 6#) * DesiredDeviation# + DesiredMean#
END FUNCTION

Hope you have a use for these.

TR

Print this item

  Plasma Studies
Posted by: bplus - 05-03-2022, 08:03 PM - Forum: bplus - Replies (14)

Probably one of my signature code themes, I've played with Plasma the color sequencing method and with Plasma the 2D blobs. This thread is a study of the latter.
________________________________________________________________________________________________

The earliest QB64 file I can find is Ectoplasm more about Ghost busters than plasma the blobs but close enough:

Code: (Select All)
_Title "Ectoplasm" 'mod of Galileo's at Retro 2019-06-22 B+
'open window 256, 256
Screen _NewImage(256, 256, 32)
Randomize Timer
'sh=peek("winheight")
sh = _Height
'sw=peek("winwidth")
sw = _Width
d = 1
Do
    'tm = peek("secondsrunning")
    tm = Timer(.001)
    dr = ran(256): dg = ran(256): db = ran(256)
    w = w + 5 / 83 '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< get things moving
    For y = 0 To sh
        For x = 0 To sw
            vl = Sin(distance(x + tm, y, 128, 128) / 8 + w)
            vl = vl + Sin(distance(x, y, 64, 64) / 8)
            vl = vl + Sin(distance(x, y + tm / 7, 192, 64) / 7)
            vl = vl + Sin(distance(x, y, 192, 100) / 8)
            clr = 255 / (1.00001 * Abs(vl))
            r = .9 * Abs(clr - dr): g = .4 * Abs(clr - dg): b = .5 * Abs(clr - db)
            'COLOR r, g, b
            'dot x, y
            PSet (x, y), _RGB32(r, g, b)
        Next
    Next
    If w > 1000 Or w < -1000 Then w = 0: d = d * -1
    _Display
    _Limit 200
Loop
Function distance (x1, y1, x2, y2) '//between two points x1,y1 and x2,y2
    distance = ((x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5
End Function
Function ran% (sing)
    ran% = Int(Rnd * sing) + 1
End Function



Attached Files Thumbnail(s)
   
Print this item

  Australian members, problem connecting?
Posted by: Jack - 05-03-2022, 07:14 PM - Forum: General Discussion - Replies (12)

Richard says he can't connect to this forum and wonders if other Australian members are having the same problem

Print this item

  Looking for sample code showing how to make use of different fonts
Posted by: hanness - 05-03-2022, 04:49 PM - Forum: General Discussion - Replies (6)

All my programming with QB64 so far has made use of a console window where I simply used plain text.

I have a small project in which I would like to use different fonts and text sizes. Does anyone have a few sample clips available to show me how to specify a font to use and how to size that font?

I've been poking at this myself but I'm simply missing something.

Print this item

  Code conversion to HTML, CSS, PHP, or Javascript
Posted by: Michelle - 05-03-2022, 03:11 PM - Forum: General Discussion - Replies (9)

So, I'm back and in search of wisdom from all of your wealth of knowledge. I have a program I wrote in QB64, and it works fine. Apparently, there is thinking that it would be nice to integrate it into a website that uses WordPress. And I know squat about WordPress. What I do know says that WordPress sites use HTML, CSS, PHP, or Javascript. Neither of which I know anything about. Is there any outside chance, that there is some sort of conversion process to take QB64 code and turn it into one of those four? Even if it is from the source code? I'm thinking that would probably be what is wanted in the end since it could be maintained within the WordPress site. Probably not, but I figured I'd ask the experts. Thanks, Michelle

Print this item

  Star Wars
Posted by: johnno56 - 05-03-2022, 02:52 PM - Forum: General Discussion - Replies (65)

May the 4th be with you!!

Print this item

  Books about qb64 network programming
Posted by: stranger_ - 05-03-2022, 02:27 PM - Forum: General Discussion - Replies (3)

Are there books where you can learn network programming on qb64? if so, please send links to them. This is my first time posting something on a forum, am I doing it right? thanks to all

Print this item

  Shell "dir" -- I expected something, but ..
Posted by: dcromley - 05-03-2022, 03:52 AM - Forum: Help Me! - Replies (4)

I expect to be humbled by this thread, but I expected something from the "dir" but get only "A" and "B".  Where is the output going?

Code: (Select All)
Print "A"
Shell "dir"
Print "B"

Print this item

  QB64 Phoenix Forum is now indexed for search Engines.
Posted by: Pete - 05-03-2022, 12:43 AM - Forum: Announcements - Replies (13)

Thanks to everyone for coming back and adding content. I just checked today, and probably earlier today or over the weekend, the search bots decided we had enough content to help people looking for the QB64 support to find the forum.

If anyone knows how to contact Tempo (TempoBasic) or Petr, they still haven't found their way here, please give them a shout out. It would be grate to see them back.

Pete

Print this item

  QPrint (falcon.h simplified)
Posted by: SMcNeill - 05-02-2022, 11:03 PM - Forum: SMcNeill - Replies (7)

There's several programs out there that make use of falcon.h by now, but I wanted to take a shot at tossing in my own personal version of a simplified wrapper for the command -- QPRINT.

Code: (Select All)
$IF FALCON = UNDEFINED THEN
    $LET FALCON = TRUE
    DECLARE LIBRARY "./falcon"
        SUB uprint_extra (BYVAL x&, BYVAL y&, BYVAL chars%&, BYVAL length%&, BYVAL kern&, BYVAL do_render&, txt_width&, BYVAL charpos%&, charcount&, BYVAL colour~&, BYVAL max_width&)
        FUNCTION uprint (BYVAL x&, BYVAL y&, chars$, BYVAL txt_len&, BYVAL colour~&, BYVAL max_width&)
        FUNCTION uprintwidth (chars$, BYVAL txt_len&, BYVAL max_width&)
        FUNCTION uheight& ()
        FUNCTION uspacing& ()
        FUNCTION uascension& ()
    END DECLARE
    DIM SHARED QPrintTextType AS STRING
    QPrintTextType = "ASCII"
$END IF


SCREEN _NEWIMAGE(1024, 720, 32)
f = _LOADFONT("cyberbit.ttf", 20, "monospace")
_FONT f


QPrintTextType = "ASCII" 'Here. we're printing using ASCII character codes

FOR y = 0 TO 15
    FOR x = 0 TO 15
        QPrintString x * 30, y * uheight, CHR$(count) 'To showcase the printstring version of Qprint
        count = count + 1
    NEXT
NEXT

SLEEP
CLS

QPrintTextType = "UTF8" 'This uses UTF8 (Unicode) character encoding to print.

OPEN "test.txt" FOR INPUT AS #1
DO UNTIL EOF(1)
    LINE INPUT #1, temp$
    QPrint temp$ 'tho show how simple Qprint itself is.
    SLEEP
LOOP


END

SUB QPrint (temp$)
    STATIC m AS _MEM: m = _MEMIMAGE(0)
    DIM BreakPoint AS STRING
    BreakPoint = ",./- ;:!" 'I consider all these to be valid breakpoints.  If you want something else, change them.
    IF QPrintTextType = "ASCII" OR QPrintTextType = "" THEN text$ = _TRIM$(AnsiTextToUtf8Text$(temp$)) ELSE text$ = temp$
    count = -1
    DO
        'first find the natural length of the line
        x = POS(0) - 1: IF _FONTWIDTH THEN x = x * _FONTWIDTH
        y = CSRLIN
        wide% = _WIDTH - x - 1
        FOR i = 1 TO LEN(text$)
            IF ASC(text$, i) = 10 OR ASC(text$, i) = 13 THEN i = i - 1: EXIT FOR
            p = uprintwidth(text$, i, 0)
            IF p > wide% THEN EXIT FOR
        NEXT
        'IF i < LEN(text$) THEN lineend = i - 1 ELSE
        lineend = i

        t$ = RTRIM$(LEFT$(text$, lineend)) 'at most, our line can't be any longer than what fits the screen.
        FOR i = lineend TO 1 STEP -1
            IF INSTR(BreakPoint, MID$(text$, i, 1)) THEN lineend = i: EXIT FOR
        NEXT
        out$ = RTRIM$(LEFT$(text$, lineend))
        text$ = LTRIM$(MID$(text$, lineend + 1))
        IF LEFT$(text$, 2) = CHR$(13) + CHR$(10) THEN text$ = MID$(text$, 3)
        IF LEFT$(text$, 2) = CHR$(10) + CHR$(13) THEN text$ = MID$(text$, 3)
        IF LEFT$(text$, 1) = CHR$(13) THEN text$ = MID$(text$, 2)
        IF LEFT$(text$, 1) = CHR$(10) THEN text$ = MID$(text$, 2)
        IF _BACKGROUNDCOLOR <> 0 THEN
            LINE (x - 1, (y - 1) * uheight)-STEP(uprintwidth(out$, LEN(out$), 0), uheight), _BACKGROUNDCOLOR, BF
        END IF
        w& = uprint(x - 1, (y - 1) * uheight, out$, LEN(out$), _DEFAULTCOLOR, 0)
        x = 1
        IF y + 1 >= _HEIGHT / uheight THEN 'scroll up
            h = uheight * _WIDTH * 4
            t$ = SPACE$(m.SIZE - h)
            _MEMGET m, m.OFFSET + h, t$
            CLS , 0
            _MEMPUT m, m.OFFSET, t$
            LOCATE y, x
        ELSE
            LOCATE y + 1, x
        END IF

    LOOP UNTIL text$ = ""
    clean_exit:
END SUB

FUNCTION QPrintWidth& (out$)
    QPrintWidth = uprintwidth(out$, LEN(out$), 0)
END FUNCTION

FUNCTION QFontHeight
    QFontHeight = uheight
END FUNCTION

SUB QPrintString (x, y, text$)
    IF QPrintTextType = "ASCII" OR QPrintTextType = "" THEN temp$ = _TRIM$(AnsiTextToUtf8Text$(text$)) ELSE temp$ = text$
    IF _BACKGROUNDCOLOR <> 0 THEN
        LINE (x, y)-STEP(uprintwidth(temp$, LEN(temp$), 0), uheight), _BACKGROUNDCOLOR, BF
    END IF
    w& = uprint(x, y, temp$, LEN(temp$), _DEFAULTCOLOR, 0)
END SUB

FUNCTION AnsiTextToUtf8Text$ (text$)
    DIM chi&, ascii%, unicode&, aci%
    FOR chi& = 1 TO LEN(text$)
        '--- get ANSI char code, reset Unicode ---
        unicode& = _MAPUNICODE(ASC(text$, chi&))
        IF unicode& = 0 THEN unicode& = 65533 'replacement character
        temp$ = temp$ + UnicodeToUtf8Char$(unicode&)
    NEXT chi&
    AnsiTextToUtf8Text$ = temp$
END FUNCTION

FUNCTION UnicodeToUtf8Char$ (unicode&)
    '--- option _explicit requirements ---
    DIM uc&, first%, remain%, conti%
    '--- UTF-8 encoding ---
    IF unicode& < 128 THEN
        '--- standard ASCII (0-127) goes as is ---
        UnicodeToUtf8Char$ = CHR$(unicode&)
        EXIT FUNCTION
    ELSE
        '--- encode the Unicode into UTF-8 notation ---
        temp$ = "": uc& = unicode& 'avoid argument side effect
        first% = &B10000000: remain% = 63
        DO
            first% = &B10000000 OR (first% \ 2): remain% = (remain% \ 2)
            conti% = &B10000000 OR (uc& AND &B00111111): uc& = uc& \ 64
            temp$ = CHR$(conti%) + temp$
            IF uc& <= remain% THEN
                first% = (first% OR uc&): uc& = 0
            END IF
        LOOP UNTIL uc& = 0
        UnicodeToUtf8Char$ = CHR$(first%) + temp$
    END IF
END FUNCTION

Instead of trying to track all sorts of parameters for uprint -- (x&, y&, chars$, txt_len&, colour~&, max_width&) -- I've written a wrapper to break it down to one little command QPrint text$.

If you want colors, simply use QB64's normal COLOR command. If you want to position your text, simply use LOCATE, like you normally would with your code. It word wraps automatically, as well as scrolls the screen for us if we end up printing down on the bottom line of the screen. Basically, use it more or less like you would a simplified PRINT statement that can only handle a single string output.

The advantage to this little command? (And to falcon.h, in general?)

No cutting off parts of your characters. Some fonts are terrible about having half the letter cut off (I was using a script font the other day that lost the whole top half of my T's and F's, and their flourishes.), and you should be able to see the difference and the problem with the example code, which relies on cyberbit.ttf.

NOTE: QPrint's LOCATE and PRINT's LOCATE are two completely different areas of your screen. Don't expect the two to match at all for you. With the example, QPRINT is printing a character 26 pixels high, whereas PRINT cuts off segments of it and only prints a character 20 pixels high... That difference is going to naturally lead to the rows being at different heights, so don't expect to LOCATE y,x and then QPRINT, and then LOCATE y,x and PRINT, and have the lines match up at all.



The first screen that pops up, you guys might recognize as our ASCII chart. It's the whole ASCII range of characters mapped over and converted from QB64's codepages over to UTF8 format, and then printed to the screen for us, by setting "ASCII" mode printing.

Now, the second screen generated above, is using QPrint to print Unicode (UTF-8) formatted text.

By default, QPrint is set to print ASCII-code pages, but it can be converted to use UTF-8 code pages with a simple variable change:

QPrintTextType = "ASCII" <-- This sets us to our default printing using the ASCII code page. (Or just leave it blank as "" does the same.)

QPrintTextType = "UTF8" or "UNICODE" and we try to print it as UTF-8 formatted text.

Change the global variable, change how you're printing...

It's now THAT simple to display UTF-8 code on to the screen.


NOTE: To use QPrint, you have to load a custom font with it. QB64's in-built fonts currently aren't working as you'd think they should with it, so be certain to load your own font.

Necessary header file, font, and test file are included in the Download.7z attachment.



Attached Files
.7z   Downloads.7z (Size: 4.65 MB / Downloads: 74)
Print this item