You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
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
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:
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
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: