Page 1 of 1

2d3d

Posted: Thu Feb 05, 2015 2:00 pm
by DrChip
REM 2D in 3D space v.1
REM it has bugs and is not finished.
REM I 'm optimizing it and i hope to
REM finish it soon...
REM enjoy if you can.
REM Sorry its not finished!
REM iPhone 6 Plus / iOS 8.2 b5

graphics
GOSUB initialize


'main:
loop:
frme=frme+1
IF frme=4 THEN
frme=1
END IF

refresh off
graphics clear 0,0,0

' draw the fans
FOR x=0 TO sw STEP 40
yo=co(ang)*100
b1=128+si(ang)*63
b2=128+co(ang)*63
draw COLOR 0,b2/255,b1/255
cc=COS((x+ang)*f)*400 '200
ss=SIN((x+ang)*f)*200 '-200
'TRIANGLE x-20,cc+yo, x,yo, x+20,ss+yo
trix(0)=x-20
triy(0)=cc+yo
trix(1)=x
triy(1)=yo
trix(2)=x+20
triy(2)=ss+yo
fill poly trix,triy count 3
NEXT x

' draw the snakes
FOR a=1 TO 15
'x=co(abx+a*10)*sw+100
bs=a*2
br=bs*5+50
'y=si(aby+a*10)*sh+100
fill COLOR br/255,0,0
fill RECT x-bs,y-bs to x+bs,y+bs
fill COLOR 0,0,br/255
fill RECT -x-bs,-y-bs to -x+bs,-y+bs
NEXT a

abx=(abx+5%360)
aby=(aby+3%360)



' draw the text
b$=MID$(m$(ml),1,tp)
ss=128+si(ang)*60
draw COLOR ss/255,(128+co(ang)*60)/255,0
IF (ttp%5)>2 THEN 'mod
b$=b$+"_"
END IF
DRAW TEXT b$ at ss-100,Screen_Height() - 20
ttp=ttp-1
IF ttp<0 THEN
ttp=5
IF tp=LEN(m$(ml))-2 THEN
ttp=100
END IF
tp=(tp+1 % LEN(m$(ml))) 'mod
IF tp=0 THEN
ml=(ml+1%4) 'mod
END IF
END IF

' draw the picture frame
FOR a=1 TO nt STEP 4
FOR b=0 TO 3
az(a+b)=co(ang)*20
x=ax(a+b)+sw/2
y=ay(a+b)+sh/2
z=az(a+b)
GOSUB cl
tx(b+1)=x
ty(b+1)=y
tz(b+1)=z
ab(b+1)=128-(z/2)
NEXT b
IF a=5 THEN
ab(1)=0
ab(2)=0
ab(3)=0
END IF
fill COLOR ab(1)/255,ab(2)/255,ab(3)/255
'TRIANGLE tx(1),ty(1), tx(2),ty(2), tx(3),ty(3)
trix(0)=tx(1)
triy(0)=ty(1)
trix(1)=tx(2)
triy(1)=ty(2)
trix(2)=tx(3)
triy(2)=ty(3)
fill poly trix,triy count 3
'TRIANGLE tx(1),ty(1), tx(4),ty(4), tx(3),ty(3)
trix(0)=tx(1)
triy(0)=ty(1)
trix(1)=tx(4)
triy(1)=ty(4)
trix(2)=tx(3)
triy(2)=ty(3)
fill poly trix,triy count 3
NEXT a

' draw the fountain
FOR a=frme TO np STEP 2
pz(a)=co(ang)*20
px(a)=px(a)+pxv(a)
py(a)=py(a)+pyv(a)
x=px(a) +sw/2
y=py(a) +sh/2
pyv(a)=pyv(a)+0.15
z=pz(a)

IF y>sh/2+90 OR y<-sh/2+90 OR x<-sw/2+90 OR x>sw/2+90 THEN
py(a)=90
px(a)=0
pyv(a)=-INT(RND(8))
END IF

GOSUB cl
bri=128-(z/2)
fill COLOR 0,0,(bri+50)/255

fill RECT x,y to x+2,y+2
NEXT a

ang=(ang+1) % 360 'mod
yrot=180+co(ang)*180
refresh on
GOTO loop
RETURN


cl:
IF yrot < 1 THEN
yrot = 1
END IF
xx=x*co(yrot)-z*si(yrot)
zz=x*si(yrot)+z*co(yrot)
x=xx/((zz/focus)+1)
y=y/((zz/focus)+1)
RETURN


initialize:
pi=3.1415
sw=Screen_Width()
sh=Screen_Height()
DIM m$(5)
m$(1)="The 2D in 3D Demo "
m$(2)="by DrChip "
m$(3)="A 2D Fountain "
m$(4)="Spinning in 3D space "

f=PI/180
DIM co(800),si(800)
FOR a=1 TO 750
co(a)=COS(a*f)
si(a)=SIN(a*f)
NEXT a

nt=8
DIM ax(nt+1),ay(nt+1),az(nt+1),tx(5),ty(5),tz(5),ab(5)
FOR a=1 TO nt
READ ax(a)
read ay(a)
NEXT a

np=80
DIM px(np+1),py(np+1),pz(np+1),pxv(np+1),pyv(np+1)
FOR a=1 TO np
px(a)=0
pxv(a)=RND(4)-2
py(a)=91
NEXT a

tp=1
frme=1
ml=1
focus=500
ang=1
xrot=2
yrot=1
zrot=3
RETURN



DATA -100, 100
DATA -100, -100
DATA 100, -100
DATA 100, 100
DATA -90, 90
DATA -90, -90
DATA 90, -90
DATA 90, 90

Re: 2d3d

Posted: Thu Feb 05, 2015 2:26 pm
by Mr. Kibernetik
In next version 4.8 you will get much faster commands like FILL TRI or DRAW QUAD.

Re: 2d3d

Posted: Thu Feb 05, 2015 2:28 pm
by DrChip
Great! Thanks!!