Announcement

Collapse
No announcement yet.

Problem with FONT NEW and GRAPHIC SET FONT

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

  • Problem with FONT NEW and GRAPHIC SET FONT

    I've run into a problem with graphic fonts in PB/CC 5.0 where for some reason, after creating and destroying fonts in a loop for a time, the FONT NEW no longer works properly.
    I'm not sure if its a PowerBASIC issue or a Windows issue, but it seems like something is running out of memory, and the program is no longer able to create new fonts.
    The reason for needing to create and destroy fonts so many times is to be able to print fonts at any rotation and at any size, so it has to be done on the fly by creating them at the right size and angle as needed. That's too many possible angles and sizes to pre-create.

    Here is the start of a program that shows the problem. It doesn't matter if the FONT END is included or not, same problem. Also, it doesn't matter if the board is rotated or not, just calling the SUB that redraws the board as is, which requires rotating the fonts to complete the drawing, causes the problem after a while. The board needs to be able to be resized too, but until I get this figured out, there's no point in going further down this path.

    Is there a better way to rotate and resize fonts on the fly with this many possible combinations of fonts using PB/CC 5.0?


    Code:
    #COMPILE EXE
    
    FUNCTION PBMAIN () AS LONG
        CONSOLE SET LOC -10000, -10000
        DESKTOP GET CLIENT TO ScreenWidth&, ScreenHeight&
        GRAPHIC WINDOW "DartBoard", 0, 0, ScreenWidth&, ScreenHeight& TO MyWindow???
        GRAPHIC ATTACH MyWindow???, 0, REDRAW
    
        DIM RingRadius#(7), BoardColor&(102), RingNumber&(102), WedgeValue&(102), FillPointx#(102), FillPointy#(102), Fontx#(20), Fonty#(20)
        Radian#  = .017453293
        MinBoardSize# = 100
        MaxBoardSize# = ScreenHeight& * .9
    
    
        FOR Wedge& = 1 TO 20
            BoardColor&(Wedge&) = RGB(Wedge&, Wedge&, Wedge&)
            RingNumber&(Wedge&) = 1
            WedgeValue&(Wedge&) = VAL(READ$(Wedge&))
        NEXT Wedge&
    
        FOR Wedge& = 0 TO 9
            BoardColor&(Wedge& * 2 + 21) = RGB(240 - Wedge&, 0, 0)
            BoardColor&(Wedge& * 2 + 22) = RGB(0, 140 - Wedge&, 0)
            RingNumber&(Wedge& * 2 + 21) = 2
            RingNumber&(Wedge& * 2 + 22) = 2
            WedgeValue&(Wedge& * 2 + 21) = VAL(READ$(Wedge& * 2 + 1))
            WedgeValue&(Wedge& * 2 + 22) = VAL(READ$(Wedge& * 2 + 2))
    
            BoardColor&(Wedge& * 2 + 41) = RGB(Wedge& + 21, Wedge& + 21, Wedge& + 21)
            BoardColor&(Wedge& * 2 + 42) = RGB(230 - Wedge&, 230 - Wedge&, 200 - Wedge&)
            RingNumber&(Wedge& * 2 + 41) = 3
            RingNumber&(Wedge& * 2 + 42) = 3
            WedgeValue&(Wedge& * 2 + 41) = VAL(READ$(Wedge& * 2 + 1))
            WedgeValue&(Wedge& * 2 + 42) = VAL(READ$(Wedge& * 2 + 2))
    
            BoardColor&(Wedge& * 2 + 61) = RGB(230 - Wedge&, 0, 0)
            BoardColor&(Wedge& * 2 + 62) = RGB(0, 130 - Wedge&, 0)
            RingNumber&(Wedge& * 2 + 61) = 4
            RingNumber&(Wedge& * 2 + 62) = 4
            WedgeValue&(Wedge& * 2 + 61) = VAL(READ$(Wedge& * 2 + 1))
            WedgeValue&(Wedge& * 2 + 62) = VAL(READ$(Wedge& * 2 + 2))
    
            BoardColor&(Wedge& * 2 + 81) = RGB(Wedge& + 31, Wedge& + 31, Wedge& + 31)
            BoardColor&(Wedge& * 2 + 82) = RGB(220 - Wedge&, 220 - Wedge&, 190 - Wedge&)
            RingNumber&(Wedge& * 2 + 81) = 5
            RingNumber&(Wedge& * 2 + 82) = 5
            WedgeValue&(Wedge& * 2 + 81) = VAL(READ$(Wedge& * 2 + 1))
            WedgeValue&(Wedge& * 2 + 82) = VAL(READ$(Wedge& * 2 + 2))
        NEXT
        BoardColor&(101) = RGB(0, 120, 0)
        BoardColor&(102) = RGB(220, 0, 0)
        RingNumber&(101) = 6
        RingNumber&(102) = 7
        WedgeValue&(101) = 100
        WedgeValue&(102) = 200
    
    
    
        ForeGroundColor& = RGB(255, 255, 255)
        BackGroundColor& = RGB(0, 0, 255)
        BoardFontColor&  = RGB(255, 255, 255)
    
        BoardCenterx# = ScreenWidth&  / 2
        BoardCentery# = ScreenHeight& / 2
        BoardSize#    = ScreenHeight& / 2 * .8
    
        BoardAngle# = 0
        SpinRate#   = 1
    
    
        DO
    
            GRAPHIC COLOR ForeGroundColor&, BackGroundColor&
            GRAPHIC CLEAR
    
            CALL GetBoardLayout   (BoardCenterx#, BoardCentery#, BoardSize#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), WedgeValue&(), Fontx#(), Fonty#(), FontSize#)
            CALL DrawBoard        (BoardCenterx#, BoardCentery#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), BoardColor&(), BackGroundColor&)
            CALL DrawBoardNumbers (BoardAngle#, BoardFontColor&, FontSize#, Fontx#(), Fonty#(), WedgeValue&())
    
    
            GRAPHIC REDRAW
    
            BoardAngle# = BoardAngle# + SpinRate#
            IF BoardAngle# = 360 THEN BoardAngle# = BoardAngle# - 360
    
    
    
            GRAPHIC INKEY$ TO test$
        LOOP UNTIL test$ <> ""
        
    
    
    
    
    DATA 20, 1, 18, 4, 13, 6, 10, 15, 2, 17, 3, 19, 7, 16, 8, 11, 14, 9, 12, 5
    
    END FUNCTION
    
    
    
    
    
    
    
    
    SUB GetBoardLayout (BoardCenterx#, BoardCentery#, BoardSize#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), WedgeValue&(), Fontx#(), Fonty#(), FontSize#)
        Radian# = .017453293
        RingRadius#(1) = BoardSize#
        RingRadius#(2) = BoardSize# * .76
        RingRadius#(3) = BoardSize# * .72
        RingRadius#(4) = BoardSize# * .48
        RingRadius#(5) = BoardSize# * .44
        RingRadius#(6) = BoardSize# * .07
        RingRadius#(7) = BoardSize# * .03
    
        FOR Ring& = 0 TO 4
            FOR Wedge& = 1 TO 20
                FillPointx#(Ring& * 20 + Wedge&) = BoardCenterx# + (RingRadius#(Ring& + 1) - 2) * SIN(((Wedge& - 1) * 18 + BoardAngle#) * Radian#)
                FillPointy#(Ring& * 20 + Wedge&) = BoardCentery# - (RingRadius#(Ring& + 1) - 2) * COS(((Wedge& - 1) * 18 + BoardAngle#) * Radian#)
            NEXT
        NEXT
    
        FillPointx#(101) = BoardCenterx#
        FillPointy#(101) = BoardCentery# - (RingRadius#(6) - 2) * COS(0 * Radian#)
        FillPointx#(102) = BoardCenterx#
        FillPointy#(102) = BoardCentery#
    
        FontName$   = ""  'Use Current
        FontSize#   = BoardSize# * .09                                          'Adjust font size according to board size
        FontStyle&  = 0   'Normal
        FontSet&    = 1   'Default
        FontFamily& = 16  'Roman
        FontAngle&  = 0
    
        FONT NEW FontName$, FontSize#, FontStyle&, FontSet&, FontFamily&, FontAngle& TO BoardFont&
        GRAPHIC SET FONT BoardFont&
    
        FOR Wedge& = 1 TO 20
            GRAPHIC TEXT SIZE LTRIM$(STR$(WedgeValue&(Wedge&))) TO TextWidth#, TextHeight#
            TextRadius#  = RingRadius#(1) * 1.015                               'Move text up a bit to adjust for space above fonts
            CenterAngle# = (Wedge& - 1) * 18 * Radian#
            TextOffset#  = ATN(TextWidth# * .75 / TextRadius#)                  'Center text according to text width plus leading space
    
            Fontx#(Wedge&) = BoardCenterx# + TextRadius# * SIN(CenterAngle# - TextOffset# + BoardAngle# * Radian#)
            Fonty#(Wedge&) = BoardCentery# - TextRadius# * COS(CenterAngle# - TextOffset# + BoardAngle# * Radian#)
        NEXT
        FONT END BoardFont&
    END SUB
    
    
    SUB DrawBoard (BoardCenterx#, BoardCentery#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), BoardColor&(), BackGroundColor&)
        Radian# = .017453293
        FOR Angle# = 0 TO 360 STEP .1
            FOR Radii# = 1 TO 7
                x# = BoardCenterx# + RingRadius#(Radii#) * SIN(Angle# * Radian#)
                y# = BoardCentery# - RingRadius#(Radii#) * COS(Angle# * Radian#)
    
                IF Radii# = 1 THEN
                    RingColor& = RGB(255, 255, 255)
                ELSE
                    RingColor& = RGB(150, 150, 150)
                END IF
    
                GRAPHIC SET PIXEL (x#, y#), RingColor&
            NEXT Radii#
        NEXT
    
        FOR Angle# = BoardAngle# + 9 TO BoardAngle# + 351 STEP 18
            x1# = BoardCenterx# + RingRadius#(6) * SIN(Angle# * Radian#)
            y1# = BoardCentery# - RingRadius#(6) * COS(Angle# * Radian#)
            x2# = BoardCenterx# + RingRadius#(1) * SIN(Angle# * Radian#)
            y2# = BoardCentery# - RingRadius#(1) * COS(Angle# * Radian#)
            GRAPHIC LINE (x1#, y1#) - (x2#, y2#), RGB(150, 150, 150)
        NEXT
    
        FOR Wedge& = 1 TO 102
            GRAPHIC PAINT REPLACE (FillPointx#(Wedge&), FillPointy#(Wedge&)), BoardColor&(Wedge&), BackGroundColor&
        NEXT
    END SUB
    
    
    SUB DrawBoardNumbers (BoardAngle#, FontColor&, FontSize#, Fontx#(), Fonty#(), WedgeValue&())
        FontName$   = ""  'Use Current
        FontStyle&  = 0   'Normal
        FontSet&    = 1   'Default
        FontFamily& = 16  'Roman
    
        GRAPHIC COLOR FontColor&, -2
    
        FOR Wedge& = 1 TO 20
            FontAngle& = (360 - BoardAngle# - (Wedge& - 1) * 18) * 10
            FONT NEW  FontName$, FontSize#, FontStyle&, FontSet&, FontFamily&, FontAngle& TO BoardFont&
            GRAPHIC SET FONT BoardFont&
            GRAPHIC SET POS (Fontx#(Wedge&), Fonty#(Wedge&))
            GRAPHIC PRINT WedgeValue&(Wedge&);
            FONT END BoardFont&
        NEXT
    END SUB

  • #2
    I compiled and ran your code but I don't know just what you mean by " no longer works properly."
    If you were experiencing inverted numbers rotating around the board, well I got that too.
    If you were experiencing that the centre about which the numbers rotated was offset from the 'board', then I got that also.
    If you were experiencing that the spacing between the numbers was inconsistent, so did I.
    If you are experiencing the receipt of errors, then I didn't get any anytime I ran it.
    The only issues that appeared were the ones I mentioned and none appear to be related directly to the FONT series of statements. It appears to me that one of you positioning calculations may be eccentric(or wrong-sorry for the pun) and by virtue of your Font's reliance on the positioning, it may be appearing as a Font issue.
    Hope this helps with your diagnosis.
    Last edited by Rodney Hicks; 3 Jun 2009, 01:51 AM.
    Rod
    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

    Comment


    • #3
      Two other items of note.
      I ran this on an 22 inch monitor in portrait mode(it swivels twixt the portrait/landscape positions) hence my height/width parameter ratio would be reversed from the norm and this would exacerbate an almost unnoticeable issue in standard landscape mode.

      Also, and studying the code, I can see no reason for the topmost and bottommost numbers appearing to jump, about 1/8 of the font height as they pass the imaginary vertical line that passes through the centre(top jumps up, and back down; bottom jumps down then back up). In other words, there does not appear to be a conditional statement to that would supply this effect.
      I did not rip apart the calculations to see where this is, and because on my monitor the extreme right and left edges of the board are clipped, I cannot tell if the same 'jump' applies at those nodes.

      I still cannot find any issue that relates to the Font directly.
      Rod
      I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

      Comment


      • #4
        Because I was suffering another night of insomnia, I thought I'd pass the time on something that was curious, as opposed to laying in bed with my agnosticism and dyslexia, wondering if there was a dog.

        I changed this:
        BoardSize# = ScreenHeight& / 2 * .8
        to this:
        BoardSize# = ScreenHeight& / 2 * .6
        and lo and behold, I got the complete board showing on my portrait monitor, but still with the features mentioned in post 2 and 3 above.
        I gleaned one other tidbit of information- that is that at 0/360 degrees, 90 degrees, 180 degrees, and 270 degrees, the number jumped, on the top, up; on the right, to the right; on the bottom, down; and on the left, to the left. Again about 1/8 the font height.

        But I didn't solve anything.
        So I watched the board spin a few times, and I realized that the weird events begin happening between 1.25 and 1.5 revolutions.
        So I looked at the following sub calls and appropriate sub:
        Code:
        CALL GetBoardLayout   (BoardCenterx#, BoardCentery#, BoardSize#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), WedgeValue&(), Fontx#(), Fonty#(), FontSize#)
        CALL DrawBoard        (BoardCenterx#, BoardCentery#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), BoardColor&(), BackGroundColor&)
        CALL DrawBoardNumbers (BoardAngle#, BoardFontColor&, FontSize#, Fontx#(), Fonty#(), WedgeValue&())
        I should state that only the numbers that were supposed to be upright were the only numbers that inverted. The already inverted numbers stayed that way. But they began to maintain a lilt to the left of a few degrees, <25, and held that angle completely around the circle as they continue to spin about in a circle that was not concentric with the board.
        I commented out the second of the three above CALLs and ran the program and the same thing occurred but without the board being drawn, as I expected. I also expected that the numbers would begin their unplanned for behaviour at the same time. And sure enough they did, but with an added flair. The numbers were now tilted to the right. Therefore, there is some element of the problem within that second CALL.
        Further analysis tells me that the problem is most likely in the following part of the third SUB: the one and only FOR/NEXT loop.
        Yet everything looks to be in order.
        I emphasize 'looks' because the looks are deceiving.(It doesn't work as planned.)
        I believe if you were to add the following line as the second line of the program
        #DIM ALL
        you might trace the problem to a reliance on a variable in one of the SUBs that you have used as if it were passed when it was not or like it was a STATIC when it was not.

        You have done some real nice work here, and I cannot believe that it is the fault of the FONT statements when the severity or features of the problem change from SUB to SUB. Definitely not the off centre characteristic.

        I hope my insomnia has helped!
        Last edited by Rodney Hicks; 3 Jun 2009, 07:51 AM.
        Rod
        I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

        Comment


        • #5
          I was in error. You do have the proper FONT END commands.
          Last edited by Chris Boss; 3 Jun 2009, 07:41 PM.
          Chris Boss
          Computer Workshop
          Developer of "EZGUI"
          http://cwsof.com
          http://twitter.com/EZGUIProGuy

          Comment


          • #6
            FONT END

            ...
            If the specified font is still in use by a Graphic Window or an XPrint page, an error 5 (Illegal Function Call) will be generated
            See if this is happening. In your code you seem to have a FONT END paired with every FONT NEW, but I can't really tell from the doc what it means, "still in use."
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              May be a less demanding approach to get the same effect is to draw a bitmap, and then rotate it. Recently, several routines to rotate bitmaps were posted.

              Comment


              • #8
                Originally posted by Michael Mattias View Post
                See if this is happening. In your code you seem to have a FONT END paired with every FONT NEW, but I can't really tell from the doc what it means, "still in use."
                #Debug Display On does reveal "error 5 (Illegal Function Call) "..

                As it stands, the fonts are not being destroyed. You'll need something like..
                Code:
                        GRAPHIC SET FONT AnotherFont&
                        FONT END BoardFont&
                The program is a lot happier with that mod
                Rgds, Dave

                Comment


                • #9
                  " A font is considered 'in use' until either another GRAPHIC SET FONT statement is executed with a different font number against all windows or controls which had the font set to the font to be ended, or or all such graphic windows or graphic controls have been destroyed."

                  I have no idea if that is absolutely correct, but it sure seems as though an edited-for-correctness-by-someone-who-actually-knows version of same should be in the documentation under FONT END.

                  MCM
                  Michael Mattias
                  Tal Systems Inc. (retired)
                  Racine WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    First of all, a big thank you to all that have looked into this issue.

                    Rodney:

                    Yes, those are the issues I am experiencing. I'm not getting any error messages, just fonts that stop rotating and move out of place.
                    They look off center and ill spaced because the fonts are rotated from the upper left corner, and are positioned accordingly. So when they are not rotated correctly, they can be quite a ways out of position.

                    The issue of the Fonts jumping off center at even intervals of 90 degrees is an issue with the way the fonts are rotated. I don't know why the font rotation is handled that way, but I can compensate for it with some IF THEN checking for even multiples of 90 degrees and then pull them back a bit to make them line up correctly. Its an inconvenient workaround, but as it stands now, its all I can do.
                    The issue with the portrait mode monitor is because I ASSUMED a landscape mode monitor is in use (see what I get!). I can add a check for which is greater between Width and Height, and adjust to the lesser one. PAINT doesn't work from outside a window, so I have to avoid having the board go past the edge of the window.

                    The fact that it works correctly for a bit before suddenly acting strangely still suggests to me to be some kind of memory related thing, possibly, as others have pointed out, that the fonts are not being destroyed, and too many are being created at once. I'll keep digging.
                    I really appreciate the effort you put into looking into this, thank you very much.

                    Chris:

                    I THOUGHT I was destroying the fonts as I was done with them, but apparently they are not being destroyed for some reason. I will have to do some more experimentation to see what works.

                    Michael:

                    I think you're on to something, as it does seem to be related to the fonts not being destroyed.

                    Manuel:

                    I actually thought about that, but I'm curious now to see if I can get this to work, as it seems that it shouldn't be that difficult.

                    Dave:

                    Does that work? Strange that it doesn't generate any error messages about that. I guess there's something I'm not understanding about how to properly destroy fonts. It looks like I'll have to do a bit of juggling with the fonts to get rid of the ones I don't need any more before creating any new ones. I'll experiment with that and see where it leads. Thank you.


                    Thanks to all who have helped me with this.

                    Comment


                    • #11
                      It seems to me that this only uses 360 different GRAPHIC SET FONT statements per revolution, so why not
                      BoardFont&(BoardAngle#), this way the fonts need only be created once. This would mean that the font would not have to be destroyed to use the next one and might prove Dave's and Michael's point.
                      They look off center and ill spaced because the fonts are rotated from the upper left corner, and are positioned accordingly. So when they are not rotated correctly, they can be quite a ways out of position.
                      I think that if this is true, and if the left hand side is being 'rotated' out of the board, then the right hand side would be 'rotated' further in onto the board and this is not the case. The top left always being the top left following the circle.
                      A fixed width font may clarify that though.
                      You could check the value of BoardFont& to see if it failed to be created:
                      If the font creation fails, the value zero (0) is assigned to fhndl
                      Last edited by Rodney Hicks; 3 Jun 2009, 03:07 PM.
                      Rod
                      I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                      Comment


                      • #12
                        I compiled and ran your snippet (pretty cool graphics there, buddy) on three different computers, three different graphics adaptors and three different operating systems (7RC, xp/home and win98/r2).

                        Ran okay on all three except for the win/98 machine. The numbers didn't jump at the 6 and 12 o'clock positions on that one.
                        There are no atheists in a fox hole or the morning of a math test.
                        If my flag offends you, I'll help you pack.

                        Comment


                        • #13
                          Dave:

                          Does that work? Strange that it doesn't generate any error messages about that.
                          Yes it worked when I tried it. I Created another Font (AnotherFont&) outside of the loops in the two subs and used as shown.

                          Actually if you add #DEBUG DISPLAY ON to the top of your code. Or if you include an error trap in your subs you will see that Error 5 - Illegal function call is being generated when you call FONT END (so that's failing to {properly?} destroy the fonts).

                          Very interesting graphics BTW
                          Rgds, Dave

                          Comment


                          • #14
                            Yes, the problem is that GRAPHIC DETACH is never called, so the font selected into the graphic window (GRAPHIC SET FONT) can not be freed until after another call to GRAPHIC SET FONT.

                            You have to use the compiler directive:

                            #DEBUG DISPLAY ON

                            to see the error #5 generated by this. If you don't you don't realize this error is occuring.

                            The solution is simple.

                            Create a single default font for the graphic window and stores its handle in a global variable. Then when ever you want to free any font which was already used in GRAPHIC SET FONT, simply call GRAPHIC SET FONT again but with the default font handle instead. Then free the other font with FONT END.

                            Here is a PBWin 9.0 version:

                            Code:
                            #DEBUG ERROR ON
                            #DEBUG DISPLAY ON
                            #COMPILE EXE
                            '
                            GLOBAL MainFont&
                            '
                            FUNCTION PBMAIN () AS LONG
                                DESKTOP GET CLIENT TO ScreenWidth&, ScreenHeight&
                                GRAPHIC WINDOW "DartBoard - Click me to close.", 0, 0, ScreenWidth&, ScreenHeight& TO MyWindow???
                                GRAPHIC ATTACH MyWindow???, 0, REDRAW
                                ' ----------------------------------------
                                FONT NEW "Arial", 10,0,1,16, 0 TO MainFont&
                                ' ----------------------------------------
                                DIM RingRadius#(7), BoardColor&(102), RingNumber&(102), WedgeValue&(102), FillPointx#(102), FillPointy#(102), Fontx#(20), Fonty#(20)
                                Radian#  = .017453293
                                MinBoardSize# = 100
                                MaxBoardSize# = ScreenHeight& * .9
                            
                                FOR Wedge& = 1 TO 20
                                    BoardColor&(Wedge&) = RGB(Wedge&, Wedge&, Wedge&)
                                    RingNumber&(Wedge&) = 1
                                    WedgeValue&(Wedge&) = VAL(READ$(Wedge&))
                                NEXT Wedge&
                                FOR Wedge& = 0 TO 9
                                    BoardColor&(Wedge& * 2 + 21) = RGB(240 - Wedge&, 0, 0)
                                    BoardColor&(Wedge& * 2 + 22) = RGB(0, 140 - Wedge&, 0)
                                    RingNumber&(Wedge& * 2 + 21) = 2
                                    RingNumber&(Wedge& * 2 + 22) = 2
                                    WedgeValue&(Wedge& * 2 + 21) = VAL(READ$(Wedge& * 2 + 1))
                                    WedgeValue&(Wedge& * 2 + 22) = VAL(READ$(Wedge& * 2 + 2))
                                    BoardColor&(Wedge& * 2 + 41) = RGB(Wedge& + 21, Wedge& + 21, Wedge& + 21)
                                    BoardColor&(Wedge& * 2 + 42) = RGB(230 - Wedge&, 230 - Wedge&, 200 - Wedge&)
                                    RingNumber&(Wedge& * 2 + 41) = 3
                                    RingNumber&(Wedge& * 2 + 42) = 3
                                    WedgeValue&(Wedge& * 2 + 41) = VAL(READ$(Wedge& * 2 + 1))
                                    WedgeValue&(Wedge& * 2 + 42) = VAL(READ$(Wedge& * 2 + 2))
                                    BoardColor&(Wedge& * 2 + 61) = RGB(230 - Wedge&, 0, 0)
                                    BoardColor&(Wedge& * 2 + 62) = RGB(0, 130 - Wedge&, 0)
                                    RingNumber&(Wedge& * 2 + 61) = 4
                                    RingNumber&(Wedge& * 2 + 62) = 4
                                    WedgeValue&(Wedge& * 2 + 61) = VAL(READ$(Wedge& * 2 + 1))
                                    WedgeValue&(Wedge& * 2 + 62) = VAL(READ$(Wedge& * 2 + 2))
                                    BoardColor&(Wedge& * 2 + 81) = RGB(Wedge& + 31, Wedge& + 31, Wedge& + 31)
                                    BoardColor&(Wedge& * 2 + 82) = RGB(220 - Wedge&, 220 - Wedge&, 190 - Wedge&)
                                    RingNumber&(Wedge& * 2 + 81) = 5
                                    RingNumber&(Wedge& * 2 + 82) = 5
                                    WedgeValue&(Wedge& * 2 + 81) = VAL(READ$(Wedge& * 2 + 1))
                                    WedgeValue&(Wedge& * 2 + 82) = VAL(READ$(Wedge& * 2 + 2))
                                NEXT
                                BoardColor&(101) = RGB(0, 120, 0)
                                BoardColor&(102) = RGB(220, 0, 0)
                                RingNumber&(101) = 6
                                RingNumber&(102) = 7
                                WedgeValue&(101) = 100
                                WedgeValue&(102) = 200
                             
                                ForeGroundColor& = RGB(255, 255, 255)
                                BackGroundColor& = RGB(0, 0, 255)
                                BoardFontColor&  = RGB(255, 255, 255)
                                BoardCenterx# = ScreenWidth&  / 2
                                BoardCentery# = ScreenHeight& / 2
                                BoardSize#    = ScreenHeight& / 2 * .8
                                BoardAngle# = 0
                                SpinRate#   = 1
                                CT!=TIMER
                                DO
                                    GRAPHIC COLOR ForeGroundColor&, BackGroundColor&
                                    GRAPHIC CLEAR
                                    CALL GetBoardLayout   (BoardCenterx#, BoardCentery#, BoardSize#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), WedgeValue&(), Fontx#(), Fonty#(), FontSize#)
                                    CALL DrawBoard        (BoardCenterx#, BoardCentery#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), BoardColor&(), BackGroundColor&)
                                    CALL DrawBoardNumbers (BoardAngle#, BoardFontColor&, FontSize#, Fontx#(), Fonty#(), WedgeValue&())
                            
                                    GRAPHIC REDRAW
                                    BoardAngle# = BoardAngle# + SpinRate#
                                    IF BoardAngle# = 360 THEN BoardAngle# = BoardAngle# - 360
                                    DIALOG DOEVENTS
                                    GRAPHIC WINDOW CLICK MyWindow??? TO IsClick&, X&,Y&
                                    IF IsClick&<>0 THEN EXIT DO
                                    GRAPHIC GET CLIENT TO W&, H&    ' test to see if window still exists
                                    IF W&=0 AND H&=0 THEN
                                          EXIT DO
                                    END IF
                                LOOP
                                GRAPHIC WINDOW END
                            DATA 20, 1, 18, 4, 13, 6, 10, 15, 2, 17, 3, 19, 7, 16, 8, 11, 14, 9, 12, 5
                            END FUNCTION
                             
                             
                             
                            
                            SUB GetBoardLayout (BoardCenterx#, BoardCentery#, BoardSize#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), WedgeValue&(), Fontx#(), Fonty#(), FontSize#)
                                Radian# = .017453293
                                RingRadius#(1) = BoardSize#
                                RingRadius#(2) = BoardSize# * .76
                                RingRadius#(3) = BoardSize# * .72
                                RingRadius#(4) = BoardSize# * .48
                                RingRadius#(5) = BoardSize# * .44
                                RingRadius#(6) = BoardSize# * .07
                                RingRadius#(7) = BoardSize# * .03
                                FOR Ring& = 0 TO 4
                                    FOR Wedge& = 1 TO 20
                                        FillPointx#(Ring& * 20 + Wedge&) = BoardCenterx# + (RingRadius#(Ring& + 1) - 2) * SIN(((Wedge& - 1) * 18 + BoardAngle#) * Radian#)
                                        FillPointy#(Ring& * 20 + Wedge&) = BoardCentery# - (RingRadius#(Ring& + 1) - 2) * COS(((Wedge& - 1) * 18 + BoardAngle#) * Radian#)
                                    NEXT
                                NEXT
                                FillPointx#(101) = BoardCenterx#
                                FillPointy#(101) = BoardCentery# - (RingRadius#(6) - 2) * COS(0 * Radian#)
                                FillPointx#(102) = BoardCenterx#
                                FillPointy#(102) = BoardCentery#
                                FontName$   = ""  'Use Current
                                FontSize#   = BoardSize# * .09                                          'Adjust font size according to board size
                                FontStyle&  = 0   'Normal
                                FontSet&    = 1   'Default
                                FontFamily& = 16  'Roman
                                FontAngle&  = 0
                                FONT NEW FontName$, FontSize#, FontStyle&, FontSet&, FontFamily&, FontAngle& TO BoardFont&
                                GRAPHIC SET FONT BoardFont&
                                FOR Wedge& = 1 TO 20
                                    GRAPHIC TEXT SIZE LTRIM$(STR$(WedgeValue&(Wedge&))) TO TextWidth#, TextHeight#
                                    TextRadius#  = RingRadius#(1) * 1.015                               'Move text up a bit to adjust for space above fonts
                                    CenterAngle# = (Wedge& - 1) * 18 * Radian#
                                    TextOffset#  = ATN(TextWidth# * .75 / TextRadius#)                  'Center text according to text width plus leading space
                                    Fontx#(Wedge&) = BoardCenterx# + TextRadius# * SIN(CenterAngle# - TextOffset# + BoardAngle# * Radian#)
                                    Fonty#(Wedge&) = BoardCentery# - TextRadius# * COS(CenterAngle# - TextOffset# + BoardAngle# * Radian#)
                                NEXT
                                ' ----------------------------------------
                                GRAPHIC SET FONT MainFont&
                                ' ----------------------------------------
                                FONT END BoardFont&
                            END SUB
                            
                            SUB DrawBoard (BoardCenterx#, BoardCentery#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), BoardColor&(), BackGroundColor&)
                                Radian# = .017453293
                                FOR Angle# = 0 TO 360 STEP .1
                                    FOR Radii# = 1 TO 7
                                        x# = BoardCenterx# + RingRadius#(Radii#) * SIN(Angle# * Radian#)
                                        y# = BoardCentery# - RingRadius#(Radii#) * COS(Angle# * Radian#)
                                        IF Radii# = 1 THEN
                                            RingColor& = RGB(255, 255, 255)
                                        ELSE
                                            RingColor& = RGB(150, 150, 150)
                                        END IF
                                        GRAPHIC SET PIXEL (x#, y#), RingColor&
                                    NEXT Radii#
                                NEXT
                                FOR Angle# = BoardAngle# + 9 TO BoardAngle# + 351 STEP 18
                                    x1# = BoardCenterx# + RingRadius#(6) * SIN(Angle# * Radian#)
                                    y1# = BoardCentery# - RingRadius#(6) * COS(Angle# * Radian#)
                                    x2# = BoardCenterx# + RingRadius#(1) * SIN(Angle# * Radian#)
                                    y2# = BoardCentery# - RingRadius#(1) * COS(Angle# * Radian#)
                                    GRAPHIC LINE (x1#, y1#) - (x2#, y2#), RGB(150, 150, 150)
                                NEXT
                                FOR Wedge& = 1 TO 102
                                    GRAPHIC PAINT REPLACE (FillPointx#(Wedge&), FillPointy#(Wedge&)), BoardColor&(Wedge&), BackGroundColor&
                                NEXT
                            END SUB
                            
                            SUB DrawBoardNumbers (BoardAngle#, FontColor&, FontSize#, Fontx#(), Fonty#(), WedgeValue&())
                                FontName$   = ""  'Use Current
                                FontStyle&  = 0   'Normal
                                FontSet&    = 1   'Default
                                FontFamily& = 16  'Roman
                                GRAPHIC COLOR FontColor&, -2
                                FOR Wedge& = 1 TO 20
                                    FontAngle& = (360 - BoardAngle# - (Wedge& - 1) * 18) * 10
                                    FONT NEW  FontName$, FontSize#, FontStyle&, FontSet&, FontFamily&, FontAngle& TO BoardFont&
                                    GRAPHIC SET FONT BoardFont&
                                    GRAPHIC SET POS (Fontx#(Wedge&), Fonty#(Wedge&))
                                    GRAPHIC PRINT WedgeValue&(Wedge&)
                                    ' ----------------------------------------
                                    GRAPHIC SET FONT MainFont&
                                    ' ----------------------------------------
                                    FONT END BoardFont&
                                NEXT
                            END SUB
                            Chris Boss
                            Computer Workshop
                            Developer of "EZGUI"
                            http://cwsof.com
                            http://twitter.com/EZGUIProGuy

                            Comment


                            • #15
                              Well, I copied Dave's and Chris's method, and that did the trick, and I now have a better understanding of how to manipulate fonts.
                              I think the help file should say that you can't delete the currently active font, instead of saying you can't delete it if its currently in use. Currently in use is too vague, imo, and had me confused. Maybe even add Chris's example for clarity, as this seems a confusing issue (but maybe its just me).

                              Thanks very much for all the help, it is very much appreciated. Now I can move on, but here is the current working code, with the 90 degree font offset issue fixed, portrait mode issue fixed, and scaling added:

                              Code:
                              #COMPILE EXE
                              
                              GLOBAL MainFont&
                              
                              
                              FUNCTION PBMAIN () AS LONG
                                  CONSOLE SET LOC -10000, -10000
                                  DESKTOP GET CLIENT TO ScreenWidth&, ScreenHeight&
                                  GRAPHIC WINDOW "DartBoard", 0, 0, ScreenWidth&, ScreenHeight& TO MyWindow???
                                  GRAPHIC ATTACH MyWindow???, 0, REDRAW
                              
                                  FONT NEW "" TO MainFont&                                                'Global font to switch to when other fonts need to be deleted. Can't delete the active font.
                              
                                  DIM RingRadius#(7), BoardColor&(102), RingNumber&(102), WedgeValue&(102), FillPointx#(102), FillPointy#(102), Fontx#(20), Fonty#(20)
                                  Radian#  = .017453293
                              
                              
                                  FOR Wedge& = 1 TO 20
                                      BoardColor&(Wedge&) = RGB(Wedge&, Wedge&, Wedge&)
                                      RingNumber&(Wedge&) = 1
                                      WedgeValue&(Wedge&) = VAL(READ$(Wedge&))
                                  NEXT Wedge&
                              
                                  FOR Wedge& = 0 TO 9
                                      BoardColor&(Wedge& * 2 + 21) = RGB(240 - Wedge&, 0, 0)
                                      BoardColor&(Wedge& * 2 + 22) = RGB(0, 140 - Wedge&, 0)
                                      RingNumber&(Wedge& * 2 + 21) = 2
                                      RingNumber&(Wedge& * 2 + 22) = 2
                                      WedgeValue&(Wedge& * 2 + 21) = VAL(READ$(Wedge& * 2 + 1))
                                      WedgeValue&(Wedge& * 2 + 22) = VAL(READ$(Wedge& * 2 + 2))
                              
                                      BoardColor&(Wedge& * 2 + 41) = RGB(Wedge& + 21, Wedge& + 21, Wedge& + 21)
                                      BoardColor&(Wedge& * 2 + 42) = RGB(230 - Wedge&, 230 - Wedge&, 200 - Wedge&)
                                      RingNumber&(Wedge& * 2 + 41) = 3
                                      RingNumber&(Wedge& * 2 + 42) = 3
                                      WedgeValue&(Wedge& * 2 + 41) = VAL(READ$(Wedge& * 2 + 1))
                                      WedgeValue&(Wedge& * 2 + 42) = VAL(READ$(Wedge& * 2 + 2))
                              
                                      BoardColor&(Wedge& * 2 + 61) = RGB(230 - Wedge&, 0, 0)
                                      BoardColor&(Wedge& * 2 + 62) = RGB(0, 130 - Wedge&, 0)
                                      RingNumber&(Wedge& * 2 + 61) = 4
                                      RingNumber&(Wedge& * 2 + 62) = 4
                                      WedgeValue&(Wedge& * 2 + 61) = VAL(READ$(Wedge& * 2 + 1))
                                      WedgeValue&(Wedge& * 2 + 62) = VAL(READ$(Wedge& * 2 + 2))
                              
                                      BoardColor&(Wedge& * 2 + 81) = RGB(Wedge& + 31, Wedge& + 31, Wedge& + 31)
                                      BoardColor&(Wedge& * 2 + 82) = RGB(220 - Wedge&, 220 - Wedge&, 190 - Wedge&)
                                      RingNumber&(Wedge& * 2 + 81) = 5
                                      RingNumber&(Wedge& * 2 + 82) = 5
                                      WedgeValue&(Wedge& * 2 + 81) = VAL(READ$(Wedge& * 2 + 1))
                                      WedgeValue&(Wedge& * 2 + 82) = VAL(READ$(Wedge& * 2 + 2))
                                  NEXT
                                  BoardColor&(101) = RGB(0, 120, 0)
                                  BoardColor&(102) = RGB(220, 0, 0)
                                  RingNumber&(101) = 6
                                  RingNumber&(102) = 7
                                  WedgeValue&(101) = 100
                                  WedgeValue&(102) = 200
                              
                              
                              
                                  ForeGroundColor& = RGB(255, 255, 255)
                                  BackGroundColor& = RGB(0, 0, 255)
                                  BoardFontColor&  = RGB(255, 255, 255)
                              
                                  BoardCenterx# = ScreenWidth&  / 2
                                  BoardCentery# = ScreenHeight& / 2
                                  
                                  IF ScreenWidth& < ScreenHeight& THEN
                                      BoardSize# = ScreenWidth&  / 2 * .8
                                      MaxBoardSize# = ScreenWidth& / 2 * .9
                                  ELSE
                                      BoardSize# = ScreenHeight& / 2 * .8
                                      MaxBoardSize# = ScreenHeight& / 2 * .9
                                  END IF
                                  MinBoardSize# = 100
                              
                                  ResizeRate# = 2
                                  BoardAngle# = 0
                                  SpinRate#   = 1
                                  
                              
                              
                                  DO
                              
                                      GRAPHIC COLOR ForeGroundColor&, BackGroundColor&
                                      GRAPHIC CLEAR
                              
                                      CALL GetBoardLayout   (BoardCenterx#, BoardCentery#, BoardSize#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), WedgeValue&(), Fontx#(), Fonty#(), FontSize#)
                                      CALL DrawBoard        (BoardCenterx#, BoardCentery#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), BoardColor&(), BackGroundColor&)
                                      CALL DrawBoardNumbers (BoardAngle#, BoardFontColor&, FontSize#, Fontx#(), Fonty#(), WedgeValue&())
                              
                                      GRAPHIC REDRAW
                                      
                              
                                      IF BoardSize# + ResizeRate# =< MinBoardSize# OR BoardSize# + ResizeRate# => MaxBoardSize# THEN
                                          ResizeRate# = -ResizeRate#
                                      END IF
                                      
                                      BoardSize# = BoardSize# + ResizeRate#
                              
                                      BoardAngle# = BoardAngle# + SpinRate#
                                      IF BoardAngle# => 360 THEN BoardAngle# = BoardAngle# - 360
                              
                              
                              
                                      GRAPHIC INKEY$ TO test$
                              
                                  LOOP UNTIL test$ <> ""
                              
                              
                              
                              
                              
                              DATA 20, 1, 18, 4, 13, 6, 10, 15, 2, 17, 3, 19, 7, 16, 8, 11, 14, 9, 12, 5
                              
                              END FUNCTION
                              
                              
                              
                              
                              
                              
                              
                              
                              SUB GetBoardLayout (BoardCenterx#, BoardCentery#, BoardSize#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), WedgeValue&(), Fontx#(), Fonty#(), FontSize#)
                                  Radian# = .017453293
                                  RingRadius#(1) = BoardSize#
                                  RingRadius#(2) = BoardSize# * .76
                                  RingRadius#(3) = BoardSize# * .72
                                  RingRadius#(4) = BoardSize# * .48
                                  RingRadius#(5) = BoardSize# * .44
                                  RingRadius#(6) = BoardSize# * .07
                                  RingRadius#(7) = BoardSize# * .03
                              
                                  FOR Ring& = 0 TO 4
                                      FOR Wedge& = 1 TO 20
                                          FillPointx#(Ring& * 20 + Wedge&) = BoardCenterx# + (RingRadius#(Ring& + 1) - 2) * SIN(((Wedge& - 1) * 18 + BoardAngle#) * Radian#)
                                          FillPointy#(Ring& * 20 + Wedge&) = BoardCentery# - (RingRadius#(Ring& + 1) - 2) * COS(((Wedge& - 1) * 18 + BoardAngle#) * Radian#)
                                      NEXT
                                  NEXT
                              
                                  FillPointx#(101) = BoardCenterx#
                                  FillPointy#(101) = BoardCentery# - (RingRadius#(6) - 2)
                                  FillPointx#(102) = BoardCenterx#
                                  FillPointy#(102) = BoardCentery#
                              
                                  FontName$   = ""  'Use Current
                                  FontSize#   = BoardSize# * .09                                          'Adjust font size according to board size
                                  FontStyle&  = 0   'Normal
                                  FontSet&    = 1   'Default
                                  FontFamily& = 16  'Roman
                                  FontAngle&  = 0
                              
                                  FONT NEW FontName$, FontSize#, FontStyle&, FontSet&, FontFamily&, FontAngle& TO BoardFont&
                                  GRAPHIC SET FONT BoardFont&
                              
                                  FOR Wedge& = 1 TO 20
                                      GRAPHIC TEXT SIZE LTRIM$(STR$(WedgeValue&(Wedge&))) TO TextWidth#, TextHeight#
                                      CenterAngle# = (Wedge& - 1) * 18 * Radian#
                                      IF ((Wedge& - 1) * 18 + BoardAngle#) MOD 90 = 0 THEN
                                          TextRadius#  = RingRadius#(1) * .995                            'Compensate for irregular 90 degree font positioning
                                      ELSE
                                          TextRadius#  = RingRadius#(1) * 1.015                           'Move text up a bit to adjust for space above fonts
                                      END IF
                                      TextOffset#  = ATN(TextWidth# * .75 / TextRadius#)                  'Center text according to text width plus leading space
                              
                                      Fontx#(Wedge&) = BoardCenterx# + TextRadius# * SIN(CenterAngle# - TextOffset# + BoardAngle# * Radian#)
                                      Fonty#(Wedge&) = BoardCentery# - TextRadius# * COS(CenterAngle# - TextOffset# + BoardAngle# * Radian#)
                                  NEXT
                              
                                  GRAPHIC SET FONT MainFont&
                                  FONT END BoardFont&
                              END SUB
                              
                              
                              SUB DrawBoard (BoardCenterx#, BoardCentery#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), BoardColor&(), BackGroundColor&)
                                  Radian# = .017453293
                                  FOR Angle# = 0 TO 360 STEP .1
                                      FOR Radii# = 1 TO 7
                                          x# = BoardCenterx# + RingRadius#(Radii#) * SIN(Angle# * Radian#)
                                          y# = BoardCentery# - RingRadius#(Radii#) * COS(Angle# * Radian#)
                              
                                          IF Radii# = 1 THEN
                                              RingColor& = RGB(255, 255, 255)
                                          ELSE
                                              RingColor& = RGB(150, 150, 150)
                                          END IF
                              
                                          GRAPHIC SET PIXEL (x#, y#), RingColor&
                                      NEXT Radii#
                                  NEXT
                              
                                  FOR Angle# = BoardAngle# + 9 TO BoardAngle# + 351 STEP 18
                                      x1# = BoardCenterx# + RingRadius#(6) * SIN(Angle# * Radian#)
                                      y1# = BoardCentery# - RingRadius#(6) * COS(Angle# * Radian#)
                                      x2# = BoardCenterx# + RingRadius#(1) * SIN(Angle# * Radian#)
                                      y2# = BoardCentery# - RingRadius#(1) * COS(Angle# * Radian#)
                                      GRAPHIC LINE (x1#, y1#) - (x2#, y2#), RGB(150, 150, 150)
                                  NEXT
                              
                                  FOR Wedge& = 1 TO 102
                                      GRAPHIC PAINT REPLACE (FillPointx#(Wedge&), FillPointy#(Wedge&)), BoardColor&(Wedge&), BackGroundColor&
                                  NEXT
                              END SUB
                              
                              
                              SUB DrawBoardNumbers (BoardAngle#, FontColor&, FontSize#, Fontx#(), Fonty#(), WedgeValue&())
                                  FontName$   = ""  'Use Current
                                  FontStyle&  = 0   'Normal
                                  FontSet&    = 1   'Default
                                  FontFamily& = 16  'Roman
                              
                                  GRAPHIC COLOR FontColor&, -2
                              
                                  FOR Wedge& = 1 TO 20
                                      FontAngle& = (360 - BoardAngle# - (Wedge& - 1) * 18) * 10
                                      FONT NEW  FontName$, FontSize#, FontStyle&, FontSet&, FontFamily&, FontAngle& TO BoardFont&
                                      GRAPHIC SET FONT BoardFont&
                                      GRAPHIC SET POS (Fontx#(Wedge&), Fonty#(Wedge&))
                                      GRAPHIC PRINT WedgeValue&(Wedge&);
                                      GRAPHIC SET FONT MainFont&
                                      FONT END BoardFont&
                                  NEXT
                              END SUB
                              Last edited by G Grant; 4 Jun 2009, 01:48 PM. Reason: Fixed garbled text due to upload error.

                              Comment


                              • #16
                                Chris,
                                I ran your code in PBCC and got the following error:
                                PowerBASIC Console Compiler
                                PB/CC Version 5.00
                                Copyright (c) 1998-2008 PowerBasic Inc.
                                Venice, Florida USA
                                All Rights Reserved

                                Error 516 in C:\PBCC50\bin\darts.bas(76:009): DefType, Type id (?%&!#$), or AS... required: DIALOG
                                Line 76: DIALOG DOEVENTS
                                ==============================
                                Compile failed at 12:41:07 AM on 04/06/2009
                                Which makes sense because the program was written in PBCC but you have adjusted it in PBWIN.
                                So I commented out "DIALOG DOEVENTS" and away it went ran like a charm albeit with the sides clipped on my monitor(I made the correction as earlier).
                                Closing the window with the "X" in the sysmenu (top right) leaves the process running, whereas clicking on the window the program ends properly.
                                However, I think by now that the solution is obvious for the thread starter G Grant. And there is nothing wrong with the FONT family of statements.
                                Rod
                                I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                                Comment


                                • #17
                                  G. Grant
                                  I see we crossed posts.
                                  Line 90 of your post has some garbled code, the "BoardAngle#," has had the last four digits changed by posting.

                                  Once that's fixed, you have an impressive bit of graphics happening, the incoming/receding board is a nice touch. I realize that this is not your main work on this, it was just to show a problem but I do hope that you slow the spin rate down a little somehow. As it is, after about 4 revolutions I find myself unable to look at it because it's making me dizzy.

                                  Well done!!
                                  Rod
                                  I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                                  Comment


                                  • #18
                                    G.

                                    Really nice!
                                    Against my guessing, your code is more efficient in terms of CPU usage than rotating the bitmap, at least using the code posted by Paul Dixon on May 29th.
                                    I saved a square bitmap containig just the board, put it to rotate using Paul's code and compared the system performance. Your code uses some 2 points % less CPU than rotating bitmap.

                                    Regards,
                                    Last edited by Manuel Valdes; 4 Jun 2009, 07:35 PM.

                                    Comment


                                    • #19
                                      Ah, well that is a good indication of how well PowerBasic handles PAINTing an area of the screen, as that is the most time consuming part of the program.

                                      Here is an example of rotating and scaling a sphere without any PAINTing going on, to show the difference in speed.

                                      Use < and > to rotate left and right, and use + and - to increase and decrease the size of the sphere. ESC to quit.
                                      Its just a sample program to show how fast PowerBASIC graphics can be, even drawing one pixel at a time (which this program does).

                                      Code:
                                      #COMPILE EXE
                                      
                                      FUNCTION PBMAIN () AS LONG
                                      
                                          radian!    = .017453293
                                          radius!    = 200
                                          tilt!      = 0
                                          tiltspeed! = 0
                                      
                                      
                                          background??? = RGB(0, 0, 0)
                                          foreground??? = RGB(255, 255, 255)
                                      
                                          DESKTOP GET CLIENT TO w&, h&
                                          xcenter! = w& / 2
                                          ycenter! = h& / 2
                                      
                                          GRAPHIC WINDOW "", 0, 0, w&, h& TO MyWindow???
                                          GRAPHIC ATTACH MyWindow???, 0, REDRAW
                                          GRAPHIC COLOR foreground???, background???
                                      
                                      
                                          DO
                                              GRAPHIC CLEAR
                                              tilt! = tilt! + tiltspeed!
                                      
                                              IF tilt! < 0 THEN
                                                  tilt! = tilt! + 360
                                              ELSEIF tilt! => 360 THEN
                                                  tilt! = tilt! - 360
                                              END IF
                                      
                                              FOR xzangle! = 0 TO 90 STEP 5
                                                  FOR xyangle! = 0 TO 90 STEP .5
                                                      x! = xcenter! + radius! * SIN(xyangle! * radian!) * COS(xzangle! * radian!)
                                                      y! = ycenter! - radius! * COS(xyangle! * radian!)
                                      
                                                      hypotenuse! = SQR((x! - xcenter!) ^ 2 + (ycenter! - y!) ^ 2)
                                      
                                                      IF y! = ycenter! THEN
                                                          vertex! = 90  * radian!
                                                      ELSE
                                                          vertex! = ATN((x! - xcenter!) / (ycenter! - y!))                         'ATN returns angle in Radians
                                                      END IF
                                      
                                      
                                                      angle1! = vertex! + tilt! * radian!
                                                      angle2! = (180 + tilt!) * radian! - vertex!
                                                      angle3! = (180 + tilt!) * radian! + vertex!
                                                      angle4! = (360 + tilt!) * radian! - vertex!
                                      
                                                      x1! = xcenter! + hypotenuse! * SIN(angle1!)
                                                      y1! = ycenter! - hypotenuse! * COS(angle1!)
                                      
                                                      x2! = xcenter! + hypotenuse! * SIN(angle2!)
                                                      y2! = ycenter! - hypotenuse! * COS(angle2!)
                                      
                                                      x3! = xcenter! + hypotenuse! * SIN(angle3!)
                                                      y3! = ycenter! - hypotenuse! * COS(angle3!)
                                      
                                                      x4! = xcenter! + hypotenuse! * SIN(angle4!)
                                                      y4! = ycenter! - hypotenuse! * COS(angle4!)
                                      
                                                      x5! = xcenter! + hypotenuse! * COS(angle1!)
                                                      y5! = ycenter! + hypotenuse! * SIN(angle1!)
                                      
                                                      x6! = xcenter! + hypotenuse! * COS(angle2!)
                                                      y6! = ycenter! + hypotenuse! * SIN(angle2!)
                                      
                                                      x7! = xcenter! + hypotenuse! * COS(angle3!)
                                                      y7! = ycenter! + hypotenuse! * SIN(angle3!)
                                      
                                                      x8! = xcenter! + hypotenuse! * COS(angle4!)
                                                      y8! = ycenter! + hypotenuse! * SIN(angle4!)
                                      
                                                      GRAPHIC SET PIXEL (x1!, y1!), foreground???
                                                      GRAPHIC SET PIXEL (x2!, y2!), foreground???
                                                      GRAPHIC SET PIXEL (x3!, y3!), foreground???
                                                      GRAPHIC SET PIXEL (x4!, y4!), foreground???
                                      
                                                      GRAPHIC SET PIXEL (x5!, y5!), foreground???
                                                      GRAPHIC SET PIXEL (x6!, y6!), foreground???
                                                      GRAPHIC SET PIXEL (x7!, y7!), foreground???
                                                      GRAPHIC SET PIXEL (x8!, y8!), foreground???
                                      
                                                  NEXT
                                              NEXT
                                              GRAPHIC REDRAW
                                      
                                              GRAPHIC INKEY$ TO i$
                                      
                                              SELECT CASE i$
                                                  CASE CHR$(27)
                                                      END
                                                  CASE ",", "<"
                                                      IF tiltspeed! > -90 THEN tiltspeed! = tiltspeed! - .5
                                                  CASE ".", ">"
                                                      IF tiltspeed! <  90 THEN tiltspeed! = tiltspeed! + .5
                                                  CASE "-", "_"
                                                      IF radius! > 5     THEN radius! = radius! - 5
                                                  CASE "=", "+"
                                                      IF radius! < 10000 THEN radius! = radius! + 5
                                      
                                      
                                              END SELECT
                                      
                                          LOOP
                                      
                                      
                                      END FUNCTION

                                      Comment


                                      • #20
                                        The problem has more to do with the how you use GRAPHIC ATTACH and GRAPHIC DETACH.

                                        These two commands should be used in pairs !

                                        You created problems by calling GRAPHIC ATTACH and not DETACH after the draw cycle.

                                        This is basically similiar to working with the API and using a DC (which is what those PB commands do). The proper way to handle a DC is to open the DC, draw into and then immediately free it and always selecting the original attributes back into the DC before freeing it.

                                        With PB's Graphic commands you should treat GRAPHIC ATTACH and GRAPHIC DETACH in the same way.
                                        Chris Boss
                                        Computer Workshop
                                        Developer of "EZGUI"
                                        http://cwsof.com
                                        http://twitter.com/EZGUIProGuy

                                        Comment

                                        Working...
                                        X