It is currently Tue May 23, 2017 1:54 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  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: digital confetti
Unread postPosted: Thu Apr 07, 2016 12:30 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 437
Simple little demo of moving pixels.... seems really fast in v.1.90!

Zig zag mode is a bit dizzying so please don't use it if you have problems with epilepsy!



Code:
! digital confetti
! moving dots demo
!
!
! WARNING: zigzag mode is probably not good for people with epileptic disorders
!
!
! zigzag mode shifts the velocities when a dot hits the screen edge

FN.DEF rand(a,b)
DO
  LET x=RND()*(b-a)+a
UNTIL ABS(x)>=1
FN.RTN x
FN.END

FN.DEF tint()
FN.RTN FLOOR(RND()*100)+50
FN.END


DIALOG.MESSAGE "confetti","select mode",zigzag,"zigzag","normal"


GR.OPEN 255,0,0,0,0
GR.ORIENTATION 1
GR.SCREEN w,h
w+=10
h+=10
POPUP "touch or drag screen to create moving dots"

LIST.CREATE n,pp
LIST.CREATE n,pv

GR.SET.STROKE 10

DO

GR.TOUCH tt,x,y
IF tt
  LET vx=rand(-10,10)
  LET vy=rand(-10,10)

  GR.COLOR 255,tint(),tint(),tint()

  GR.POINT p,x,y
  GR.SHOW p
  LIST.ADD pp,p
  LIST.ADD pv,vx,vy
ENDIF

mv:
LIST.SIZE pp,z

LET i=1
DO
  IF i<=z & z
   LET j=2*(i-1)+1
   LIST.GET pp,i,q
   GR.GET.POSITION q,qx,qy
   IF qx<-10 | qx>w| qy<-10|qy>h
    LIST.REMOVE pp,i

    IF zigzag<>1
     LIST.REMOVE pv,j
     LIST.REMOVE pv,j
    ENDIF
    z--
   ELSE
    LIST.GET pv,j,dx
    LIST.GET pv,j+1,dy
    GR.MOVE q,dx,dy
   ENDIF
  ENDIF
  i++

UNTIL i>z

GR.RENDER
!timing ---------------
LET toc=CLOCK()-tic
PAUSE MAX(20-toc,1)
LET tic=CLOCK()
UNTIL 0


Report this post
Top
 Profile  
 
 Post subject: Re: digital confetti
Unread postPosted: Thu Apr 07, 2016 12:35 pm 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5518
Location: Paris, France
Drunk pixels :lol:
Very well done Chris! I love it ;)

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: digital confetti
Unread postPosted: Thu Apr 07, 2016 4:02 pm 
Offline
User avatar

Joined: Tue Sep 13, 2011 4:58 am
Posts: 721
Location: Sao Paulo, Brasil
pokemon style warning. Very good!

_________________
Alfredo Peine

-------------

Hisense Sero 7 Pro (Tegra 3 7" rooted tablet - Android 4.4.4) / Moto G 3rd Gen (5" quad core rooted phone - Android 6.0).


Report this post
Top
 Profile  
 
 Post subject: Re: digital confetti
Unread postPosted: Thu Apr 07, 2016 5:47 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 437
This version is a bit zippier. I took out the timing statements too because I figured it would slow down anyways as there are more and more pixels added.

Anybody see any other speed optimizations?

Code:
DIALOG.MESSAGE "confetti","select mode",c,"zigzag","normal"
nm=(c<>1)


GR.OPEN 255,0,0,0,0
GR.ORIENTATION 1
GR.SCREEN w,h
w+=9:h+=9
POPUP "touch or drag screen to create moving dots"

LIST.CREATE n,pp
LIST.CREATE n,pv

GR.SET.STROKE 9
GR.SET.ANTIALIAS 0

DO
GR.TOUCH tt,x,y
IF tt
  LET vx=RND()*9+1:LET vy=RND()*9+1
  IF RND()>0.5 THEN vx=-vx
  IF RND()>0.5 THEN vy=-vy
  LET r=FLOOR(RND()*99)+50
  LET g=FLOOR(RND()*99)+50
  LET b=FLOOR(RND()*99)+50
  GR.COLOR 255,r,g,b
  GR.POINT p,x,y:GR.SHOW p
  LIST.ADD pp,p:LIST.ADD pv,vx,vy
ENDIF

LIST.SIZE pp,z:LET i=0
DO
  IF i<z
   LET j=2*i+1
   LIST.GET pp,i+1,q
   GR.GET.POSITION q,qx,qy
   IF qx<-9|qx>w|qy<-9|qy>h
    LIST.REMOVE pp,i+1
    GR.HIDE q
    IF nm
     LIST.REMOVE pv,j
     LIST.REMOVE pv,j
    ENDIF
    z--
   ELSE
    LIST.GET pv,j,dx
    LIST.GET pv,j+1,dy
    GR.MOVE q,dx,dy
   ENDIF
  ENDIF
  i++
UNTIL i>=z
GR.RENDER
UNTIL 0


Report this post
Top
 Profile  
 
 Post subject: Re: digital confetti
Unread postPosted: Thu Apr 07, 2016 6:20 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 437
The v1.90 apk is still pretty small at 487Kb.... nice job guys at keeping BASIC! lean and mean!

http://laughton.com/basic/programs/games/confetti/


Report this post
Top
 Profile  
 
 Post subject: Re: digital confetti
Unread postPosted: Thu Apr 07, 2016 10:44 pm 
Offline

Joined: Sat Dec 22, 2012 2:32 pm
Posts: 830
Pretty nice and fast! Maybe you can get a little accel by replacing the out-of-screen condition by a GR_COLLISION:

Code:
GR.RECT screen , -9,-9,w,h
...

IF  GR_COLLISION(q,screen)   % qx<-9|qx>w|qy<-9|qy>h
    LIST.GET pv,j,dx
    LIST.GET pv,j+1,dy
    GR.MOVE q,dx,dy
   ELSE
    LIST.REMOVE pp,i+1
    GR.HIDE q
    IF nm
     LIST.REMOVE pv,j
     LIST.REMOVE pv,j
    ENDIF
    z--
   ENDIF
  ENDIF




or even replace the whole if-contruct by to subs
Code:
gosub  GR_COLLISION(q,screen) +1  remove, move


...but just a gues, didn't check. Differences will be small anyway, so don't know if worth it...


regards, brochi


Report this post
Top
 Profile  
 
 Post subject: Re: digital confetti
Unread postPosted: Thu Apr 07, 2016 10:59 pm 
Offline
User avatar

Joined: Sat Oct 04, 2014 5:45 am
Posts: 639
Really nice demo Cterp

MouGikPein wrote:
We don't drink no more, we are now in the balancing business
:lol:

_________________
Download and tutorial for RFODESIGNER
https://sites.google.com/site/rfodesigner/


Report this post
Top
 Profile  
 
 Post subject: Re: digital confetti
Unread postPosted: Sat Apr 09, 2016 4:14 am 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 437
Thanks brochi-- The rect collision doesn't work I don't think because GR_COLLISION goes by the boundaries so it always registers a collision..

I am not sure BASIC! is similar to Atari BASIC ... I remember in Atari BASIC that you could speed up programs somewhat by replacing numeric constants with variables. Not sure if this helps in BASIC! too but I tried it and it seems pretty zippy.

ALSO... I allowed the pixel size to be changed... Wanna see something cool? Try a pixel size of 150 to 200

check it out: https://youtu.be/rbb8lJKgOgU


Code:
! digital confetti
! moving pixels

input "pixel size",pz,8

DIALOG.MESSAGE "confetti","select mode",c,"zigzag","normal"
nm=(c<>1)

GR.OPEN 255,0,0,0,0
GR.ORIENTATION 1
GR.SCREEN w,h
w+=5:h+=5:e=-5
POPUP "touch or drag screen to create moving dots"
LIST.CREATE n,l:LIST.CREATE n,v
GR.SET.STROKE pz
GR.SET.ANTIALIAS 0
br=50:hh=99:p5=0.5:a=255:mv=10
DO
GR.TOUCH t,x,y
IF t
  LET vx=FLOOR(RND()*mv+1)
  LET vy=FLOOR(RND()*mv+1)
  IF RND()>p5 THEN vx=-vx
  IF RND()>p5 THEN vy=-vy
  LET r=FLOOR(RND()*hh)+br
  LET g=FLOOR(RND()*hh)+br
  LET b=FLOOR(RND()*hh)+br
  GR.COLOR a,r,g,b
  GR.POINT p,x,y:GR.SHOW p
  LIST.ADD l,p:LIST.ADD v,vx,vy
ENDIF

LIST.SIZE l,z:LET i=0
DO
  IF i<z
   LET j=2*i+1:LIST.GET l,i+1,q
   GR.GET.POSITION q,x,y
   IF x<e|x>w|y<e|y>h
    LIST.REMOVE l,i+1:GR.HIDE q
    IF nm
     LIST.REMOVE v,j:LIST.REMOVE v,j
    ENDIF
    z--
   ELSE
    LIST.GET v,j,dx:LIST.GET v,j+1,dy:GR.MOVE q,dx,dy
   ENDIF
  ENDIF
  i++
UNTIL i>=z
GR.RENDER
UNTIL 0


Report this post
Top
 Profile  
 
 Post subject: Re: digital confetti
Unread postPosted: Sun Apr 10, 2016 1:41 am 
Offline

Joined: Sat Dec 22, 2012 2:32 pm
Posts: 830
...i meant like this (...+some other things ).

regards, brochi


Code:
INPUT "pixel size",pz,8

DIALOG.MESSAGE "confetti","select mode",c,"zigzag","normal"
nm=(c<>1)


pz =8

GR.OPEN 255,0,0,0,0
GR.ORIENTATION 1
GR.SCREEN w,h
w+=5:h+=5:e=-5
POPUP "touch or drag screen to create moving dots"
LIST.CREATE n,l :LIST.CREATE n,lvx :LIST.CREATE n,lvy
GR.SET.STROKE pz
GR.SET.ANTIALIAS 0
br=50:hh=99:p5=0.5:a=255:mv=20
GR.RECT screen,0,0,w,h

DIM tbuffer[30]


DO

tic              = CLOCK()


GR.TOUCH           t,x,y

IF                 t
  GR.COLOR          a, RND()*hh+br , RND()*hh+br , RND()*hh+br
  GR.POINT          p,x,y
  LIST.ADD          l,p
  LIST.ADD          lvx, RND()*mv-10 :LIST.ADD lvy, RND()*mv-10
ENDIF

LIST.SIZE          l,z
max              = z


FOR i            = 1 TO z

  ii              = MIN(max,i)
  LIST.GET          l,ii,q

  IF                GR_COLLISION(q,screen)

   LIST.GET         lvx,ii,dx
   LIST.GET         lvy,ii,dy
   GR.MOVE          q,dx,dy

  ELSE

   GR.HIDE          q
   LIST.REMOVE      l,ii   
   LIST.REMOVE      lvx,ii
   LIST.REMOVE      lvy,ii
   max--

  ENDIF

NEXT

tbuffer[MOD(ctr++,30)+1] = CLOCK()-tic
ARRAY.AVERAGE      tavg, tbuffer[]
PRINT              INT$(ctr), ROUND(tavg,1), INT$(z)


GR.RENDER

UNTIL 0



Report this post
Top
 Profile  
 
 Post subject: Re: digital confetti
Unread postPosted: Sun Apr 10, 2016 3:27 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 437
Thanks brochi! Yeah, it never occurred to me to use the RECT screen collision the other way around. Cool!

I commented out your timing statements and added an offset so that the pixels have at least a minimum velocity of 1.

Super zippy now! Awesome.



Code:
REM Start of BASIC! Program
INPUT "pixel size",pz,8

DIALOG.MESSAGE "confetti","select mode",c,"zigzag","normal"
nm=(c<>1)

GR.OPEN 255,0,0,0,0
GR.ORIENTATION 1
GR.SCREEN w,h
w+=5:h+=5:e=-5
POPUP "touch or drag screen to create moving dots"
LIST.CREATE n,l :LIST.CREATE n,lvx :LIST.CREATE n,lvy
GR.SET.STROKE pz
GR.SET.ANTIALIAS 0
br=50:hh=99:p5=0.5:a=255:mv=10
GR.RECT screen,0,0,w,h

!DIM tbuffer[30]
DO

!tic              = CLOCK()
GR.TOUCH           t,x,y

IF                 t
  GR.COLOR          a, RND()*hh+br , RND()*hh+br , RND()*hh+br
  GR.POINT          p,x,y
  LIST.ADD          l,p
  LIST.ADD          lvx, SGN(RND()-0.5)*(RND()*mv+1):LIST.ADD lvy, SGN(RND()-0.5)*(RND()*mv+1)
ENDIF

LIST.SIZE          l,z
max              = z


FOR i            = 1 TO z

  ii              = MIN(max,i)
  LIST.GET          l,ii,q

  IF                GR_COLLISION(q,screen)

   LIST.GET         lvx,ii,dx
   LIST.GET         lvy,ii,dy
   GR.MOVE          q,dx,dy

  ELSE

   GR.HIDE          q
   LIST.REMOVE      l,ii   
   IF nm
    LIST.REMOVE      lvx,ii
    LIST.REMOVE      lvy,ii
   ENDIF
   max--

  ENDIF

NEXT

!tbuffer[MOD(ctr++,30)+1] = CLOCK()-tic
!ARRAY.AVERAGE      tavg, tbuffer[]
!PRINT              INT$(ctr), ROUND(tavg,1), INT$(z)


GR.RENDER

UNTIL 0


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next


Who is online

Users browsing this forum: No registered users and 0 guests


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:  
suspicion-preferred