Page 1 of 1

Pseudo depth

Posted: Sun Jun 22, 2014 6:02 am
by Mr. Kibernetik
This program demonstrates depth imitation using accelerometer

Code: Select all

'pseudo depth
'by Mr.K
print "Touch me!"
pause 1
graphics
option base 1
option angle degrees
option sprite pos central
maxx=screen_width()
maxy=screen_height()
maxz=max(maxx,maxy)
aver=0.25
maxs=int(maxz/32)
dim spos(maxs,3)

graphics lock
for i=1 to maxs
  spos(i,1)=rnd(maxx)
  spos(i,2)=rnd(maxy)
  spos(i,3)=rnd(maxz)
  s=1-spos(i,3)/maxz*0.7

  sw=200*s! sh=150*s
  sprite i begin sw,sh
  draw font size 100*s
  draw color s,s,s
  fill color 0,s,0
  fill alpha 0.9
  t$=i
  tw=text_width(t$)
  th=text_height(t$)
  fill circle sw/2,sh/2 size max(tw,th)*0.5
  draw text t$ at (sw-tw)/2,(sh-th)/2
  sprite end
  sprite i at -1000,-1000
  sprite i order maxz-spos(i,3)
  sprite i show
  next i
graphics unlock

ax=accel_x()
ay=accel_y()

loop:
ax=(1-aver)*ax+aver*accel_x()
ay=(1-aver)*ay+aver*accel_y()
tx=touch_x(0)! ty=touch_y(0)
for i=1 to maxs
  z=spos(i,3)
  x=spos(i,1)-z*ax
  y=spos(i,2)-z*ay
  get sprite i angle a
  sprite i at x,y angle a
  if tx>0 and sprite_hit(str$(i),tx,ty) then
    sprite i da rnd(20)-10
    sprite i play
  end if
  next i

goto loop