Space Box Demo

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

Space Box Demo

Post by DrChip »

REM BOX SPACE DEMO
REM iPhone 6 Plus / 8.2 b4
REM Please feel free to optimize and post!
REM Enjoy...

def reload
notes load "/Examples/10. Music & Sound/files/test2.mid"
notes play
enddef

reload


gosub initialize
gosub slapemin

Do
refresh off
graphics clear 0,0,0

Fill color 6/255,23/255,3/255
'triangle 0,0 to 640,512 to 0,512
trix(0)=0
triy(0)=0
trix(1)=sw
triy(1)=sh
trix(2)=0
triy(2)=sh
fill poly trix, triy count 3
'triangle 0,0 to 640,512 to 640,0
trix(0)=0
triy(0)=0
trix(1)=sw
triy(1)=sh
trix(2)=sw
triy(2)=0
fill poly trix, triy count 3
mm=mm+.02
size=30+25*sin(mm)

f1=8!f2=4!f3=3
gosub draw
f1=12!f2=8!f3=3
gosub draw
f1=12!f2=13!f3=8
gosub draw
f1=13!f2=4!f3=8
gosub draw
f1=12!f2=3!f3=7
gosub draw
f1=3!f2=4!f3=5
gosub draw
f1=13!f2=9!f3=4
gosub draw
f1=4!f2=9!f3=1
gosub draw
f1=4!f2=1!f3=5
gosub draw
f1=3!f2=5!f3=2
gosub draw
f1=5!f2=1!f3=2
gosub draw
f1=7!f2=3!f3=2
gosub draw
f1=6!f2=2!f3=1
gosub draw
f1=11!f2=7!f3=2
gosub draw
f1=11!f2=2!f3=6
gosub draw
f1=10!f2=11!f3=6
gosub draw
f1=10!f2=6!f3=1
gosub draw
f1=9!f2=10!f3=1
gosub draw
f1=13!f2=10!f3=9
gosub draw
f1=12!f2=7!f3=11
gosub draw
f1=12!f2=11!f3=14
gosub draw
f1=13!f2=12!f3=14
gosub draw
f1=13!f2=14!f3=10
gosub draw
f1=14!f2=11!f3=10
gosub draw

fill color 50/255,50/255,120/255

f1=8!f2=4!f3=3
gosub draw2
f1=12!f2=8!f3=3
gosub draw2
f1=12!f2=13!f3=8
gosub draw2
f1=13!f2=4!f3=8
gosub draw2
f1=12!f2=3!f3=7
gosub draw2
f1=3!f2=4!f3=5
gosub draw2
f1=13!f2=9!f3=4
gosub draw2
f1=4!f2=9!f3=1
gosub draw2
f1=4!f2=1!f3=5
gosub draw2
f1=3!f2=5!f3=2
gosub draw2
f1=5!f2=1!f3=2
gosub draw2
f1=7!f2=3!f3=2
gosub draw2
f1=6!f2=2!f3=1
gosub draw2
f1=11!f2=7!f3=2
gosub draw2
f1=11!f2=2!f3=6
gosub draw2
f1=10!f2=11!f3=6
gosub draw2
f1=10!f2=6!f3=1
gosub draw2
f1=9!f2=10!f3=1
gosub draw2
f1=13!f2=10!f3=9
gosub draw2
f1=12!f2=7!f3=11
gosub draw2
f1=12!f2=11!f3=14
gosub draw2
f1=13!f2=12!f3=14
gosub draw2
f1=13!f2=14!f3=10
gosub draw2
f1=14!f2=11!f3=10
gosub draw2
fill color 30/255,155/255,155/255
for a=1 to str
tx1=(sx(a)/sz(a))+sw/2
ty1=(sy(a)/sz(a))+sh/2
siz=6-sz(a)
sz(a)=sz(a)-.04
fill rect tx1,ty1 to tx1+siz,ty1+siz
if (tx1<0) or (tx1>sw) or (ty1<0) or (ty1>sh) then
sx(a)=-1500+rnd(3000)
sy(a)=-1500+rnd(3000)
sz(a)=5
End if
next a
gosub rotate
gosub scroller
refresh on
until 1=2

slapemin:
Draw color 150/255,250/255,150/255
Draw text "CONVERTING SCROLL TO ASCII FORMAT" at 0,sh-40
Draw text "BOX SPACE DEMO" at 0,0
mmm=0
target=len(s$)+1
for a=1 to len(s$)-1
letter=asc(mid$(s$,a,1))-48
ostore(mmm)=(letter*10)
if ostore(mmm)<0 then ostore(mmm)=-1
mmm=mmm+1
width=(int((target-a)/len(s$)*200))*2
Draw rect 0,sh-20 to sw-width,sh
pause .01
next a
p=p+1
if p>len(s$)-5 then p=0
'clear window
graphics clear 0,0,0
'Take the offsets and build the connection data from them

Draw color 150/255,1,150/255
Draw text "CALCULATING SCROLL CONNECTIONS" at 0,sh-40

os=1
l=0
for a=1 to len(s$) -1
for b=1 to 10
connects(os)=fnt(ostore(a)+b)
if ostore(a)<0 then connects(os)=(1)
os=os+1
next b
width=(int((target-a)/len(s$)*200))*2
Draw rect 0,sh-20 to sw-width,sh
pause .01
next a
flag=0
l=0
p=0
return

scroller:
scrl=scrl-8
if scrl<-164 then
scrl=scrl+164
p=p+10
if (p/10)>(len(s$)-6) then p=0
End if
f=100+100*sin(mm)

Draw color 155+f/255,155+f/255,1
lf=0
l=0
for a=1 to 50 step 2
Draw line txx(connects(p+a)+l)+scrl,tyy(connects(p+a)+l) to txx(connects(p+a+1)+l)+scrl,tyy(connects(p+a+1)+l)
lf=lf+1
if lf=5 then
lf=0
l=l+9
End if
next a
return


draw:
'Draw A Face Of The Cube!
l=l+1
if l>5 then l=4
vx1= tx(f1)-tx(f2)
vy1= ty(f1)-ty(f2)
vx2= tx(f3)-tx(f2)
vy2= ty(f3)-ty(f2)
if (vx1*vy2-vx2*vy1)<0 then
light=-(tz(f1)+tz(f2)+tz(f3))*l
Fill color r+light/255,g+light/255,b+light/255
'gtriangle tx(f1),ty(f1) to tx(f2),ty(f2) to tx(f3),ty(f3)
trix(0)=tx(f1)
triy(0)=ty(f1)
trix(1)=tx(f2)
triy(1)=ty(f2)
trix(2)=tx(f3)
triy(2)=ty(f3)
fill poly trix, triy count 3
Fill color r+30+light/255,g+30+light/255,b+30+light/255
'triangle tx(f1),ty(f1) to tx(f2),ty(f2) to tx(f3),ty(f3)
trix(0)=tx(f1)
triy(0)=ty(f1)
trix(1)=tx(f2)
triy(1)=ty(f2)
trix(2)=tx(f3)
triy(2)=ty(f3)
fill poly trix, triy count 3
End if
return

draw2:

'Draw A Face Of The Cube
vx1= tx(f1)-tx(f2)
vy1= ty(f1)-ty(f2)
vx2= tx(f3)-tx(f2)
vy2= ty(f3)-ty(f2)
if (vx1*vy2-vx2*vy1)>0 then
'triangle tx(f1),ty(f1) to tx(f2),ty(f2) to tx(f3),ty(f3)
trix(0)=tx(f1)
triy(0)=ty(f1)
trix(1)=tx(f2)
triy(1)=ty(f2)
trix(2)=tx(f3)
triy(2)=ty(f3)
fill poly trix, triy count 3
End if
return

rotate:

'Rotate And Scale Each Point
for a=1 to polys
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!
xx=size*(xx/((zz/50)+1))+sw/2
yy=size*(yy/((zz/50)+1))+sh/2
tx(a)=xx
ty(a)=yy
tz(a)=zz
next a
xr=xr+3
yr=yr+2
zr=zr+4
if xr>720 then xr=xr-720
if yr>720 then yr=yr-720
if zr>720 then zr=zr-720
return

initialize:

'Open Gfx Screen!
Graphics
pi=3.1415
sw=screen_width()
sh=screen_height()

'Define the necessary variables!
size=29 ' how big do you want it?
polys=14 ' polygons in the object

dim x(polys+1) 'Original X co-ordinate
dim y(polys+1) 'Original Y co-ordinate
dim z(polys+1) 'Original Z co-ordinate

dim tx(polys+2) 'Transformed X co-ordinate
dim ty(polys+2) 'Transformed Y co-ordinate
dim tz(polys+2) 'Transformed Z co-ordinate

str=65
dim sx(str+2),sy(str+2),sz(str+2)

for a=1 to str
sx(a)=-1000+rnd(2000)
sy(a)=-1000+rnd(2000)
sz(a)=rnd(5)+1
next a

r=10
g=10
b=40

'Define Sine Tables!!
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

for a=1 to polys
read x(a),y(a),z(a)
next a
s$=" YOU ARE NOW "
s$=s$&"LOOKING AT A VECTOR SCROLL TEXT AND 70 3D STARS "
s$=s$&"WITH A NEW GLASS TYPE OBJECT THAT I BASED ON A "
s$=s$&"BOX AND STRETCHED OUT THE MIDDLES ; HENCE THE "
s$=s$&"NAME OF THE DEMO ; INCIDENTALLY I CREATED THE "
s$=s$&"OBJECT WITH MY VECTOR EDITOR ;; DO YOU CODE 3D "
s$=s$&" I HOPE THAT YOU ENJOY THIS LATEST DEMOS... "
s$=s$&" SCROLL RESTARTS IN A FEW MOMENTS "
s$=s$&";;10;; "
s$=s$&";;9;; "
s$=s$&";;8;; "
s$=s$&";;7;; "
s$=s$&";;6;; "
s$=s$&";;5;; "
s$=s$&";;4;; "
s$=s$&";;3;; "
s$=s$&";;2;; "
s$=s$&";;1;; "
s$=s$&";;0;; "
s$=s$&" "

dim ostore(len(s$))
dim scx(46),scy(46),txx(46),tyy(46) ' scroll template.
dim connects(10*len(s$)) 'This stores display lines.
dim fnt (431) 'storage space for letter connections.

for a=1 to 45
read scx(a),scy(a)
next a
for a=1 to 45
txx(a)=(55*scx(a))+sw/2
tyy(a)=(55*scy(a))+sh/2
next a

for a=1 to 430
read fnt(a)
next a
'The Object Description As Data
'The Data Describes A Special Cube/Sphere.
'Designed with my vector editor.

data 5,-5,-5,5,5,-5,-5,5,-5,-5,-5,-5,0,0,-8,8,0,0,0,8,0,-8,0,0,0,-8,0,5,-5,5,5,5,5,-5,5,5,-5,-5,5,0,0,8

'The Scroling message template;
data -10,-1,-9,-1,-8,-1,-10,0,-9,0,-8,0,-10,1,-9,1,-8,1
data -7,-1,-6,-1,-5,-1,-7,0,-6,0,-5,0,-7,1,-6,1,-5,1
data -4,-1,-3,-1,-2,-1,-4,0,-3,0,-2,0,-4,1,-3,1,-2,1
data -1,-1,0,-1,1,-1,-1,0,0,0,1,0,-1,1,0,1,1,1
data 2,-1,3,-1,4,-1,2,0,3,0,4,0,2,1,3,1,4,1

'The Font. (Each letter has five lines).
'AscII map;
'48=0:49=1:50=2:51=3:52=4:53=5:54=6:55=7:56=8:57=9:58=:
'59=;:60=<:61==:62=>:63=?:64=@:65=A: to 90= Z:

'0 to 3
data 1,3,3,9,9,7,7,1,1,9
data 4,2,2,5,5,8,8,7,8,9
data 2,3,3,6,6,4,4,7,7,9
data 1,2,2,6,6,4,6,9,9,7
'4 to 7
data 1,4,4,5,5,2,5,8,5,6
data 2,1,1,4,4,6,6,9,9,7
data 3,1,1,7,7,9,9,6,6,4
data 1,3,3,6,6,4,6,8,8,6
'8 to 9,:,;
data 1,3,3,9,9,7,7,1,4,6
data 1,3,3,6,6,4,4,1,6,8
data 4,6,6,4,4,6,6,4,4,6 ' colon gives -
data 2,8,4,6,1,9,3,7,4,6 ' semicolon gives *
'< = > ? @
data 3,4,4,9,9,5,5,3,3,4
data 1,3,3,1,7,9,9,7,7,9
data 1,6,6,7,7,5,5,1,1,6
data 1,3,3,6,6,5,5,4,7,8
data 3,1,1,7,7,9,9,6,6,8
'A to D;
data 7,4,4,2,2,6,6,9,4,6
data 1,7,7,9,9,4,4,6,6,1
data 6,3,3,2,2,4,4,7,7,9
data 1,2,2,6,6,9,9,7,7,1
'E to H
data 3,2,2,4,4,6,4,7,7,9
data 3,2,2,4,4,6,4,7,4,7
data 3,4,4,7,7,9,9,6,6,5
data 1,7,4,6,3,9,4,6,4,6
'I to L
data 1,2,2,3,2,8,7,8,8,9
data 1,3,3,6,6,8,8,7,7,4
data 1,7,4,2,9,5,5,4,4,5
data 1,4,4,7,7,8,8,9,8,9
'M to P
data 1,3,3,9,1,7,2,5,5,2
data 7,4,4,1,1,5,5,9,9,3
data 1,3,3,9,9,7,7,1,1,3
data 7,4,4,1,1,3,3,6,6,4
'Q to T
data 1,3,3,9,9,7,7,1,9,5
data 1,2,2,6,6,4,4,9,1,7
data 3,1,1,4,4,6,6,9,9,7
data 1,3,3,1,2,5,5,8,8,2
'U to X
data 1,7,7,8,8,9,9,6,6,3
data 1,4,4,8,8,6,6,3,3,6
data 1,7,7,9,9,3,8,5,5,8
data 1,5,5,9,3,5,5,7,7,5
'Y to Z
data 1,4,4,6,6,3,6,9,9,7
data 1,2,2,3,3,7,7,8,8,9
return
Attachments
image.jpg
image.jpg (122.27 KiB) Viewed 1766 times
image.jpg
image.jpg (123.41 KiB) Viewed 1766 times
image.jpg
image.jpg (125.53 KiB) Viewed 1766 times

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Space Box Demo

Post by Mr. Kibernetik »

Very impressive!

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Space Box Demo

Post by Henko »

A lot of work, like this one:
viewtopic.php?f=20&t=224

Post Reply