Page 1 of 1

Old school plasma program

Posted: Fri Aug 08, 2014 6:46 pm
by Henko
Ported from the basic programming forum.
Runs rather slow on iPad3, even with refresh off
Somewhat better on iPhone 5s : 0,6 fps

Code: Select all

' sdl plasma example[size=150][size=200][/size][/size] on: https://gist.github.com/stevenlr/824019
' ported to CMLua by Cybermonkey 08/2014
' ported to OxygenBasic by Peter Wirbelauer  o7.o8.2o14
' ported to X11Basic by vsync o8.o8.2o14
' ported to Smart Basic on iPhone by Henko 8/8/2014
'
bw=320 ! bh=200 ! pi=3.14
graphics ! graphics clear 1,1,1
DIM c(256,3)
FOR x=0 TO 255
  r=255-((SIN(PI*2*x/255)+1)*127)
  c(x,0)=r/256
  c(x,1)=(SIN(PI*2*x/127)+1)/4
  c(x,2)=1-r/256
NEXT x
iter:
'  refresh off
  t=TIMER()
  FOR y=0 TO bh
    FOR x=0 TO bw
      a=COS(1.2*f)*100-y+100
      b=SIN(0.8*f)*160-x+160
      ind=((SIN(x/50+f+y/200)+SIN(SQR(b*b+a*a)/50))/2+1)*127
      draw pixel x,y COLOR c(ind,0),c(ind,1),c(ind,2)
    NEXT x
    ' VSYNC
  NEXT y
  fps=1000/(TIMER()-t)
  draw TEXT "fps= " & fps at 8,24
  f=f+0.2
' refresh
  goto iter
stop ! end

Re: Old school plasma program

Posted: Sat Aug 09, 2014 4:14 am
by Mr. Kibernetik
Very interesting!
I made it a little bit faster:

Code: Select all

' sdl plasma example on: https://gist.github.com/stevenlr/824019
' ported to CMLua by Cybermonkey 08/2014
' ported to OxygenBasic by Peter Wirbelauer  o7.o8.2o14
' ported to X11Basic by vsync o8.o8.2o14
' ported to Smart Basic on iPhone by Henko 8/8/2014
'
bw=320 ! bh=200 ! pi=3.14
graphics ! graphics clear 1,1,1
DIM r(256),g(256),b(256)
FOR x=0 TO 255
  r(x)=(255-(SIN(PI*2*x/255)+1)*127)/256
  g(x)=(SIN(PI*2*x/127)+1)/4
  b(x)=1-r(x)
NEXT x
'refresh off
k3=sqr(35600)/50
iter:
  timer reset
  k1=COS(1.2*f)+1
  k2=SIN(0.8*f)+1
  FOR y=0 TO bh
    FOR x=0 TO bw
      ind=SIN(x/50+f+y/200+SIN(abs(k1-y/100+(k2-x/160)*1i)*k3))*63.5+127
      draw pixel x,y COLOR r(ind),g(ind),b(ind)
    NEXT x
    ' VSYNC
  NEXT y
  fps=1000/TIMER()
  draw TEXT "fps= " & fps at 8,24
  f+=0.2
  'refresh
  goto iter

Re: Old school plasma program

Posted: Sat Aug 09, 2014 10:25 pm
by Operator
Nice Plasma : )
Just faked the speed, but at least it is now animated
(~5 fps on iPhone4)

Code: Select all

  Code:
' sdl plasma example on: https://gist.github.com/stevenlr/824019
' ported to CMLua by Cybermonkey 08/2014
' ported to OxygenBasic by Peter Wirbelauer  o7.o8.2o14
' ported to X11Basic by vsync o8.o8.2o14
' ported to Smart Basic on iPhone by Henko 8/8/2014
'
bw=160 ! bh=100 ! pi=3.1415
graphics ! graphics clear 1,1,1
DIM r(256),g(256),b(256)
k3=sqr(35600)/50
draw font size 10

FOR x=0 TO 255
  r(x)=(255-(SIN(PI*3*x/255)+1)*127)/256
  g(x)=(SIN(PI*2*x/127)+1)/4
  b(x)=1-r(x)
NEXT x

refresh off
iter:
  timer reset
  k1 = COS(1.2*f)+1
  k2 = 1-k1

  FOR y =0 TO bh step 5
    FOR x =0 TO bw step 5
      ind=SIN(x/50+f+y/200+SIN(abs(k1-y/100+(k2-x/160)*1i)*k3))*63.5+127

     'draw pixel x,y COLOR r(ind),g(ind),b(ind)
      fill COLOR r(ind),g(ind),b(ind)
      fill rect x,y size 3
    NEXT x
    ' VSYNC
  NEXT y

  fps = 1000/TIMER()
  draw TEXT "fps= " & fps at 8,8
  f += 0.15
  refresh
  goto iter

Re: Old school plasma program

Posted: Sun Aug 10, 2014 8:26 am
by Henko
Nice mod! Runs at 41 fps on 5S. Made full screen (320x520) it still runs at 5.1 fps, which is a nice speed for a dynamic plasma clip.