Waves

Post Reply
DrChip
Posts: 167
Joined: Wed Oct 22, 2014 3:26 pm
My devices: iPhone 4 to 6+,iPad mini to iPad air 2

Waves

Post by DrChip »

Code: Select all

rem Waves - A wave simulation
rem iPhone 6 Plus / 8.3
rem Enjoy...

size=20 'size of wave plate

pi=3.1415
gosub initialize


loop:
  refresh off
graphics clear 50/255,80/255,50/255
  gosub drawfluid
  if rnd(20)>18 then gosub drops 
  gosub fluctuate
  refresh on
goto loop
return


fluctuate:
 for x=0 to 10
  for y=0 to 10
   land(x,y)=land(x,y)+landd(x,y)
   if land(x,y)>mid then
    landd(x,y)=landd(x,y)-0.4
   else
    if land(x,y)<mid then
     landd(x,y)=landd(x,y)+0.4
    end if
   end if

   if landd(x,y)>20 then landd(x,y)=20 
   if landd(x,y)<-20 then landd(x,y)=-20 
  next y
 next x
return


drops:
  dropx=int(rnd(10))
  dropy=int(rnd(10))
  for x=dropx to dropx+1
   for y=dropy to dropy+1
    land(x,y)=land(x,y)-2
   next y
  next x
return


drawfluid:

 for y=10 to 1 step -1
  for x=1 to 10
   x1=(x*size+y*size) '-sw/2+size
   y1=(x*size/2-y*size/2)+sh/2
   if (x+y)%2=0 then
    fill color 150/255,150/255,150/255
   else
    fill color 50/255,50/255,100/255
   end if

   col1=land(x-1,y-1)+100
   col2=land(x-1,y)+100
   col3=land(x,y)+100
   col4=land(x,y-1)+100

   rem top
   fill color 0,0,col1/255
   
   'triangle x1,y1-15-land(x-1,y-1) to x1+30,y1-30-land(x-1,y) to x1+60,y1-15-land(x,y)
trix(0)=x1
triy(0)=y1-15-land(x-1,y-1)
trix(1)=x1+30
triy(1)=y1-30-land(x-1,y)
trix(2)=x1+60
triy(2)=y1-15-land(x,y)
fill poly trix,triy count 3
   
   'triangle x1,y1-15-land(x-1,y-1) to x1+60,y1-15-land(x,y) to x1+30,y1+15-land(x,y-1)
trix(0)=x1
triy(0)=y1-15-land(x-1,y-1) 
trix(1)=x1+60
triy(1)=y1-15-land(x,y)
trix(2)=x1+30
triy(2)=y1+15-land(x,y-1)
fill poly trix,triy count 3
   
   if y=1 then
    rem bottom left edge
    fill color 0,0,0
    
    'triangle x1,y1+30 to x1,y1-15-land(x-1,y-1) to x1+30,y1-land(x,y-1)
trix(0)=x1
triy(0)=y1+30
trix(1)=x1
triy(1)=y1-15-land(x-1,y-1)
trix(2)=x1+30
triy(2)=y1-land(x,y-1)
fill poly trix,triy count 3
   
    'triangle x1,y1+30 to x1+30,y1-land(x,y-1) to x1+30,y1+45
trix(0)=x1
triy(0)=y1+30
trix(1)=x1+30
triy(1)=y1-land(x,y-1)
trix(2)=x1+30
triy(2)=y1+45
fill poly trix,triy count 3
   
   end if

   if x=10 then
   rem bottom right edge
   fill color 0,0,0
   'triangle x1+30,y1+45 to x1+30,y1-land(x,y-1) to x1+60,y1-15-land(x,y)
trix(0)=x1+30
triy(0)=y1+45
trix(1)=x1+30
triy(1)=y1-land(x,y-1)
trix(2)=x1+60
triy(2)=y1-15-land(x,y)
fill poly trix,triy count 3
   
   'triangle x1+30,y1+45 to x1+60,y1-15-land(x,y) to x1+60,y1+30
trix(0)=x1+30
triy(0)=y1+45
trix(1)=x1+60
triy(1)=y1-15-land(x,y)
trix(2)=x1+60
triy(2)=y1+30
fill poly trix,triy count 3
   
   end if
  next x
 next y
return


initialize:
 graphics
 sw=screen_width()
 sh=screen_height()
 mid=10
 dim land(11,11)
 dim landd(11,11)
 for x=0 to 10
  for y=0 to 10
   land(x,y)=mid
   landd(x,y)=0
  next y
 next x
return
Attachments
image.jpg
image.jpg (85.66 KiB) Viewed 2823 times
image.jpg
image.jpg (81.9 KiB) Viewed 2823 times
image.jpg
image.jpg (75.06 KiB) Viewed 2823 times

Post Reply