It is currently Sun May 28, 2017 7:15 am



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  [ 3 posts ] 
Author Message
 Post subject: life (goes on)
Unread postPosted: Tue Apr 25, 2017 10:26 am 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 440
Trying to come up with the fastest algorithm possible to run Conway's Life in BASIC!

This one seems to do 3-4fps on my Moto g4..




Code:
! Life (goes on)
! Conway's Life in BASIC!
! mookiebearapps
w=20:h=30
GOSUB start
generate:
LET k=CLOCK()
FOR y=2 TO h-1
FOR x=2 TO w-1
  LET l=x-1:LET r=x+1:LET u=y-1:LET d=y+1
  LET t=a[l,u]+a[x,u]+a[r,u]+a[l,y]+a[r,y]+a[l,d]+a[x,d]+a[r,d]:LET n=(t=3)+(t=2)*a[x,y]:LET b[x,y]=n
  IF n<>a[x,y] THEN GR.MODIFY o[x,y],"paint",p1*n+p2*(1-n)
NEXT
NEXT
GR.RENDER

ARRAY.COPY b[],a[]
e+=CLOCK()-k:g++
GOTO generate

start:
GR.OPEN 255,0,0,0,0,1
GR.SCREEN ww,hh
qq=ww/w
GR.SET.STROKE qq
WAKELOCK 3

DIM a[w,h],b[w,h],o[w,h]

! init grid
FOR y=1 TO h
FOR x=1 TO w
  IF x>w/4 & x< w-w/4 & y>h/4 & y<h-h/4
   r=FLOOR(RND()*2)
   LET a[x,y]=r
  ENDIF
  LET c=a[x,y]
  GR.COLOR 255,0,0,255*c
  GR.POINT o[x,y],x*qq,y*qq
NEXT
NEXT
GR.RENDER

GR.COLOR 255,0,0,255
GR.PAINT.GET p1
GR.COLOR 255,0,0,0
GR.PAINT.GET p2
RETURN

ONGRTOUCH:
GR.CLOSE
PRINT STR$(1000/(e/g))+" fps"
PAUSE 3000
EXIT



Report this post
Top
 Profile  
 
 Post subject: Re: life (goes on)
Unread postPosted: Wed May 24, 2017 5:48 am 
Offline

Joined: Mon Feb 08, 2016 9:07 am
Posts: 107
Great job, cterp!

Very fast code.
4.9 fps on my Samsung Galaxy TAB A6

nobs


Report this post
Top
 Profile  
 
 Post subject: Re: life (goes on)
Unread postPosted: Wed May 24, 2017 7:17 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 440
Cool! Thanks for trying it!


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 


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