Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

A graphical, mathematical & possibly philosophical puzzle

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

  • A graphical, mathematical & possibly philosophical puzzle

    Gustav Fechner, the 19th century founder of psychophysics, said that there are actually two branches of this discipline -- the inner & the outer. He explained the difference by asking one to consider whether a circle is concave or convex.

    Obviously, he said, the answer will depend on whether you mentally or physically place yourself inside or outside of the circle. He would not, of course, have ruled out the possibility that a circle can also be a straight line, or flat. And if you think that that is crazy, you ain't seen nothing yet.

    The .zip file attachment to this post contains of a compiled version of the program below, and a screen capture. If you can predict in advance, from the source code, what the screen capture will look like, I'll be amazed. Unless of course you have by chance already downloaded tgDraw.INC and run the demos.

    Code:
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
         LOCAL I AS LONG
         I = 3701
        CALL BigBangDemo(I)
        'unREM next line if you want to save screen
        'GRAPHIC SAVE "BigBang"+TRIM$(STR$(I))+"EXT.BMP"
    END FUNCTION
    
    '===============================================================================
    '=                                     BigBangDemo                             =
    '=                                 by Emil Menzel 2008                         =
    '=                          requires Menzel & Schreiber's tgDraw.INC           =
    '= FREE AT http://www.powerbasic.com/support/pbforums/showthread.php?t=37809   =
    '===============================================================================
    'tgDraw.INC is a PBCC/PBWin "update" of DOS BASIC's graphic "DRAW" command.
    
    #INCLUDE "tgDraw.inc"
    #INCLUDE "win32api.inc"
    SUB BigBangDemo(MaxNumber AS LONG)
        LOCAL I AS LONG, A,B,C AS STRING
        LOCAL hBMPSource AS DWORD
        ' You can use Win32API to get desktop resolution, & full screen size:
        ' (And BigBangDemo would be best if run at Max size, or at least max width)
        turtle.canvaswidth = GetSystemMetrics(%SM_CXSCREEN)  'all turtle.X variables are GLOBAL and defined by tgDraw.INC
        turtle.canvasheight =GetSystemMetrics(%SM_CYSCREEN)
    
        GRAPHIC WINDOW "BigBang demo (Pythagoreans, beware the number 3601)", 0, 0, turtle.canvaswidth,turtle.canvasheight TO hBmpSource
    
        tgAttachGraphic(hBmpSource, 0, %TG_DOUBLE_BUFFER)
    
    
        tgDraw "Q0"  'ClearScreen to color 0
        tgDraw "w1 z50 s15"  'pen width,  ms sleep after each move, scale (here, length of each 'side' of polygons)
    
        'The basic command for drawing a polygon...
        'e.g.: triangle, color4, starting X/Y pos,startAngle, forwardJumpValue (* scale Sn, above), turnRight 360/3 degrees, & repeat 3 times,
        C$=STR$(turtle.canvaswidth/2)
        tgDraw "c4 bm" + C$ + ",100 a0 X3(j2 o120)"    'cn=color#, an= angle of rotation,Xn =Repeat n times, Jn=jump forward,On=turnRight n degrees
        tgDraw ("k bm" + STR$(VAL(C$)+5) + ",105 P15,4") 'tgHome(k), then move into triangle, & Paint it... Syntax: Pcolor,boundaryColor
    
        'You can also print with tgTextDrawCode but for this demo PB's GRAPHIC PRINT is better
        tgSetPos(80,40)                     'GRAPHIC SET POS in PBCC/PBWin lingo
        tgSetColor(%TG_White, %TG_Black)    'GRAPHIC SET COLOR
        A$=" 'Polygons' can never truly become circles, nor a 'circle' a straight line -- Plato "
        B$=" Run this program long enough, Dave, & you'll see the dark side of the Force -- Hal "
        tgPrint A$  'GRAPHIC PRINT A$
        tgSetPos(80,55)
        tgDraw "?" + B$  'equivalent to tgGPrint B$ and to GRAPHIC PRINT B$
    
        tgUpdateScreen()
        I=3 'from triangle to square, pentagon... circle...
            '(that is an 'apparent' but not true circle, if you are a Platonist)...
            'to straight line, & finally to chaos after count 3600 (if you are a turtle)
            'Note: You can start with I at any number
        C$="BM" + C$ + ",100 A0"  'to set POS and angle
        DO
            'Show the count (no. of sides on current polygon)
            tgDraw("BM10,10 C255,255,255,0,0,0 ?" + STR$(I))
            'format the string that draws the next polygon
            A$="C" + FORMAT$((I MOD 15)+1) + C$ + "X"+FORMAT$(I)+"(J2 O"+FORMAT$(360/I) + ")"
            IF I > 21 THEN A$="z0" + A$  'max speed
            tgDraw A$
            tgUpdateScreen()
            INCR I
        LOOP UNTIL I > MaxNumber
    END SUB
    Attached Files

  • #2
    Emil,

    I found out the reason of the anomaly

    There is a part in draw string for the circle:
    Code:
    "(J2 O"+FORMAT$(360/I) + ")"
    But - FORMAT$ for tiny numbers like 360/3651 outputs numbers in engineers notation - for this case like 9.860312E-2. Our parser trims out that E, so instead of 0.0986031 tgDraw works with 9.860312. Not the same

    To quick fix we can change line with FORMAT$(360/i) to something like:
    Code:
    A$="C" + FORMAT$((I MOD 15)+1) + C$ + "X"+FORMAT$(I)+"(J2 O"+FORMAT$(360/I, "0.##################") + ")"
    Then the anomaly disappears, I have to learn to live without it now.
    But it made my head hurt


    Petr
    [email protected]

    Comment

    Working...
    X