It is currently Wed Jun 28, 2017 12:21 pm



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 33 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: Some functions and tricks
Unread postPosted: Sat Oct 27, 2012 8:08 pm 
Offline
User avatar

Joined: Sat Jun 04, 2011 2:29 pm
Posts: 188
Hello to all people.
I'm try to collect some functions or tricks in the forum and put here with the original link.

Please don't ask questions in this post, use:
http://rfobasic.freeforums.org/questions-or-comments-about-basic-f4.html
to make your question. ;)

If you have some trick or function to share post it here, if you want.
Have a happy day.


I want to make an index for organizing this thread.
Page one
Post #2:
*_Function to trim leading spaces from a string. *_Function for an int. *_If you need pi. *_Number odd or even?
Post #3:
*_Function 5 stars
Post #4:
Post #5:
*_Reference Object Variable
Post #6:
*_Function Return array[]. *_Set print decimals to ,,,(comma). *_Interrupt Timer.
*_Print command. Is there a trick to display horizontally?
Post #7:
*_Function called "Cartman as Roadrunner"
Post #8:
*_This is a function to print large numbers.
Post #9:
*_Tutorial Basic! online.
Post #10:
*_Function will sort a 2D Numeric Array.


Page two
Post #1 #2:
*_Some Date Functions
Post #3 #4:
Post #5:
*_Basic Formula-parser
Post #6:
*_Function for drawing round rectangles, *_Rounded-bicolor button
Post #7:
*_Function allows to transform a number into a string
Post #8:
*_Function to create a pie chart
Post #9:
*_WAIT Command, *_ Put more entries with the INPUT command
Post #10:
*_Copy Files and Directories, *_Copy a directory full of files

Page three
Post #:
Post #:
Post #:
Post #:
Post #:
Post #:
Post #:
Post #:


Last edited by IAO on Thu Apr 10, 2014 7:23 am, edited 27 times in total.

Top
 Profile  
 
 Post subject: Re: Some functions and trics
Unread postPosted: Sat Oct 27, 2012 8:08 pm 
Offline
User avatar

Joined: Sat Jun 04, 2011 2:29 pm
Posts: 188
Function to trim leading spaces from a string.
Original Link: http://rfobasic.freeforums.org/post2922.html?hilit=trim#p2922
Code:
Fn.def TRIM$ (e$)
  t$ = e$
  WHILE LEFT$(t$, 1) = " "
    t$ = RIGHT$(t$, LEN(t$) - 1)
  REPEAT
  WHILE RIGHT$(t$, 1) = " "
    t$ = LEFT$(t$, LEN(t$) - 1)
  REPEAT
  Fn.rtn t$
Fn.end


;==========================================================
Function for an int.
Original Link: http://rfobasic.freeforums.org/post4754.html?hilit=integer#p4754
Code:
fn.def int(v)
if v<0 then
   fn.rtn Ceil(v)
   else
   fn.rtn floor(v)
fn.end

! test
for i=1 to 10
v=(rnd()*50)-25
print v
print int(v)
next i


;==========================================================
If you need pi
Original Link: No found.
Code:
pi=ATAN(1)*4


;==========================================================
Number odd or even?
Original Link: http://rfobasic.freeforums.org/post3093.html?hilit=%20function#p3093
Code:
Try:
if ceil(number/2)=number/2 then ...... (number is even - otherwise it is odd)
___________________
Probably better:
if mod(number,2)=0 then ............ (number is even - otherwise it is odd)


Last edited by IAO on Tue Oct 30, 2012 6:54 am, edited 12 times in total.

Top
 Profile  
 
 Post subject: Re: Some functions and tricks
Unread postPosted: Mon Oct 29, 2012 2:15 am 
Offline
User avatar

Joined: Mon Oct 17, 2011 9:34 am
Posts: 891
I'll give you 5 stars for your initiative! :mrgreen: , i mean it ;) :
Code:
! star from x,y (upper left) to x+a,y+1.25*a (lower right)
! by tony_gr
! Oct.29.2012
! Basic v1.68

FN.DEF star(x,y,a)
  LIST.CREATE n,stella
  LIST.ADD stella, x,y+a*0.5, x+a*0.3125,y+a*0.5, x+a*0.5,y
  LIST.ADD stella, x+a*0.6875,y+a*0.5, x+a,y+a*0.5, x+a*0.75,y+a*0.75
  LIST.ADD stella, x+a,y+1.25*a, x+a*0.5,y+a*0.875, x,y+1.25*a,x+a*0.25,y+a*0.75
  GR.POLY sObj, stella
  FN.RTN stella
FN.END

! main
GR.OPEN 255,0,0,0,0,1
GR.ORIENTATION 1
GR.SCREEN w,h
sx=w/800
sy=h/1232
GR.SCALE sx,sy

! draw 5 stars
FOR i=1 TO 5
  GR.COLOR 255,50*i,255-50*i,155,1
  x=70*(i-1)
  y=100
  a=30+i*10
  z=star(x,y,a) % function call
NEXT i
GR.RENDER

DO
UNTIL 0

I've created a dir in "Other" named "Tricks". Place there your tricks too, if you want.
http://laughton.com/basic/programs/other/Tricks/

_________________
Check out my RFO Basic! apps & games: Image, on Google Play Store! Slide me!, Amazon, or AppsLib!


Top
 Profile  
 
 Post subject: Re: Some functions and tricks
Unread postPosted: Mon Oct 29, 2012 3:48 pm 
Offline
User avatar

Joined: Sat Jun 04, 2011 2:29 pm
Posts: 188
Hi...
This is a function to print large numbers. It is a beta function.
I'm improving it. If someone has something better is welcome.

Code:
I deleted this code. It is very ugly.


Please see this post below. (Post Number 8).
Wonderful function, elegant, compact.
Quote:
Tony_gr:
I wrote a more generic and elegant function to display big numbers

http://rfobasic.freeforums.org/post6081.html#p6081


Last edited by IAO on Tue Apr 08, 2014 6:15 am, edited 8 times in total.

Top
 Profile  
 
 Post subject: Re: Some functions and tricks
Unread postPosted: Tue Oct 30, 2012 7:10 am 
Offline
User avatar

Joined: Sat Jun 04, 2011 2:29 pm
Posts: 188
Hi...

Reference Object Variable (You may use a list to save the created pointers for later use)
Original Link: http://rfobasic.freeforums.org/post4717.html?hilit=FN.DEF#p4717
Code:
FN.DEF  Build(left, top)
GR.RECT objpointer, left, top, left+200, top+50
FN.RTN objPointer
FN.END

LIST.CREATE N, Pointers

GR.OPEN 255,0,0,0,0,1
PAUSE 1000
GR.COLOR 255,255,255,0,0
Left=0
Top=0
FOR i=1 TO 5
Pointer=Build(Left,Top)
LIST.ADD Pointers,Pointer
NEXT i

LIST.SIZE Pointers,Lsize
FOR i=1 TO Lsize
newTop=i*5
newLeft=i*10
newRight=200-i*5
newBottom=50-i*3
LIST.GET Pointers,i, objectP
GR.MODIFY objectP,"left",newLeft
GR.MODIFY objectP,"top",newTop
GR.MODIFY objectP,"right",newRight
GR.MODIFY objectP,"bottom",newBottom
NEXT i
GR.RENDER
DO
UNTIL 0


Last edited by IAO on Tue Oct 30, 2012 7:19 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Some functions and tricks
Unread postPosted: Tue Oct 30, 2012 7:18 am 
Offline
User avatar

Joined: Sat Jun 04, 2011 2:29 pm
Posts: 188
Hi...

Function Return array[]
Original Link:http://rfobasic.freeforums.org/post4740.html?hilit=fn.def#p4740
Code:
fn.def demo(a[])
a[2] = 10
fn.end

array.load z[], 1, 2, 3

print z[2]
call demo(z[])
print z[2]
end


;==========================================================
Set print decimals to ,,,(comma)
Original Link:http://rfobasic.freeforums.org/post2650.html?hilit=%20def#p2650
Code:
Fn.def Stg$(c)
  Fn.rtn Left$(Str$(c),Is_In(".",Str$(c))-1)
Fn.end


;==========================================================
Interrupt Timer
Original Link: http://rfobasic.freeforums.org/interrupt-timer-t1031-10.html
Code:
n = 0
timer.set 3000

do
until n = 3

timer.clear
Print "Timer cleared. No further interrupts."
do
until 0

onTimer:
n = n + 1
print n*3; " seconds"
timer.resume


;==========================================================
Print command. Is there a trick to display horizontally?
Original Link: http://rfobasic.freeforums.org/print-command-question-t600.html?hilit=print
Code:
for i = 1 to 10
  print i;
  next i
print ""



;==========================================================
Thanks Mr. toni_gr for their support. ;)
Mr. tony_gr, if you see an error and you want to correct it or improve post, please do. ;)


Top
 Profile  
 
 Post subject: Re: Some functions and tricks
Unread postPosted: Thu Nov 08, 2012 12:48 pm 
Offline
User avatar

Joined: Mon Oct 17, 2011 9:34 am
Posts: 891
My newest function is called "Cartman as Roadrunner" :mrgreen:
You've seen how Roadrunner moves:

Code:
! CartmanAsRoadrunner
! by tony_gr
! basic! v1.69

FN.DEF CartmanAsRoadrunner (x,y,r)
GR.BITMAP.LOAD cc,"cartman.png"
AUDIO.LOAD au,"whee.mp3"
GR.BITMAP.DRAW c,cc,x+r,y
GR.RENDER
PAUSE 500
FOR k=1 TO 5
  FOR i=0 TO 2*3.14159 STEP 0.25
   myX=(x+r*COS(i))
   myY=(y+r*SIN(i))
   GR.MODIFY c,"x", myX
   GR.MODIFY c,"y", myY
   GR.RENDER
   PAUSE 10
  NEXT i
NEXT k
AUDIO.PLAY au
FOR l=MyX TO 880 STEP 25
  GR.MODIFY c,"x", l
  GR.RENDER
NEXT
FN.END


! main
GR.OPEN 255,0,0,0,0,1
GR.ORIENTATION 1
GR.SCREEN w,h
sx=w/800
sy=h/1232
GR.SCALE sx,sy

CALL CartmanAsRoadrunner(150,500,100)

DO
UNTIL 0

_________________
Check out my RFO Basic! apps & games: Image, on Google Play Store! Slide me!, Amazon, or AppsLib!


Top
 Profile  
 
 Post subject: Re: Some functions and tricks
Unread postPosted: Sun Dec 02, 2012 10:35 am 
Offline
User avatar

Joined: Mon Oct 17, 2011 9:34 am
Posts: 891
Quote:
This is a function to print large numbers. It is a beta function. I'm improving it. If someone has something better is welcome.

I was thinking about this. It's useful not only in math programs, but also in games.
Consider a player that has more than 999999999 points. What to tell him, that he has
1E07 points? :mrgreen:
I wrote a more generic and elegant function to display big numbers:

Code:
! big numbers by tony_gr
! basic! v1.71

FN.DEF bigNumbers$(number)
a$=FORMAT$("#####################.################",number)
a$=REPLACE$(a$," ","") % trim leading spaces
! trim ending 0s of decimal numbers
a=IS_IN(".", a$)
IF a>0 THEN
  l=LEN(a$)
  DO
   d$=MID$(a$,l,1)
   IF d$="0" THEN a$=LEFT$(a$,l-1)
   l=l-1
  UNTIL MID$(a$,l,1)<>"0"
  IF ABS(number)<1 THEN a$=REPLACE$(a$,".","0.")
ENDIF
FN.RTN a$
FN.END

! test
num= 1234567890123.0123456
PRINT num
s$= bigNumbers$(num)
PRINT s$

num= -0.0123456
PRINT num
s$= bigNumbers$(num)
PRINT s$
END



And before having any objections on basic!s arithmetics please take a look
at the "Numbers" section in the manual...

_________________
Check out my RFO Basic! apps & games: Image, on Google Play Store! Slide me!, Amazon, or AppsLib!


Top
 Profile  
 
 Post subject: Re: Some functions and tricks
Unread postPosted: Sun Dec 09, 2012 3:57 pm 
Offline
User avatar

Joined: Sat Jun 04, 2011 2:29 pm
Posts: 188
Hi...
@tony_gr:
Wonderful function, elegant, compact. I'm surprised, congratulations.

;==========================
Tutorial Basic! online.
http://rfobasic.com/
Original link: http://rfobasic.freeforums.org/post4573.html#p4573


Top
 Profile  
 
 Post subject: Re: Some functions and tricks
Unread postPosted: Thu Jan 17, 2013 7:20 am 
Offline

Joined: Sun Jan 22, 2012 3:38 pm
Posts: 19
The Function below will sort a 2D Numeric Array:
Code:
Fn.Def QuickSort(A[], SCol, ACols, ARows, D]
   !SCol is Column to be sorted on
   !ACols is number of Columns in Array
   !ARows is number of Rows in Array
   !D is Sort Direction 0 = Desc, 1 = Asc

    I = 1
    J = ARows
    X = A[(1 + ARows) / 2, SCol]
    If D Then
        While (I <= J)
            While (A[I, SCol] < X & I < ARows)
                I = I + 1
            Repeat
            While (X < A[J, SCol] & J > 1)
                J = J - 1
            Repeat
            If (I <= J) Then
                For C = 1 To ACols
                    Y = A[I, C]
                    A[I, C] = A[J, C]
                    A[J, C] = Y
                Next
                I = I + 1
                J = J - 1
            End If
        Repeat
    Else
        While (I <= J)
            While (A[I, SCol] > X & I < ARows)
                I = I + 1
            Repeat
            While (X > A[J, SCol] & J > 1)
                J = J - 1
            Repeat
            If (I <= J) Then
                For C = 1 To ACols
                    Y = A[I, C]
                    A[I, C] = A[J, C]
                    A[J, C] = Y
                Next
                I = I + 1
                J = J - 1
            End If
        Repeat
    End If
    If (J > 1) Then Call QuickSort(A[], SCol, 1, J, D)
    If (ARows > I) Then Call QuickSort(A[], SCol, I, ARows, D)
Fn.End


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 33 posts ]  Go to page 1, 2, 3, 4  Next


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
suspicion-preferred