BIG BEN under repair

Post Reply
smbstarv
Posts: 98
Joined: Wed Nov 27, 2013 3:44 pm
My devices: Ipad 6th gen
Flag: Netherlands
Contact:

BIG BEN under repair

Post by smbstarv »

REM ...for those who miss the Big Ben Boings.. by smbstarv, 5 oct 2017
SET ORIENTATION LANDSCAPE
IF DEVICE_TYPE$()<>"iPad" THEN
PRINT "only for iPad"
STOP
END IF
IF SYSTEM_VOLUME<.3 THEN
PRINT "turn sound on !"
PAUSE 2
END IF
SET TOOLBAR OFF
OPTION BASE 1
OPTION SPRITE POS CENTRAL
DIM vx(4),vy(4),cln(4),ns(10)
h=SCREEN_HEIGHT()
w=SCREEN_WIDTH()
GRAPHICS
GRAPHICS CLEAR 1,1,1
m=1

DRAW IMAGE "big ben.png" AT 300,100

'create 4 balls with different colors
s=100
s2=s/2
rd=s2*.99
colors:
DATA 1,0,0, 0,0,1, 1,1,0, 0,1,1
FOR i=1 TO 4
SPRITE i BEGIN s,s
READ r,g,b
FILL COLOR r,g,b
FILL CIRCLE s2,s2 SIZE rd
SPRITE END
NEXT i

'big ben notes sequence
DATA 4,0,2,-5,-5,2,4,0
FOR i=1 TO 8
READ ns(i)
NEXT i

'start position balls
DATA 900,300, 450,310, 300,500, 200,200
FOR i=1 TO 4
READ x,y
SPRITE i AT x,y
SPRITE i SHOW
NEXT i

'init balls velocity
DATA -1.5,0, 0,0.5, .5,.3, 0,.5
FOR i=1 TO 4
READ vx(i),vy(i)
NEXT i


'start moving balls
FOR i=1 TO 4
SPRITE i DX vx(i) DY vy(i)
SPRITE i DELAY 0.002
SPRITE i LOOP
NEXT i

lp1:

'if ball meets wall...
FOR i=1 TO 4
GET SPRITE i POS x,y
IF x=<rd THEN x=rd
IF x=>w-rd THEN x=w-rd
IF x=<rd OR x=>w-rd THEN
vx(i)=-vx(i)
SPRITE i AT x,y
SPRITE i DX vx(i) DY vy(i)
END IF
IF y=<rd THEN y=rd
IF y=>h-rd THEN y=h-rd
IF y=<rd OR y=>h-rd THEN
vy(i)=-vy(i)
SPRITE i AT x,y
SPRITE i DX vx(i) DY vy(i)
END IF
NEXT i


'if balls collide...
FOR i=1 TO 4
FOR j=i+1 TO 4
GET SPRITE i POS xi,yi
GET SPRITE j POS xj,yj
IF SQR((xi-xj)^2+(yi-yj)^2)<=(2*rd) THEN
IF cip(i,j) THEN BREAK j 'collision in progress !!
cip(i,j)=1
'boing !!!!
th=ns(m)
NOTES MIDI 0,12,0
NOTES MIDI 0,9,60+th,80 'typical bell sound
NOTES MIDI 1,9,72+th,80 'composed of 4 frequencies
NOTES MIDI 2,9,75+th,80 '
NOTES MIDI 3,9,84+th,80 '
m=m+1
IF m>8 THEN m=1

'calculate x- & y-velocities after collision (v2xi,v2yi, etc...)
vxi=vx(i)
vyi=vy(i)!
vxj=vx(j)
vyj=vy(j)
vi=SQR(vxi^2+vyi^2) 'velocity of ball i
vj=SQR(vxj^2+vyj^2) 'idem ball j
a=(xj-xi)/2/rd
b=(yj-yi)/2/rd
v2xi=vxj*a^2+(vyj-vyi)*a*b+vxi*b^2'x-coordinate of velocity of ball i
v2yi=vyi*a^2+(vxj-vxi)*a*b+vyj*b^2
v2xj=vxi*a^2+(vyi-vyj)*a*b+vxj*b^2
v2yj=vyj*a^2+(vxi-vxj)*a*b+vyi*b^2'y-coordinate of velocity of ball j


SPRITE i DX v2xi DY v2yi
SPRITE j DX v2xj DY v2yj
vx(i)=v2xi
vy(i)=v2yi
vx(j)=v2xj
vy(j)=v2yj

ELSE
cip(i,j)=0 'no collision in progress

END IF

NEXT j
NEXT i

tch=TOUCH_X(0) 'to stop, touch screen
IF tch>0 THEN
GRAPHICS CLEAR 0,0,0
SPRITES DELETE
SET TOOLBAR ON
STOP
END IF

GOTO lp1
Attachments
big ben.png
big ben.png (198.5 KiB) Viewed 2635 times

smbstarv
Posts: 98
Joined: Wed Nov 27, 2013 3:44 pm
My devices: Ipad 6th gen
Flag: Netherlands
Contact:

Re: BIG BEN under repair

Post by smbstarv »

A small correction added.
Link to "big ben.png" is https://www.dropbox.com/s/4c8w0tjkshhp5 ... n.png?dl=0
Attachments
BIG BEN BELLS.txt
(3.98 KiB) Downloaded 343 times

smbstarv
Posts: 98
Joined: Wed Nov 27, 2013 3:44 pm
My devices: Ipad 6th gen
Flag: Netherlands
Contact:

Re: BIG BEN under repair

Post by smbstarv »

Sorry, forgot to include corrected programtext.
Attachments
BIG BEN BELLS.txt
(3.98 KiB) Downloaded 368 times

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: BIG BEN under repair

Post by rbytes »

Thanks smbstarv...this is a fun program. My Grandma and Grandy had a clock above their fireplace that played the Westminster chimes.
The only thing that gets me down is gravity...

Post Reply