rem On Reflection Demo
rem iPhone 6 plus / 8.2 b4
rem Enjoy...
gosub initialize
draw color 40/255,30/255,20/255
do
refresh off
graphics clear 0,0,0
gosub rotate
gosub inf
o=16!gosub construct2
o=24!gosub construct2
o=32!gosub construct2
o=40!gosub construct2
gosub construct
gosub rotcontrol
draw color cf,cf,cf
draw text m$(mp) at 0,sh-20
refresh on
until 1=2
'Rotations For The Central Cube
rotcontrol:
tt=tt+2
if tt<255 then cf=cf+2
if tt>500 then cf=cf-2
if tt>750 then
tt=0
mp=mp+1
if mp>15 then mp=1
end if
zr2=zr2+1
xr2=xr2+3
yr2=yr2+2
if xr2>720 then xr2=xr2-720
if yr2>720 then yr2=yr2-720
if zr2>720 then zr2=zr2-720
return
'Draw The Cube Reflections;
construct2:
for a=1 to faces
gosub draw2
next a
return
'Draw A Face Of The Central Cube;
draw2:
vx1= tx(f1(a)+o)-tx(f2(a)+o)
vy1= ty(f1(a)+o)-ty(f2(a)+o)
vx2= tx(f3(a)+o)-tx(f2(a)+o)
vy2= ty(f3(a)+o)-ty(f2(a)+o)
n= vx1*vy2-vx2*vy1
if n>0 then
n=n/100
fill color r(a)+n/255,g(a)+n/255,b(a)+n/255
'fill triangle tx(f1(a)+o),ty(f1(a)+o) to tx(f2(a)+o),ty(f2(a)+o) to tx(f3(a)+o),ty(f3(a)+o)
trix(0)=tx(f1(a)+o)
triy(0)=ty(f1(a)+o)
trix(1)=tx(f2(a)+o)
triy(1)=ty(f2(a)+o)
trix(2)=tx(f3(a)+o)
triy(2)=ty(f3(a)+o)
fill poly trix,triy count 3
'fill triangle tx(f1(a)+o),ty(f1(a)+o) to tx(f4(a)+o),ty(f4(a)+o) to tx(f3(a)+o),ty(f3(a)+o)
trix(0)=tx(f1(a)+o)
triy(0)=ty(f1(a)+o)
trix(1)=tx(f4(a)+o)
triy(1)=ty(f4(a)+o)
trix(2)=tx(f3(a)+o)
triy(2)=ty(f3(a)+o)
fill poly trix,triy count 3
end if
return
'Draw Large Cube;
inf:
fill color 0,10/255,20/255
'fill triangle tx(12),ty(12) to tx(11),ty(11) to tx(10),ty(10)
trix(0)=tx(12)
triy(0)=ty(12)
trix(1)=tx(11)
triy(1)=ty(11)
trix(2)=tx(10)
triy(2)=ty(10)
fill poly trix,triy count 3
'fill triangle tx(12),ty(12) to tx(9),ty(9) to tx(10),ty(10)
trix(0)=tx(12)
triy(0)=ty(12)
trix(1)=tx(9)
triy(1)=ty(9)
trix(2)=tx(10)
triy(2)=ty(10)
fill poly trix,triy count 3
fill color 0,20/255,100/255
'fill triangle tx(13),ty(13) to tx(14),ty(14) to tx(10),ty(10)
trix(0)=tx(13)
triy(0)=ty(13)
trix(1)=tx(14)
triy(1)=ty(14)
trix(2)=tx(10)
triy(2)=ty(10)
fill poly trix,triy count 3
'fill triangle tx(13),ty(13) to tx(9),ty(9) to tx(10),ty(10)
trix(0)=tx(13)
triy(0)=ty(13)
trix(1)=tx(9)
triy(1)=ty(9)
trix(2)=tx(10)
triy(2)=ty(10)
fill poly trix,triy count 3
fill color 0,20/255,140/255
'fill triangle tx(13),ty(13) to tx(16),ty(16) to tx(12),ty(12)
trix(0)=tx(13)
triy(0)=ty(13)
trix(1)=tx(16)
triy(1)=ty(16)
trix(2)=tx(12)
triy(2)=ty(12)
fill poly trix,triy count 3
'fill triangle tx(13),ty(13) to tx(12),ty(12) to tx(9),ty(9)
trix(0)=tx(13)
triy(0)=ty(13)
trix(1)=tx(12)
triy(1)=ty(12)
trix(2)=tx(9)
triy(2)=ty(9)
fill poly trix,triy count 3
fill color 0,20,140
'fill triangle tx(11),ty(11) to tx(15),ty(15) to tx(14),ty(14)
trix(0)=tx(11)
triy(0)=ty(11)
trix(1)=tx(15)
triy(1)=ty(15)
trix(2)=tx(14)
triy(2)=ty(14)
fill poly trix,triy count 3
'fill triangle tx(11),ty(11) to tx(10),ty(10) to tx(14),ty(14)
trix(0)=tx(11)
triy(0)=ty(11)
trix(1)=tx(10)
triy(1)=ty(10)
trix(2)=tx(14)
triy(2)=ty(14)
fill poly trix,triy count 3
fill color 0,20/255,100/255
'fill triangle tx(16),ty(16) to tx(15),ty(15) to tx(11),ty(11)
trix(0)=tx(16)
triy(0)=ty(16)
trix(1)=tx(15)
triy(1)=ty(15)
trix(2)=tx(11)
triy(2)=ty(11)
fill poly trix,triy count 3
'fill triangle tx(16),ty(16) to tx(11),ty(11) to tx(12),ty(12)
trix(0)=tx(16)
triy(0)=ty(16)
trix(1)=tx(11)
triy(1)=ty(11)
trix(2)=tx(12)
triy(2)=ty(12)
fill poly trix,triy count 3
return
'Draw The Central Cube;
construct:
for a=1 to faces
gosub draw
next a
return
'Draw A Face Of The Central Cube;
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/300)
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
end if
return
'Rotations;
rotate:
'Rotate And Scale Each Point (Inner) Store Result
for a=1 to 8
x1=x(a)
y1=y(a)
z1=z(a)
'X,Y,Z rotations
xx=x1
yy=y1*cs(xr2)+z1*sn(xr2)
zz=z1*cs(xr2)-y1*sn(xr2)
y1=yy
x1=xx*cs(yr2)-zz*sn(yr2)
z1=xx*sn(yr2)+zz*cs(yr2)
zz=z1
xx=x1*cs(zr2)-y1*sn(zr2)
yy=x1*sn(zr2)+y1*cs(zr2)
'Apply Perspective
x(a+16)=20
x(a+24)=-20
x(a+32)=-xx
x(a+40)=xx
y(a+16)=-yy
y(a+24)=yy
y(a+32)=20
y(a+40)=-20
z(a+16)=zz
z(a+24)=zz
z(a+32)=zz
z(a+40)=zz
dv=(zz/80)+1
xx=size*(xx/dv)
yy=size*(yy/dv)
tx(a)=xx
ty(a)=yy
tz(a)=zz
next a
'Scale Each Point (Outer) Store Result
for a=9 to points
x1=x(a)
y1=y(a)
z1=z(a)
'X,Y,Z rotations
xx=x1
yy=y1*cs(0)+z1*sn(0)
zz=z1*cs(0)-y1*sn(0)
y1=yy
x1=xx*cs(0)-zz*sn(0)
z1=xx*sn(0)+zz*cs(0)
zz=z1
xx=x1*cs(0)-y1*sn(0)
yy=x1*sn(0)+y1*cs(0)
'Apply Perspective
dv=(zz/80)+1
xx=size*(xx/dv)
yy=size*(yy/dv)
tx(a)=xx
ty(a)=yy
tz(a)=zz
next a
return
initialize:
sw=screen_width()
sh=screen_height()
'Open Gfx Screen
graphics
'Define the necessary variables;
mp=1
pi=3.1415
points=48 ' The amount of points in the object
faces=6 ' The Amount of faces in the object
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
size=12
dim m$(9)
m$(1)="WELCOME TO MY LATEST DEMO!"
m$(2)="CALLED: ON REFLECTION DEMO"
m$(3)="A CUBE WITH A DIFFERENCE!"
m$(4)="CENTRAL CUBE IS PROPERLY"
m$(5)="REFLECTED AND MAPPED ONTO"
m$(6)="THE OUTER CUBE'S FACES!"
m$(7)="THANKS TO FORUM MEMBERS!"
m$(8)="TEXT RESTARTS NOW..."
'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 16
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)
next a
'The Data Below Describes A Cube.
'Points definition
'Below are the points of the object defined as x,y,z
data -9,9,9,9,9,9,9,-9,9,-9,-9,9
data -9,9,-9,9,9,-9,9,-9,-9,-9,-9,-9
data -20,20,20,20,20,20,20,-20,20,-20,-20,20
data -20,20,-20,20,20,-20,20,-20,-20,-20,-20,-20
'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.
data 1,2,3,4,30,0,0
data 5,8,7,6,30,0,0
data 6,2,1,5,0,30,0
data 8,4,3,7,0,30,0
data 2,6,7,3,0,0,30
data 8,5,1,4,0,0,30
return
Reflection Demo
-
- Posts: 167
- Joined: Wed Oct 22, 2014 3:26 pm
- My devices: iPhone 4 to 6+,iPad mini to iPad air 2
Reflection Demo
- Attachments
-
- image.jpg (132.53 KiB) Viewed 1948 times
-
- image.jpg (138.96 KiB) Viewed 1948 times
-
- image.jpg (130.89 KiB) Viewed 1948 times