Announcement

Collapse
No announcement yet.

Drawing a figure i PB for Windows

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

  • Drawing a figure i PB for Windows

    I wonder if you can draw the figure below with PB?
    With GRAPHIC ELLIPSE you can draw the circle, but have no idea how to draw the oblique rectangles.

    Click image for larger version

Name:	Ratten-Röd.bmp
Views:	1
Size:	23.6 KB
ID:	773565

    Attached Files
    Fim Wästberg

  • #2
    About the only way I can think of would be a series of Graphic PolyLine, Graphic Paint and Graphic Ellipse commands.

    Edit after thinking a bit more:
    :
    A series of Graphic Polygon and Graphic Ellipse would be better overlaying each other. Here's one of the diagonals as a sample.

    Click image for larger version  Name:	Diagonal.jpg Views:	1 Size:	8.5 KB ID:	773567

    Code:
    #COMPILE EXE
    #DIM ALL
    
    TYPE PolyPoints
     count AS LONG
     x1 AS SINGLE
     y1 AS SINGLE
     x2 AS SINGLE
     y2 AS SINGLE
     x3 AS SINGLE
     y3 AS SINGLE
     x4 AS SINGLE
     y4 AS SINGLE
     END TYPE
    FUNCTION PBMAIN () AS LONG
        LOCAL hWnd AS LONG
        LOCAL points AS polypoints
        points.count = 4
        points.x1 =  100
        points.y1 =  100
        points.x2 =  120
        points.y2 =  80
        points.x3 =  420
        points.y3 =  400
        points.x4 =  400
        points.y4 =  420
        GRAPHIC WINDOW NEW "Drawing", 100, 100, 600, 600 TO hWnd
        GRAPHIC POLYGON points,%RGB_BLUE,%RGB_BLUE
    
        ? ""
    
    END FUNCTION
    --
    [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
    PNG Domain Hosting[/URL]

    Comment


    • #3
      Stuart,
      Brilliant, thank you very much.
      /Fim W.
      Fim Wästberg

      Comment


      • #4
        Thinking about it. You would need:
        2 x Graphic Box followed by
        2 x Graphic Ellipse (one red and a smaller one white) followed by
        2 x Graphic Polygon
        --
        [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
        PNG Domain Hosting[/URL]

        Comment


        • #5
          You might be able to glean something from this, it's not well commented since I didn't think I'd be sharing it at the time I wrote it.
          One sample image, others available in the program.
          Code:
          #COMPILE EXE
          #DIM ALL
          '#DEBUG ERROR ON
          #INCLUDE ONCE "WIN32API.INC"
          
          %graphic      = 1000
          %addgraphic   = 1001
          %noncontrol   = 1002
          %rects        = 1003
          %finale       = 1004
          %clear2black  = 1005
          %more_rects   = 1006
          %ellipses     = 1007
          %clear2white  = 1008
          %IDCANCEL     = 2
          
          TYPE PolyPoint
           x AS SINGLE
           y AS SINGLE
          END TYPE
          
          TYPE polyrect
            count AS LONG
            xy(1 TO 4) AS PolyPoint
          END TYPE
          
          TYPE PolyArray
           count AS LONG
           xy(1 TO 1000) AS PolyPoint
          END TYPE
          
          TYPE polytriangle
           count AS LONG
           x1 AS SINGLE
           y1 AS SINGLE
           x2 AS SINGLE
           y2 AS SINGLE
           x3 AS SINGLE
           y3 AS SINGLE
          END TYPE
          
          FUNCTION PBMAIN () AS LONG
            LOCAL hDlg, hParent AS LONG
            LOCAL lRslt AS LONG
            DIALOG NEW hParent, "Rotary Graphics", 50, 50, 600, 400, %WS_POPUP OR %WS_BORDER _
              OR %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR _
              %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR _
              %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR _
              %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
            CONTROL ADD BUTTON, hDlg, %addgraphic, "Rotatable Bound Ellipse", 5, 380, 120, 15
            CONTROL ADD BUTTON, hDlg, %noncontrol, "Rotatable Centred Ellipse", 130, 380, 120, 15
            CONTROL ADD BUTTON, hDlg, %ellipses, "Ellipses at an Angle", 130, 360, 120, 15
            CONTROL ADD BUTTON, hDlg, %rects, "Rectangles/Squares at an Angle", 255, 360, 120, 15
            CONTROL ADD BUTTON, hDlg, %more_rects, "Rotating Rectangles/Squares", 255, 380, 120, 15
            CONTROL ADD BUTTON, hDlg, %finale, "Rotating Triangles", 380, 380, 120, 15
            CONTROL ADD BUTTON, hDlg, %clear2black, "Clear to Black", 380, 360, 120, 15
            CONTROL ADD BUTTON, hDlg, %clear2white, "Arrows Rotate at Centre", 5, 360, 120, 15
            CONTROL ADD BUTTON, hDlg, %IDCANCEL, "Exit", 505, 380, 50, 15
            CONTROL ADD GRAPHIC, hDlg, %graphic, "", 5,5,590,350
          
          
            DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
            FUNCTION = lRslt
          END FUNCTION
          
          CALLBACK FUNCTION ShowDIALOG1Proc()
          LOCAL start AS POINT
          LOCAL angle, rat, angletri AS DOUBLE
          LOCAL r, b, g, edge, stp, hop AS LONG
          STATIC isbounding, keepit,flag,hh, bwtgl, arrowtoggle AS LONG
            SELECT CASE AS LONG CB.MSG
              CASE %WM_INITDIALOG
          
              CASE %WM_COMMAND
                SELECT CASE AS LONG CB.CTL
                  CASE %addgraphic
                    IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                      IF ISTRUE isbounding THEN
                        CONTROL KILL CB.HNDL, %graphic
                        SLEEP 1
                        isbounding= 0
                      ELSEIF ISFALSE isbounding THEN
                        isbounding = 1
                        CONTROL KILL CB.HNDL, %graphic
                        SLEEP 1
                      END IF
          
                      IF keepit= 9 THEN
                        keepit=0
                      END IF
                      SELECT CASE keepit MOD 9
                        CASE 0
                          start.x=100
                          start.y=150
                          angle=222
                          br_nidus_ellipse CB.HNDL, %graphic, start.x-100, start.y-100, 200, 200, angle, 7, %BLACK, %RGB_CORAL, %RED
                        CASE 1
                          start.x=100
                          start.y=200
                          angle=33
                          br_nidus_ellipse CB.HNDL, %graphic, start.x-100, start.y-100, 200, 200, angle, 4, %BLACK, %RGB_CORAL, %GRAY
                        CASE 2
                          start.x=100
                          start.y=250
                          angle=160
                          br_nidus_ellipse CB.HNDL, %graphic, start.x-100, start.y-100, 200, 200, angle, 9, %BLACK, %RGB_CORAL, %BLUE
                        CASE 3
                          start.x=300
                          start.y=100
                          angle=333
                          br_nidus_ellipse CB.HNDL, %graphic, start.x-100, start.y-100, 200, 200, angle, 100, %BLACK, %BLUE, %GRAY
                        CASE 4
                          start.x=100
                          start.y=250
                          angle=75
                          br_nidus_ellipse CB.HNDL, %graphic, start.x-100, start.y-100, 200, 200, angle, 6, %BLACK, %RGB_CORAL, %MAGENTA
                        CASE 5
                          start.x=500
                          start.y=250
                          angle=270
                          br_nidus_ellipse CB.HNDL, %graphic, start.x-100, start.y-100, 200, 200, angle, 40, %MAGENTA, %GREEN, %BLACK
                          CONTROL REDRAW CB.HNDL, %graphic
                        CASE 6
                          start.x=200
                          start.y=200
                          angle=310
                          br_nidus_ellipse CB.HNDL, %graphic, start.x-100, start.y-150, 200, 300, angle, 5, %MAGENTA, %RGB_CORAL, %BLUE
                        CASE 7
                          start.x=400
                          start.y=200
                          angle=112
                          br_nidus_ellipse CB.HNDL, %graphic, start.x-150, start.y-150, 300, 300, angle, 15, %MAGENTA, %BLACK, %RGB_CORAL
                        CASE 8
                          isbounding=1
                          start.x=300
                          start.y=200
                          angle=112
                          FOR angle=0 TO 359 STEP 10
          
                            br_nidus_ellipse CB.HNDL, %graphic, start.x-150, start.y-150, 300, 300, angle, 15, %BLUE, %BLACK, %GRAY
                          NEXT angle
          
                      END SELECT
                      INCR keepit
                    END IF
                  CASE %noncontrol
                    IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                      IF ISTRUE isbounding THEN
                        CONTROL SET LOC CB.HNDL, %graphic, 5,5
                        CONTROL SET SIZE CB.HNDL, %graphic, 590,350
                        GRAPHIC ATTACH CB.HNDL, %graphic, REDRAW
                        GRAPHIC REDRAW
                        isbounding= 0
                      END IF
                      GRAPHIC ATTACH CB.HNDL, %graphic
          
                      start.x=300
                      start.y=100
                      angle=60
                      draw_llps_nidus CB.HNDL, %graphic, angle, start, 90, 13, %RGB_CORAL, %GRAY
                      angle=150
                      draw_llps_nidus CB.HNDL, %graphic, angle, start, 120, 2, %RGB_CORAL, %BLUE
                      angle=33
                      draw_llps_nidus CB.HNDL, %graphic, angle, start, 90, 3, %RGB_CORAL, %MAGENTA
                      angle=75
                      draw_llps_nidus CB.HNDL, %graphic, angle, start, 150, .1, %RGB_CORAL, %CYAN
          
                      start.x=100
                      start.y=100
                      edge=90
                      rat=20
                      r=255
                      g=255
                      b=0
                      FOR angle=330 TO 0 STEP -30
                        draw_llps_nidus CB.HNDL, %graphic, angle, start, edge, rat, %RGB_CORAL, RGB(r,g,b)
                        edge-=5
                        rat-=1
                        b+=20
                        SLEEP 20
                      NEXT angle
          
                      start.x=150
                      start.y=300
                      edge=90
                      rat=8
                      r=127
                      g=127
                      b=0
                      FOR angle=0 TO 330 STEP 30
                        draw_llps_nidus CB.HNDL, %graphic, angle, start, edge, rat, %MAGENTA, RGB(r,g,b)
                        rat-=.5
                        b+=20
                        SLEEP 20
                      NEXT angle
          
                      start.x=450
                      start.y=100
                      edge=90
                      rat=3
                      r=255
                      g=190
                      b=0
                      FOR angle=0 TO 345 STEP 15
                        draw_llps_nidus CB.HNDL, %graphic, angle, start, edge, rat, %MAGENTA, RGB(r,g,b)
                        rat-=.1
                        b+=15
                        start.y+=5
                        SLEEP 20
                      NEXT angle
                    END IF
                  CASE %ellipses
                    IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                      IF ISTRUE isbounding THEN
                       CONTROL SET LOC CB.HNDL, %graphic, 5,5
                        CONTROL SET SIZE CB.HNDL, %graphic, 590,350
                        GRAPHIC ATTACH CB.HNDL, %graphic, REDRAW
                        GRAPHIC REDRAW
                        isbounding= 0
                      END IF
                      GRAPHIC ATTACH CB.HNDL, %graphic
          
                      start.x=300
                      start.y=100
                      angle=317
                      draw_ellipse CB.HNDL, %graphic, angle, start, 75, 10, %WHITE, %RED
                      start.x=200
                      start.y=100
                      r=255
                      g=127
                      b=0
                      FOR angle=0 TO 345 STEP 15
                        draw_ellipse CB.HNDL, %graphic, angle, start, 75, 8, %WHITE, RGB(r,g,b)
                        b+=10
                        SLEEP 20
                      NEXT angle
          
                      start.x=500
                      start.y=300
                      r=0
                      g=127
                      b=255
                      FOR angle=0 TO 330 STEP 30
                        draw_ellipse CB.HNDL, %graphic, angle, start, 20, 100, %WHITE, RGB(r,g,b)
                        r+=10
                        start.x-=10
                        SLEEP 20
                      NEXT angle
          
                      start.x=100
                      start.y=300
                      r=0
                      g=127
                      b=255
                      FOR angle=0 TO 330 STEP 30
                        draw_ellipse CB.HNDL, %graphic, angle, start, 40, 3, %WHITE, RGB(r,g,b)
                        r+=10
                        g+=5
                        b-=10
                        start.x+=10
                        SLEEP 20
                      NEXT angle
                    END IF
                  CASE %rects
                    IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                      IF ISTRUE isbounding THEN
                        CONTROL SET LOC CB.HNDL, %graphic, 5,5
                        CONTROL SET SIZE CB.HNDL, %graphic, 590,350
                        GRAPHIC ATTACH CB.HNDL, %graphic, REDRAW
                        GRAPHIC REDRAW
                        isbounding= 0
                      END IF
                      GRAPHIC ATTACH CB.HNDL, %graphic
          
                      start.x=100
                      start.y=100
                      angle =227
                      draw_rect CB.HNDL, %graphic, angle, start, 75, 25, %GREEN, %RED
          
                      start.x=300
                      start.y=100
                      angle =170
                      draw_rect CB.HNDL, %graphic, angle, start, 75, 75, %GREEN, %RED
          
                      start.x=100
                      start.y=200
                      r=255
                      g=0
                      b=127
                      FOR angle=0 TO 340 STEP 20
                        draw_rect CB.HNDL, %graphic, angle, start, 85, 20, %CYAN, RGB(r,g,b)
                        r-=10
                        g+=10
                        SLEEP 20
                      NEXT angle
          
                      start.x=300
                      start.y=250
                      r=0
                      g=255
                      b=127
                      FOR angle=0 TO 340 STEP 20
                        draw_rect CB.HNDL, %graphic, angle, start, 75, 75, %CYAN, RGB(r,g,b)
                        g-=10
                        r+=10
                        SLEEP 20
                      NEXT angle
          
                      start.x=450
                      start.y=100
                      r=255
                      g=127
                      b=0
                      edge=40
                      FOR angle=0 TO 345 STEP 15
                        draw_rect CB.HNDL, %graphic, angle, start, edge, edge, %CYAN, RGB(r,g,b)
                        r-=10
                        b+=10
                        edge+=5
                        SLEEP 20
                      NEXT angle
          
                      start.x=500
                      start.y=300
                      r=255
                      g=0
                      b=127
                      FOR angle=0 TO 340 STEP 20
                        draw_rect CB.HNDL, %graphic, angle, start, 30, 80, %CYAN, RGB(r,g,b)
                        r-=10
                        g+=10
                        b+=3
                        start.x-=10
                        SLEEP 20
                      NEXT angle
                    END IF
                  CASE %more_rects
                    IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                      IF ISTRUE isbounding THEN
                        CONTROL SET LOC CB.HNDL, %graphic, 5,5
                        CONTROL SET SIZE CB.HNDL, %graphic, 590,350
                        GRAPHIC ATTACH CB.HNDL, %graphic, REDRAW
                        GRAPHIC REDRAW
                        isbounding= 0
                      END IF
                      GRAPHIC ATTACH CB.HNDL, %graphic
          
                      start.x=100
                      start.y=100
                      angle =227
                      nidus_rect CB.HNDL, %graphic, angle, start, 80, 30, %GREEN, %RED
          
                      start.x=100
                      start.y=200
                      r=255
                      g=0
                      b=127
                      FOR angle=0 TO 340 STEP 20
                        nidus_rect CB.HNDL, %graphic, angle, start, 85, 20, %CYAN, RGB(r,g,b)
                        r-=10
                        g+=10
                        start.x+=5
                        start.y+=5
                        SLEEP 20
                      NEXT angle
          
                      start.x=300
                      start.y=250
                      r=127
                      g=0
                      b=255
                      FOR angle=0 TO 340 STEP 20
                        nidus_rect CB.HNDL, %graphic, angle, start, 75, 75, %BLUE, RGB(r,g,b)
                        b-=10
                        g+=10
                        SLEEP 20
                      NEXT angle
          
                      start.x=450
                      start.y=150
                      r=255
                      g=127
                      b=0
                      edge=40
                      FOR angle=0 TO 345 STEP 15
                        nidus_rect CB.HNDL, %graphic, angle, start, edge, edge, %MAGENTA, RGB(r,g,b)
                        r-=10
                        b+=10
                        g+=5
                        edge+=5
                        SLEEP 20
                      NEXT angle
          
                      start.x=250
                      start.y=100
                      r=255
                      g=127
                      b=0
                      edge=140
                      FOR angle=0 TO 345 STEP 15
                        nidus_rect CB.HNDL, %graphic, angle, start, edge, edge, %CYAN, RGB(r,g,b)
                        r-=10
                        b+=10
                        g+=5
                        edge-=5
                        SLEEP 20
                      NEXT angle
                    END IF
                  CASE %finale
                    IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                      IF ISTRUE isbounding THEN
                        CONTROL SET LOC CB.HNDL, %graphic, 5,5
                        CONTROL SET SIZE CB.HNDL, %graphic, 590,350
                        GRAPHIC ATTACH CB.HNDL, %graphic, REDRAW
                        GRAPHIC REDRAW
                        isbounding= 0
                      END IF
                      GRAPHIC ATTACH CB.HNDL, %graphic
          
                      start.x   =250
                      start.y   =100
                      angle     =35
                      angletri  =55
                      draw_triang_pts CB.HNDL, %graphic, start, angle, angletri,50, 50, %BLUE, %GREEN
          
                      start.x   =100
                      start.y   =100
                      angle     =35
                      r=255
                      g=255
                      b=0
                      FOR angletri=160 TO 20 STEP -20
                        draw_triang_pts CB.HNDL, %graphic, start, angle, angletri,75, 65, %BLUE, RGB(r,g,b)
                        b+=10
                        SLEEP 20
                      NEXT angletri
          
                      start.x   =100
                      start.y   =200
                      angletri  =65
                      r=255
                      g=127
                      b=0
                      FOR angle=300 TO 20 STEP -20
                        draw_triang_pts CB.HNDL, %graphic, start, angle, angletri,75, 65, %BLUE, RGB(r,g,b)
                        b+=20
                        g+=5
                        SLEEP 20
                      NEXT angle
          
                      start.x   =500
                      start.y   =250
                      angletri  =29
                      r=100
                      g=100
                      b=100
                      FOR angle=20 TO 340 STEP 20
                        draw_triang_pts CB.HNDL, %graphic, start, angle, angletri,75, 65, %GRAY, RGB(r,g,b)
                        r+=5
                        b+=15
                        g+=10
                        start.x-=7
                        start.y-=6
                        SLEEP 20
                      NEXT angle
          
                      start.x   =300
                      start.y   =250
                      angletri  =60
                      r=255
                      g=127
                      b=255
                      FOR edge=250 TO 100 STEP -10
                        start.y=edge
                        draw_triang_pts CB.HNDL, %graphic, start, angle, angletri,75, 65, %GRAY, RGB(r,g,b)
                        r+=5
                        b-=15
                        g+=10
                        SLEEP 20
                      NEXT edge
          
                      start.x   =200
                      start.y   =250
                      angletri  =90
                      angle     =90
                      stp       =60
                      hop       =80
                      r=0
                      g=127
                      b=255
                      FOR edge=250 TO 100 STEP -5
                        start.y=edge
                        draw_triang_pts CB.HNDL, %graphic, start, angle, angletri,stp, hop, %GRAY, RGB(r,g,b)
                        r+=5
                        b-=15
                        g+=10
                        stp-=3
                        hop-=4
                        SLEEP 20
                      NEXT edge
                    END IF
                  CASE %clear2black
                    IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                      'MSGBOX FORMAT$(isbounding)
                      bwtgl= bwtgl XOR 1
                      IF ISTRUE isbounding THEN
          
                        'CONTROL KILL CB.HNDL, %graphic
                       ' SLEEP 2
                        CONTROL SET LOC CB.HNDL, %graphic, 5,5
                        CONTROL SET SIZE CB.HNDL, %graphic, 590,350
                        ',CONTROL ADD GRAPHIC, CB.HNDL, %graphic, "", 5,5,590,350
                        GRAPHIC ATTACH CB.HNDL, %graphic, REDRAW
                        GRAPHIC REDRAW
                        isbounding= 0
                      END IF
                      GRAPHIC ATTACH CB.HNDL, %graphic
                      IF ISTRUE bwtgl THEN
                        GRAPHIC CLEAR %BLACK
                        CONTROL SET TEXT CB.HNDL, %clear2black, "Clear to White"
                      ELSE
                        GRAPHIC CLEAR %WHITE
                        CONTROL SET TEXT CB.HNDL, %clear2black, "Clear to Black"
                      END IF
                    END IF
                  CASE %clear2white
                    IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                      arrowtoggle = arrowtoggle XOR 1
          '            IF ISTRUE isbounding THEN
          '              'CONTROL KILL CB.HNDL, %graphic
          '              SLEEP 2
          '              CONTROL SET LOC CB.HNDL, %graphic, 5,5
          '              CONTROL SET SIZE CB.HNDL, %graphic, 590,350
          '              ',CONTROL ADD GRAPHIC, CB.HNDL, %graphic, "", 5,5,590,350
          '              GRAPHIC ATTACH CB.HNDL, %graphic, REDRAW
          '              GRAPHIC REDRAW
          '              isbounding= 0
          '            END IF
          '            GRAPHIC ATTACH CB.HNDL, %graphic
          '            GRAPHIC CLEAR %WHITE
                      start.x   =200
                      start.y   =250
                      angle     =55
                      arrow_p CB.HNDL, %graphic, angle, start, 40, 0,0,%BLUE
                      start.x   =100
                      start.y   =250
                      angle     =190
                      arrow_p CB.HNDL, %graphic, angle, start, 40, 0,2,%YELLOW
                      start.x   =300
                      start.y   =100
                      hop=1
                      FOR angle=0 TO 345 STEP 30
                        arrow_p CB.HNDL, %graphic, angle, start, 60, 0,hop,%MAGENTA
                        INCR hop
                      NEXT angle
                      start.x   =350
                      start.y   =225
                      hop=1
                      FOR angle=0 TO 345 STEP 30
                        arrow_p CB.HNDL, %graphic, angle, start, 20, 0,0,%CYAN
                        INCR hop
                      NEXT angle
                      start.x   =400
                      start.y   =50
                      angle     =90
                      hop=1
                      FOR r= 50 TO 250 STEP 25
                        start.y=r
                        arrow_p CB.HNDL, %graphic, angle, start, 20, 0, hop,%CYAN
                        INCR hop
                      NEXT r
                      start.x   =425
                      start.y   =50
                      angle     =270
                      hop=1
                      FOR r= 50 TO 250 STEP 25
                        start.y=r
                        arrow_p CB.HNDL, %graphic, angle, start, 30, 0, hop,%MAGENTA
                        INCR hop
                      NEXT r
                      start.x   =490
                      start.y   =50
                      hop=1
                      FOR angle=0 TO 345 STEP 30
                        arrow_p CB.HNDL, %graphic, angle, start, 60, 0,hop,%GREEN
                        start.y+=20
                        'INCR hop
                      NEXT angle
                      start.x   =50
                      start.y   =50
                      angle     =45
                      r=125
                      g=110
                      b=25
                      FOR hop= 50 TO 250 STEP 25
          
                        arrow_p CB.HNDL, %graphic, angle, start, 20, 0, 0,RGB(r,g,b)
                        start.y+=10
                        start.x+=10
                        r+=5
                        g+=5
                        b+=5
                       ' msgbox format$(start.y)
                      NEXT hop
                      IF ISTRUE arrowtoggle THEN
                        CONTROL SET TEXT CB.HNDL, %clear2white, "Arrows Rotate at Point"
                      ELSE
                        CONTROL SET TEXT CB.HNDL, %clear2white, "Arrows Rotate at Centre"
                      END IF
                    END IF
                  CASE %IDCANCEL
                    IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                      GRAPHIC DETACH
                      DIALOG END CB.HNDL, 0
                    END IF
                END SELECT
            END SELECT
          END FUNCTION
          SUB arrow_p(whndl AS LONG, _  'Window handle, required for REDRAW
                      ident AS LONG, _  'required for REDRAW
                      ang AS DOUBLE, _  'main axis angle clockwise from 3 o'clock
                      orig AS POINT, _  'starting point-arrows radiate from this point
                      leng AS LONG, _   'distance twixt the two end points
                      proj AS LONG, _   '0 for angle at base, 1 for angle at point
                      wid  AS LONG, _   'width of the line elements of the arrow  'bclr AS LONG, _   'border colour
                      fclr AS LONG)     'fill colour
            LOCAL nd, pp, mp AS POINT
            LOCAL PI AS EXTENDED
            PI=ATN(1)*4
            IF ISTRUE wid THEN
              GRAPHIC WIDTH wid
            END IF
            nd.x=orig.x+(leng)*COS((ang*pi)/180)
            nd.y=orig.y+(leng)*SIN((ang*pi)/180)
           ' msgbox format$(nd.x)+$crlf+format$(nd.y)
            pp.x=nd.x+(leng*.25)*COS(((ang-135)*pi)/180)
            pp.y=nd.y+(leng*.25)*SIN(((ang-135)*pi)/180)
            mp.x=nd.x+(leng*.25)*COS(((ang+135)*pi)/180)
            mp.y=nd.y+(leng*.25)*SIN(((ang+135)*pi)/180)
            GRAPHIC LINE (orig.x, orig.y)-(nd.x,nd.y), fclr
            GRAPHIC LINE (nd.x,nd.y)-(pp.x,pp.y), fclr
            GRAPHIC LINE (nd.x,nd.y)-(mp.x,mp.y), fclr
            IF ISTRUE wid THEN
              GRAPHIC WIDTH 1
            END IF
          END SUB
          SUB draw_triang_pts(whndl  AS LONG,    _  'Window handle, required for REDRAW
                              ident  AS LONG,    _  'required for REDRAW
                              orig   AS POINT,   _  'starting point-triangles rotate around this point
                              angle  AS DOUBLE,  _  'main axis angle bisector clockwise from 3 o'clock
                              bisang AS DOUBLE,  _  'bisected angle 179 max
                              minlen AS LONG,    _  'length of less than angle side
                              plulen AS LONG,    _  'length of greater than angle side
                              bclr   AS LONG,    _  'border colour
                              fclr   AS LONG)       'fill colour
            GRAPHIC ATTACH whndl, ident, REDRAW
            IF bisang>179 THEN
              MSGBOX "Angle must be 0 to 179"
              EXIT SUB
            END IF
            LOCAL ang, pi AS DOUBLE
            LOCAL p1, p2 AS POINT
            LOCAL tri AS polytriangle
            ang=bisang/2
            tri.count =3
            tri.x1    =orig.x
            tri.y1    =orig.y
            PI=ATN(1)*4
            tri.x2=orig.x+(minlen)*COS(((angle-ang)*pi)/180)
            tri.y2=orig.y+(minlen)*SIN(((angle-ang)*pi)/180)
            tri.x3=orig.x+(plulen)*COS(((angle+ang)*pi)/180)
            tri.y3=orig.y+(plulen)*SIN(((angle+ang)*pi)/180)
            GRAPHIC POLYGON tri, bclr, fclr
            GRAPHIC REDRAW
            GRAPHIC ATTACH whndl, ident
          END SUB
          
          SUB br_nidus_ellipse(whndl AS LONG,    _  'Window handle, required for REDRAW
                               ident AS LONG,    _  'required for REDRAW
                               xpos   AS LONG,   _  'client area horizontal location of bounding rect
                               ypos   AS LONG,   _  'client area vertical location of bounding rect
                               wid    AS LONG,   _  'width of bounding rectangle
                               hgt    AS LONG,   _  'height of bounding rectangle
                               ang    AS DOUBLE, _  'angle of the ellipse
                               rat    AS DOUBLE, _  'ration of the short to long axes
                               bdrclr AS LONG,   _  'field colour of the bounding rectangle default -2
                               fllclr AS LONG,   _  'border colour of the ellipse default -1
                               fldclr AS LONG)      'fill colour of the ellipse default-same as border
            LOCAL fdclr, flclr, bdclr, maxed, keep, match, xxx, lots, flag,yyy AS LONG
            LOCAL dist, dbcnt, leng, prj, stb, ttl, tmp, tst, tsto, tstu AS DOUBLE
            LOCAL ndx, equal, less, more AS LONG
            LOCAL myd, g, t, n, a1, a2, t1, t2, ot, ut AS POINT
            LOCAL pts AS PolyArray
            pts.count=1000
            LOCAL PI AS EXTENDED
            PI=ATN(1)*4
            CONTROL ADD GRAPHIC, whndl,ident, "", xpos,ypos,wid,hgt
            GRAPHIC ATTACH whndl,ident, REDRAW
            myd.x=wid/2
            myd.y=hgt/2
            IF wid>=hgt THEN
              dist = wid/2
            ELSE
              dist = hgt/2
            END IF
            maxed = 0
            g.x=myd.x+(dist)*COS((ang*pi)/180)
            g.y=myd.y+(dist)*SIN((ang*pi)/180)
            t=g
            DO
              INCR ndx
              IF ndx>1 THEN
                t=g
              END IF
              dist+=.36
              g.x=myd.x+(dist)*COS((ang*pi)/180)
              g.y=myd.y+(dist)*SIN((ang*pi)/180)
              IF g.x<=0 OR g.x>=wid THEN
                maxed=1
                EXIT DO
              END IF
              IF g.y<=0 THEN
                maxed=1
                EXIT DO
              ELSEIF g.y>=hgt THEN
                maxed=1
                EXIT DO
              END IF
            LOOP UNTIL maxed
            ndx=0
            DO
              lots=0
              flag=0
              ndx=0
              leng=dist*2
              prj=rat/100*dist
              n.x=myd.x+(dist)*COS(((ang+180)*pi)/180)
              n.y=myd.y+(dist)*SIN(((ang+180)*pi)/180)
              stb=dist-prj
              ttl=stb*4+prj*2
              a2.x=myd.x+(stb)*COS((ang*pi)/180)
              a2.y=myd.y+(stb)*SIN((ang*pi)/180)
              a1.x=myd.x+(stb)*COS(((ang+180)*pi)/180)
              a1.y=myd.y+(stb)*SIN(((ang+180)*pi)/180)
              FOR dbcnt=0 TO 360 STEP .36
          
                INCR ndx
                match=0
                xxx=1
                DO
                  t1.x=myd.x+(xxx)*COS((dbcnt*pi)/180)
                  t1.y=myd.y+(xxx)*SIN((dbcnt*pi)/180)
                  IF t1.x<=0 THEN
                    flag=1
                    EXIT FOR
                  END IF
                  IF t1.x>=wid THEN
                    flag=1
                    EXIT FOR
                  END IF
                  IF t1.y<=0 THEN
                    flag=1
                    EXIT FOR
                  END IF
                  IF t1.y>=hgt THEN
                    flag=1
                    EXIT FOR
                  END IF
                  tst=(stb*2)
                  tst+=SQR(((t1.x-a1.x)*(t1.x-a1.x))+((t1.y-a1.y)*(t1.y-a1.y)))
                  tst+=SQR(((t1.x-a2.x)*(t1.x-a2.x))+((t1.y-a2.y)*(t1.y-a2.y)))
                  IF tst=ttl THEN
                    match=1
                    EXIT DO
                  END IF
                  IF tst>ttl THEN
                    ot=t1
                    tsto=tst
                    IF tsto-ttl>ttl-tstu THEN
                      match=1
                      t1=ut
                    ELSEIF tsto-ttl< ttl-tstu THEN
                      match=1
                      t1=ot
                    END IF
                  END IF
                  IF tst<ttl THEN
                    ut=t1
                    tstu=tst
                  END IF
                  INCR xxx
          
                LOOP UNTIL ISTRUE match
          
          
                INCR lots
                IF lots=1000 THEN
                  INCR keep
                END IF
                pts.xy(lots).x=t1.x
                pts.xy(lots).y=t1.y
              NEXT dbcnt
              IF ISTRUE flag THEN
                dist-=1
              END IF
            LOOP UNTIL ISTRUE keep
            GRAPHIC BOX (0,0)-(wid,hgt), 0, fldclr, fldclr
            GRAPHIC POLYGON pts, bdrclr, fllclr
            GRAPHIC REDRAW
            GRAPHIC ATTACH whndl,ident
          
          END SUB
          
          SUB draw_llps_nidus(whndl AS LONG,    _  'Window handle, required for REDRAW
                              ident AS LONG,    _  'required for REDRAW
                              ang   AS DOUBLE,  _  'main axis angle clockwise from 3 o'clock
                              orig  AS POINT,   _  'starting point-ellipes rotate around this point
                              leng  AS LONG,    _  'distance twixt the two major axes
                              proj  AS DOUBLE,  _  'straight line distance from one axis as a percentage of 'leng'
                              bclr  AS LONG,    _  'border colour
                              fclr  AS LONG)       'fill colour
            LOCAL last, t1, ot, ut, a2, a1 AS POINT
            LOCAL ndx, match AS LONG
            LOCAL dcnt, xxx, ttl, tst, tsto, tstu, prj AS DOUBLE
            LOCAL pts AS PolyArray
            pts.count=1000
            LOCAL PI AS EXTENDED
            PI=ATN(1)*4
            GRAPHIC ATTACH whndl,ident, REDRAW
            ttl=(leng+((proj/100)*leng))*2
            prj=leng*proj/100
            a2.x=orig.x+((leng/2))*COS((ang*pi)/180)
            a2.y=orig.y+((leng/2))*SIN((ang*pi)/180)
            a1.x=orig.x+((leng/2))*COS(((ang+180)*pi)/180)
            a1.y=orig.y+((leng/2))*SIN(((ang+180)*pi)/180)
            IF proj>0 AND proj<=100 THEN
          
              ndx=0
              FOR dcnt= 0 TO 360 STEP .36
                match=0
                xxx=1
                DO
                  t1.x=orig.x+(xxx)*COS((dcnt*pi)/180)
                  t1.y=orig.y+(xxx)*SIN((dcnt*pi)/180)
                  tst=leng
                  tst+=SQR(((t1.x-a1.x)*(t1.x-a1.x))+((t1.y-a1.y)*(t1.y-a1.y)))
                  tst+=SQR(((t1.x-a2.x)*(t1.x-a2.x))+((t1.y-a2.y)*(t1.y-a2.y)))
                  IF tst=ttl THEN
                    match=1
                    EXIT DO
                  ELSEIF tst>ttl THEN
                    ot=t1
                    tsto=tst
                    IF tsto-ttl>ttl-tstu THEN
                      match=1
                      t1=ut
                    ELSEIF tsto-ttl< ttl-tstu THEN
                      match=1
                      t1=ot
                    END IF
                  ELSEIF tst<ttl THEN
                    ut=t1
                    tstu=tst
                  END IF
                INCR xxx
                LOOP UNTIL ISTRUE match
                INCR ndx
                pts.xy(ndx).x=t1.x
                pts.xy(ndx).y=t1.y
              NEXT dcnt
              GRAPHIC POLYGON pts, bclr, fclr
            END IF
            GRAPHIC REDRAW
            GRAPHIC ATTACH whndl,ident
          END SUB
          
          SUB draw_ellipse(whndl AS LONG, _  'Window handle, required for REDRAW
                           ident AS LONG, _  'required for REDRAW
                           ang AS DOUBLE, _  'main axis angle clockwise from 3 o'clock
                           orig AS POINT, _  'starting point-ellipes radiate from this point
                           leng AS LONG, _   'distance twixt the two major axes
                           proj AS DOUBLE, _ 'straight line distance from one axis as a percentage of 'leng' 0-100
                           bclr AS LONG, _   'border colour
                           fclr AS LONG)     'fill colour
            LOCAL last, myd, sprout1, sprout2, q1, q2, q3, q4, route, a1, a2, t1, t2, ut, ot AS POINT
            LOCAL ndx, cntr, qud, match AS LONG
            LOCAL ttl, perp, hypo, bal, seg, prj, xx, yy, half, tst, xxx, yyy, tstu, tsto, dcnt AS DOUBLE
            LOCAL hx, lx, hy, ly AS DOUBLE
            LOCAL pts AS PolyArray
            LOCAL ptts() AS POINT
            pts.count=1000
            LOCAL PI AS EXTENDED
            PI=ATN(1)*4
            GRAPHIC ATTACH whndl,ident, REDRAW
            SELECT CASE ang
              CASE 0 TO 90
                qud=1
              CASE 90 TO 180
                qud=2
              CASE 180 TO 270
                qud=3
              CASE 270 TO 360
                qud=4
            END SELECT
          
            IF proj=0 THEN
              last.x=orig.x+(leng)*COS((ang*pi)/180)
              last.y=orig.y+(leng)*SIN((ang*pi)/180)
              GRAPHIC LINE (orig.x,orig.y)-(last.x,last.y),bclr
            ELSEIF proj<=200 THEN
              ttl=(leng+((proj/100)*leng))*2
              prj=leng*proj/100
              bal=ttl-leng
              hypo=bal/2
              seg=leng/2
              half=prj+seg
              perp=SQR((hypo*hypo)-(seg*seg))
              last.x=orig.x+(leng+(prj*2))*COS((ang*pi)/180)
              last.y=orig.y+(leng+(prj*2))*SIN((ang*pi)/180)
              a2.x=orig.x+(leng+prj)*COS((ang*pi)/180)
              a2.y=orig.y+(leng+prj)*SIN((ang*pi)/180)
              a1.x=orig.x+(prj)*COS((ang*pi)/180)
              a1.y=orig.y+(prj)*SIN((ang*pi)/180)
              myd.x=orig.x+(prj+(leng/2))*COS((ang*pi)/180)
              myd.y=orig.y+(prj+(leng/2))*SIN((ang*pi)/180)
              sprout1.x=myd.x+(perp)*COS(((90+ang)*pi)/180)
              sprout1.y=myd.y+(perp)*SIN(((90+ang)*pi)/180)
              sprout2.x=myd.x+(perp)*COS(((270+ang)*pi)/180)
              sprout2.y=myd.y+(perp)*SIN(((270+ang)*pi)/180)
              xx=ABS(sprout1.x-myd.x)
              yy=ABS(sprout1.y-myd.y)
              hx=myd.x+(half)*COS(((0)*pi)/180)
              lx=myd.x+(half)*COS(((180)*pi)/180)
              ly=myd.y+(half)*SIN(((270)*pi)/180)
              hy=myd.y+(half)*SIN(((90)*pi)/180)
              ndx=0
              FOR dcnt= 0 TO 360 STEP .36
                match=0
                xxx=1
                DO
                  t1.x=myd.x+(xxx)*COS((dcnt*pi)/180)
                  t1.y=myd.y+(xxx)*SIN((dcnt*pi)/180)
                  tst=leng
                  tst+=SQR(((t1.x-a1.x)*(t1.x-a1.x))+((t1.y-a1.y)*(t1.y-a1.y)))
                  tst+=SQR(((t1.x-a2.x)*(t1.x-a2.x))+((t1.y-a2.y)*(t1.y-a2.y)))
                  IF tst=ttl THEN
                    match=1
                    EXIT DO
                  ELSEIF tst>ttl THEN
                    ot=t1
                    tsto=tst
                    IF tsto-ttl>ttl-tstu THEN
                      match=1
                      t1=ut
                    ELSEIF tsto-ttl< ttl-tstu THEN
                      match=1
                      t1=ot
                    END IF
                  ELSEIF tst<ttl THEN
                    ut=t1
                    tstu=tst
                  END IF
                INCR xxx
                LOOP UNTIL ISTRUE match
                INCR ndx
                REDIM PRESERVE ptts(1 TO ndx)
                ptts(ndx).x=t1.x
                ptts(ndx).y=t1.y
                pts.xy(ndx).x=t1.x
                pts.xy(ndx).y=t1.y
              NEXT dcnt
          
              GRAPHIC POLYGON pts, bclr, fclr
            END IF
            GRAPHIC REDRAW
            GRAPHIC ATTACH whndl,ident
          END SUB
          SUB nidus_rect(whndl AS LONG, _  'Window or graphic handle, required for REDRAW
                        ident AS LONG, _  'required for REDRAW
                        ang AS DOUBLE, _  'main axis angle clockwise from 3 o'clock
                        orig AS POINT, _  'center starting point-shapes rotate around this point
                        leng AS LONG,  _  'length of rectangle or square
                        hyte AS LONG,  _  'width of rectangle, equal to leng for square
                        bclr AS LONG,  _   'border colour
                        fclr AS LONG)     'fill colour
            LOCAL hyp, angle AS DOUBLE
            LOCAL ldist AS LONG
            LOCAL hdist AS LONG
            LOCAL c1, c2, c3, c4, t1, t2 AS POINT
            LOCAL rct AS polyrect
            rct.count=4
            LOCAL PI AS EXTENDED
            PI=ATN(1)*4
            GRAPHIC ATTACH whndl,ident, REDRAW
            hdist=hyte/2
            ldist=leng/2
            t1.x= orig.x+(ldist)*COS((ang*pi)/180)
            t1.y= orig.y+(ldist)*SIN((ang*pi)/180)
            t2.x= orig.x+(ldist)*COS(((ang+180)*pi)/180)
            t2.y= orig.y+(ldist)*SIN(((ang+180)*pi)/180)
            angle=(ang-90) MOD 360
            c1.x= t2.x+(hdist)*COS((angle*pi)/180)
            c1.y= t2.y+(hdist)*SIN((angle*pi)/180)
            angle=(ang+90) MOD 360
            c2.x= t2.x+(hdist)*COS((angle*pi)/180)
            c2.y= t2.y+(hdist)*SIN((angle*pi)/180)
            angle=(ang-90) MOD 360
            c3.x= t1.x+(hdist)*COS((angle*pi)/180)
            c3.y= t1.y+(hdist)*SIN((angle*pi)/180)
            angle=(ang+90) MOD 360
            c4.x= t1.x+(hdist)*COS((angle*pi)/180)
            c4.y= t1.y+(hdist)*SIN((angle*pi)/180)
            rct.xy(1).x=c1.x
            rct.xy(1).y=c1.y
            rct.xy(2).x=c2.x
            rct.xy(2).y=c2.y
            rct.xy(3).x=c4.x
            rct.xy(3).y=c4.y
            rct.xy(4).x=c3.x
            rct.xy(4).y=c3.y
            GRAPHIC POLYGON rct, bclr, fclr
            GRAPHIC REDRAW
            GRAPHIC ATTACH whndl,ident
          END SUB
          
          SUB draw_rect(whndl AS LONG, _  'Window or graphic handle, required for REDRAW
                        ident AS LONG, _  'required for REDRAW
                        ang AS DOUBLE, _  'main axis angle clockwise from 3 o'clock
                        orig AS POINT, _  'starting point-shapes rotate around this point
                        leng AS LONG,  _  'length of rectangle or square
                        hyte AS LONG,  _  'width of rectangle, equal to leng for square
                        bclr AS LONG,  _   'border colour
                        fclr AS LONG)     'fill colour
            LOCAL hyp, angle AS DOUBLE
            LOCAL ldist AS LONG
            LOCAL hdist AS LONG
            LOCAL c1, c2, c3, c4, t1, t2 AS POINT
            LOCAL rct AS polyrect
            rct.count=4
            LOCAL PI AS EXTENDED
            PI=ATN(1)*4
            GRAPHIC ATTACH whndl,ident, REDRAW
            hdist=hyte/2
            ldist=leng/2
            t1.x= orig.x+(leng)*COS((ang*pi)/180)
            t1.y= orig.y+(leng)*SIN((ang*pi)/180)
            angle=(ang-90) MOD 360
            c1.x= orig.x+(hdist)*COS((angle*pi)/180)
            c1.y= orig.y+(hdist)*SIN((angle*pi)/180)
            angle=(ang+90) MOD 360
            c2.x= orig.x+(hdist)*COS((angle*pi)/180)
            c2.y= orig.y+(hdist)*SIN((angle*pi)/180)
            angle=(ang-90) MOD 360
            c3.x= t1.x+(hdist)*COS((angle*pi)/180)
            c3.y= t1.y+(hdist)*SIN((angle*pi)/180)
            angle=(ang+90) MOD 360
            c4.x= t1.x+(hdist)*COS((angle*pi)/180)
            c4.y= t1.y+(hdist)*SIN((angle*pi)/180)
            rct.xy(1).x=c1.x
            rct.xy(1).y=c1.y
            rct.xy(2).x=c2.x
            rct.xy(2).y=c2.y
            rct.xy(3).x=c4.x
            rct.xy(3).y=c4.y
            rct.xy(4).x=c3.x
            rct.xy(4).y=c3.y
            GRAPHIC POLYGON rct, bclr, fclr
            GRAPHIC REDRAW
            GRAPHIC ATTACH whndl,ident
          END SUB
          Click image for larger version  Name:	rotary_graphics.gif Views:	2 Size:	133.8 KB ID:	773572
          Rod
          "To every unsung hero in the universe
          To those who roam the skies and those who roam the earth
          To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

          Comment


          • #6
            Code:
            PBCC6 program
            #BREAK ON
            #DEBUG ERROR ON
            
            FUNCTION PBMAIN
            
            LOCAL r, hGraphic AS LONG
            LOCAL angle AS SINGLE
            
            GRAPHIC WINDOW NEW "Graphic",600,400,500,500 TO hGraphic
            GRAPHIC ATTACH hGraphic,0
            
            'show at a variety of angles
            FOR r = 0 TO 360  STEP 10
                angle = r/57.29  'in radians
            
                GRAPHIC CLEAR
                DrawWideLine (200,200,200+100*SIN(angle), 200+100*COS(angle) , 20, %BLUE)
            
                SLEEP 50
            
            NEXT
            
            'show a single line
            DrawWideLine (300,300,400,400, 30,%RED)
            
            CONSOLE SET FOCUS
            PRINT "Press a key to end."
            WAITKEY$
            
            END FUNCTION
            
            
            
            
            
            TYPE PolyPoints4
              count AS LONG
              x1 AS SINGLE
              y1 AS SINGLE
              x2 AS SINGLE
              y2 AS SINGLE
              x3 AS SINGLE
              y3 AS SINGLE
              x4 AS SINGLE
              y4 AS SINGLE
            
            END TYPE
            
            
            FUNCTION DrawWideLine(FromX AS SINGLE, FromY AS SINGLE, ToX AS SINGLE, ToY AS SINGLE, LineWidth AS SINGLE, LineColour AS LONG) AS LONG
            
            LOCAL Xdistance, Ydistance, LineLength, Dx, Dy AS SINGLE
            LOCAL Pts AS PolyPoints4
            
            Pts.count = 4
            
            Xdistance = FromX-ToX
            Ydistance = FromY-ToY
            
            Linelength = SQR(Xdistance * Xdistance + Ydistance * Ydistance)
            
            Dx =(LineWidth/2) / LineLength * Ydistance
            Dy =(LineWidth/2) / LineLength * Xdistance
            
            Pts.x1 = FromX-Dx
            Pts.y1 = FromY+Dy
            
            Pts.x2 = FromX+Dx
            Pts.y2 = FromY-Dy
            
            Pts.x3 = ToX+Dx
            Pts.y3 = ToY-Dy
            
            Pts.x4 = ToX-Dx
            Pts.y4 = ToY+Dy
            
            GRAPHIC WIDTH 1
            GRAPHIC POLYGON pts, LineColour,LineColour
            
            END FUNCTION

            Comment


            • #7
              Oops. PBWin version:
              Code:
              PBWin10 program
              #DEBUG ERROR ON
              
              FUNCTION PBMAIN
              
              LOCAL r, hGraphic AS LONG
              LOCAL angle AS SINGLE
              
              GRAPHIC WINDOW NEW "Graphic",600,400,500,500 TO hGraphic
              GRAPHIC ATTACH hGraphic,0
              
              'show at a variety of angles
              FOR r = 0 TO 360  STEP 10
                  angle = r/57.29  'in radians
              
                  GRAPHIC CLEAR
                  DrawWideLine (200,200,200+100*SIN(angle), 200+100*COS(angle) , 20, %BLUE)
              
                  SLEEP 50
              
              NEXT
              
              'show a single line
              DrawWideLine (300,300,400,400, 30,%RED)
              
              
              MSGBOX "Press to end"
              
              END FUNCTION
              
              
              
              
              
              TYPE PolyPoints4
                count AS LONG
                x1 AS SINGLE
                y1 AS SINGLE
                x2 AS SINGLE
                y2 AS SINGLE
                x3 AS SINGLE
                y3 AS SINGLE
                x4 AS SINGLE
                y4 AS SINGLE
              
              END TYPE
              
              
              FUNCTION DrawWideLine(FromX AS SINGLE, FromY AS SINGLE, ToX AS SINGLE, ToY AS SINGLE, LineWidth AS SINGLE, LineColour AS LONG) AS LONG
              
              LOCAL Xdistance, Ydistance, LineLength, Dx, Dy AS SINGLE
              LOCAL Pts AS PolyPoints4
              
              Pts.count = 4
              
              Xdistance = FromX-ToX
              Ydistance = FromY-ToY
              
              Linelength = SQR(Xdistance * Xdistance + Ydistance * Ydistance)
              
              Dx =(LineWidth/2) / LineLength * Ydistance
              Dy =(LineWidth/2) / LineLength * Xdistance
              
              Pts.x1 = FromX-Dx
              Pts.y1 = FromY+Dy
              
              Pts.x2 = FromX+Dx
              Pts.y2 = FromY-Dy
              
              Pts.x3 = ToX+Dx
              Pts.y3 = ToY-Dy
              
              Pts.x4 = ToX-Dx
              Pts.y4 = ToY+Dy
              
              GRAPHIC WIDTH 1
              GRAPHIC POLYGON pts, LineColour,LineColour
              
              END FUNCTION

              Comment


              • #8
                Fim,

                The hard part is knowing the (x,y) of each corner point of each oblique rectangle.

                But with those in hand, 5 lines of code will draw each oblique rectangle ... 4 x Graphic Line (corner to corner) then Graphic Paint to fill.

                Comment


                • #9
                  Gary,
                  the code I posted does away with that need as it calculates the corners based on the start point, end point and width of the line.

                  Comment


                  • #10
                    Hi Paul,
                    Yep. It does and it's an accurate way to get the uniform widths and rectangle angular position Kim is wanting.

                    Kim,
                    Another option for the oblique rectangles .. create a rotated font (Arial worked well in my test) at each of four angles and as large as needed, drawing the letter "I" each time. But has the same problem of needing to know the starting corner point - not as easy to calculate as with Paul's code. The approach might come in handy for other rotations, especially if you're picking a symbol from a font.

                    Comment


                    • #11
                      Hi Fim,
                      Another way - use a bitmap and render it to screen? Borrowed your litte one (had to save it via MS Paint)), placed in same folder as test code and..
                      Code:
                      #COMPILE EXE
                      #DIM ALL
                      FUNCTION PBMAIN () AS LONG
                        LOCAL hWin AS LONG
                        GRAPHIC WINDOW NEW "Graphic Render test", 200, 100, 500, 500 TO hWin
                        GRAPHIC ATTACH hWin, 0
                        GRAPHIC RENDER "Ratten-Röd-mindre.bmp", (0,0)-(500,500)
                        GRAPHIC WAITKEY$
                      END FUNCTION

                      Comment


                      • #12
                        You can draw that circular figure entirely using GRAPHIC BOX statements, as the roundedness of the corner if set to 100 gives a circle.

                        Come to think of it, you can also draw the diagonals using GRAPHIC LINE with a suitable line width, then clip the extremities using a GRAPHIC BOX in background colour, though the outer ends would be sections of the circumference of the BOX-circle.

                        Comment


                        • #13
                          like this:
                          Code:
                          #compile exe
                          #dim all
                          
                          function pbmain () as long
                              local hGW as long
                          
                              graphic window "", 100, 100, 500, 500 to hGW
                              graphic attach hGW, 0, redraw
                              graphic clear %white
                              graphic width 30
                              graphic box (100,100)-(400,400), 100, %red, %red
                              graphic line (50, 250)-(450, 250), %red
                              graphic line (250, 50)-(250, 450), %red
                              graphic box (130,130)-(370,370), 100, %white, %white
                              graphic line (50, 75)-(450, 400), %red
                              graphic line (450, 75)-(50, 400), %red
                              graphic width 120
                              graphic box(0, 0)-(500, 500), 100, %white, -2
                              graphic redraw
                              ? "done"
                              graphic window end
                          
                          end function

                          Comment


                          • #14
                            Of course, instead of using the last GRAPHIC BOX, you could always clip those wide GRAPHIC LINEs with an intersecting GRAPHIC LINE in background colour, then repaint the unwanted ends in background colour using GRAPHIC PAINT.

                            Comment


                            • #15
                              Very nice, Chris!!
                              And a very good example of why we continue to use the 'deprecated' DDT styled graphics(as mentioned in another thread). Simplicity, thy name is GRAPHIC.
                              Rod
                              "To every unsung hero in the universe
                              To those who roam the skies and those who roam the earth
                              To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

                              Comment


                              • #16
                                Originally posted by Rodney Hicks View Post
                                And a very good example of why we continue to use the 'deprecated' DDT styled graphics(as mentioned in another thread). Simplicity, thy name is GRAPHIC.
                                Thanks Rodney!
                                I think there are two kinds of people, the ones who want the biggest, best and shiniest and the ones who aspire to travel light. Good arguments on each side. Which reminds me, there are two kinds of people, the ones who must always be right and the ones who...

                                [scuffle...click]

                                It's Ok Sir, we got him back again

                                Comment

                                Working...
                                X