Code: Select all
rem "shocking" demo
rem im still working on it.
rem iPhone 6 Plus / iOS 8.3 b2
'This one uses a simple perspective transformation to create a shimmering effect similar to being submerged
'The Gem object is about the most complex so far at 50fps, it has 40 faces and 34 Vertices.
'sorry for the bubbles, they look a bit ropey.
gosub initialize
do
refresh off
gosub swap
gosub rotate
gosub construct
draw color (155+blu)/255,1,1
draw text "SHOCKING DEMO!" at 0,sh-20
refresh on
until 1=2
swap:
mm=mm+.1
red=10+10*sin(mm/2)
grn=10+10*sin(mm/2)
blu=60+60*cos(mm/3)
fill color red/255,0,blu/255
trix(0)=0
triy(0)=101
trix(1)=sw
triy(1)=sh
trix(2)=0
triy(2)=sh
fill poly trix,triy count 3
trix(0)=0
triy(0)=101
trix(1)=sw
triy(1)=sh
trix(2)=sw
triy(2)=101
fill poly trix,triy count 3
'line
fill color 1,1,1
fill rect 0,sh-24 to sw,sh-22
'bubbles
fill color 155/255,155/255,1
for a=1 to 19
fill rect bx(a),by(a) to bx(a)+2,by(a)+2
by(a)=by(a)-rnd(10)
bx(a)=bx(a)-5+rnd(10)
if by(a)<102 then by(a)=sh-22
next a
return
'Draw The Object
construct:
for a=1 to faces
gosub draw
next a
return
'Draw A Face Of The Object;
draw:
vx1= tx(f1(a))-tx(f2(a))
vy1= ty(f1(a))-ty(f2(a))
vx2= tx(f3(a))-tx(f2(a))
vy2= ty(f3(a))-ty(f2(a))
n= vx1*vy2-vx2*vy1
if n<0 then
n=-(n/400)
if n>120 then n=120
fill color (r(a)+n)/255,(g(a)+n)/255,(b(a)+n)/255
'fill triangle tx(f1(a)),ty(f1(a)) to tx(f2(a)),ty(f2(a)) to tx(f3(a)),ty(f3(a))
trix(0)=tx(f1(a))
triy(0)=ty(f1(a))
trix(1)=tx(f2(a))
triy(1)=ty(f2(a))
trix(2)=tx(f3(a))
triy(2)=ty(f3(a))
fill poly trix,triy count 3
'fill triangle tx(f1(a)),ty(f1(a)) to tx(f4(a)),ty(f4(a)) to tx(f3(a)),ty(f3(a))
trix(0)=tx(f1(a))
triy(0)=ty(f1(a))
trix(1)=tx(f4(a))
triy(1)=ty(f4(a))
trix(2)=tx(f3(a))
triy(2)=ty(f3(a))
fill poly trix,triy count 3
if cls(a)=1 then
draw color 0,0,0
draw line tx(f1(a)),ty(f1(a)) to tx(f2(a)),ty(f2(a))
draw line tx(f2(a)),ty(f2(a)) to tx(f3(a)),ty(f3(a))
draw line tx(f3(a)),ty(f3(a)) to tx(f4(a)),ty(f4(a))
draw line tx(f4(a)),ty(f4(a)) to tx(f1(a)),ty(f1(a))
end if
end if
return
rotate:
'Rotate And Scale Each Point Store Result
for a=1 to points
x1=x(a)
y1=y(a)
z1=z(a)
'X,Y,Z rotations
xx=x1
yy=y1*cs(xr)+z1*sn(xr)
zz=z1*cs(xr)-y1*sn(xr)
y1=yy
x1=xx*cs(yr)-zz*sn(yr)
z1=xx*sn(yr)+zz*cs(yr)
zz=z1
xx=x1*cs(zr)-y1*sn(zr)
yy=x1*sn(zr)+y1*cs(zr)
'Apply Perspective
dv=(zz/40)+1
xx=size*(xx/dv)+sw/2
yy=size*(yy/dv/2)+sh/2
tx(a)=xx
ty(a)=yy
tz(a)=zz
next a
xr=xr+3
yr=yr+2
zr=zr+7
if xr>720 then xr=xr-720
if yr>720 then yr=yr-720
if zr>720 then zr=zr-720
return
initialize:
graphics
pi=3.1415
sw=screen_width()
sh=screen_height()
'Put Logo On Logical And Physical Screens
for a=1 to 2
'Logo Background
fill color 1,1,1
'triangle 0,0 to sw,100 to 0,100
trix(0)=0
triy(0)=0
trix(1)=sw
triy(1)=100
trix(2)=0
triy(2)=100
fill poly trix,triy count 3
'triangle 0,0 to sw,100 to sw,0
trix(0)=0
triy(0)=0
trix(1)=sw
triy(1)=100
trix(2)=sw
triy(2)=0
fill poly trix,triy count 3
fill color 1,1,1
fill rect 0,100 to sw,97
'Logo Image
fill color 10/255,160/255,90/255
's
fill rect 10,10 to 70,20
fill rect 10,90 to 70,80
fill rect 10,45 to 70,55
fill rect 10,10 to 20,55
fill rect 70,55 to 60,90
fill rect 70,45 to 50,90
'h
fill rect 80,10 to 90,90
fill rect 140,10 to 130,90
fill rect 140,45 to 80,55
fill rect 80,45 to 100,90
'o
fill rect 150,10 to 210,20
fill rect 150,90 to 210,80
fill rect 150,10 to 160,90
fill rect 210,10 to 200,90
fill rect 150,45 to 170,90
'c
fill rect 220,10 to 280,20
fill rect 220,90 to 280,80
fill rect 220,10 to 230,90
fill rect 220,45 to 240,90
'k
fill rect 290,10 to 300,90
fill rect 290,45 to 350,55
fill rect 350,45 to 330,90
fill rect 320,10 to 330,45
'i
fill rect 360,10 to 370,90
fill rect 360,45 to 380,90
'n
fill rect 400,10 to 410,90
fill rect 450,10 to 460,90
fill rect 410,45 to 420,90
fill rect 400,10 to 460,20
'g
fill rect 480,10 to 490,90
fill rect 480,10 to 535,20
fill rect 490,45 to 500,90
fill rect 540,50 to 530,90
fill rect 480,80 to 535,90
fill rect 525,50 to 530,60
next a
'Define the necessary variables
size=20 ' how big do you want it?
points=34 ' The amount of points in the object
faces=40 ' The Amount of faces in the object
dim bx(20) ' Bubble X Storage.
dim by(20) ' Bubble Y Storage
for a=1 to 19 ' Define bubble positions.
bx(a)=rnd(sw)
by(a)=102+rnd(sh)
next a
dim x(points+1) 'Original X co-ordinate store
dim y(points+1) 'Original Y co-ordinate store
dim z(points+1) 'Original Z co-ordinate store
dim tx(points+1)'Transformed X co-ordinate store
dim ty(points+1)'Transformed Y co-ordinate store
dim tz(points+1)'Transformed Z co-ordinate store
dim f1(faces+1) 'Connections definition
dim f2(faces+1) 'Connections definition
dim f3(faces+1) 'Connections definition
dim f4(faces+1) 'Connections definition
dim r(faces+1) 'Red Component
dim g(faces+1) 'Green Component
dim b(faces+1) 'Blue Component
dim cls(faces+1)'Cell Shade Face?
dim sort(faces+1) 'Drawing order
'Define Sine Tables for faster matrix calculations
dim cs(721)
dim sn(721)
for ang=0 to 720
cs(ang)=cos(ang*(pi/360))
sn(ang)=sin(ang*(pi/360))
next ang
'Read in the object's points
for a=1 to points
read x(a),y(a),z(a)
next a
'Read In Connections and face parameters
for a=1 to faces
read f1(a)
read f2(a)
read f3(a)
read f4(a)
read r(a),g(a),b(a),cls(a)
next a
'The Object Description As Data
data 0,0,-7,3,-3,-6,3,3,-6,-3,3,-6
data -3,-3,-6,4,0,-6,0,4,-6,-4,0,-6
data 0,-4,-6,0,-7,-4,0,7,-4,-7,0,-4
data 7,0,-4,5,5,-4,-5,5,-4,-5,-5,-4
data 5,-5,-4,5,-5,-2,5,5,-2,-5,5,-2
data -5,-5,-2,-7,0,-2,0,7,-2,7,0,-2
data 0,-7,-2,0,-4,3,0,4,3,4,0,3
data -4,0,3,-3,3,3,3,3,3,3,-3,3
data -3,-3,3,0,0,7
'Connection definition
'Below are the faces of the object defined as vertice
'numbers, specified in clockwise order. These are followed
'by r,g,b values for the face and finally cell shaded
'parameter (0)=off (1)=on.
data 30,29,22,20,0,0,90,1
data 29,33,21,22,0,0,90,0
data 33,26,25,21,0,0,90,1
data 27,30,20,23,0,0,90,1
data 31,27,23,19,0,0,90,0
data 19,24,28,31,0,0,90,1
data 32,28,24,18,0,0,90,1
data 18,25,26,32,0,0,90,0
data 20,22,12,15,0,0,90,1
data 23,20,15,11,0,0,90,0
data 21,16,12,22,0,0,90,1
data 25,10,16,21,0,0,90,1
data 19,23,11,14,0,0,90,1
data 13,24,19,14,0,0,90,1
data 18,24,13,17,0,0,90,1
data 10,25,18,17,0,0,90,1
data 33,29,34,34,0,0,90,1
data 29,30,34,34,0,0,90,0
data 30,27,34,34,0,0,90,1
data 27,31,34,34,0,0,90,0
data 31,28,34,34,0,0,90,1
data 28,32,34,34,0,0,90,0
data 32,26,34,34,0,0,90,1
data 26,33,34,34,0,0,90,0
data 15,12,8,4,0,0,90,1
data 12,16,5,8,0,0,90,0
data 15,4,7,11,0,0,90,1
data 7,3,14,11,0,0,90,0
data 3,6,13,14,0,0,90,1
data 16,10,9,5,0,0,90,0
data 2,9,10,17,0,0,90,1
data 6,2,17,13,0,0,90,0
data 9,2,1,1,0,0,90,0
data 2,6,1,1,0,0,90,1
data 6,3,1,1,0,0,90,0
data 3,7,1,1,0,0,90,1
data 7,4,1,1,0,0,90,1
data 5,9,1,1,0,0,90,1
data 4,8,1,1,0,0,90,0
data 8,5,1,1,0,0,90,1
'Points definition
'Below are the points of the object defined as x,y,z
data -10,10,10,10,10,10,10,-10,10,-10,-10,10
data -10,10,-10,10,10,-10,10,-10,-10,-10,-10,-10
'Connection definition
'Below are the faces of the object defined as vertice
'numbers, specified in clockwise order. These are followed
'by r,g,b values for the face and finally cell shaded
'parameter (0)=off (1)=on.
data 1,2,3,4,30,0,0,1
data 5,8,7,6,30,0,0,1
data 6,2,1,5,0,30,0,1
data 8,4,3,7,0,30,0,1
data 2,6,7,3,0,0,30,1
data 8,5,1,4,0,0,30,1
return