TextMorph

Post Reply
Wilshusen
Posts: 14
Joined: Mon Aug 12, 2013 6:21 pm

TextMorph

Post by Wilshusen »

Simple text morphing.
Only few character available right now. 7 points per character (with 700 points characters would probably look nicer)

Code: Select all

graphics


option base 0
dim f(35,7,2) 'font
dim o1(225)!dim o2(225) 'origyn
dim d1(225)!dim d2(225) 'destiny
dim r1(225)!dim r2(225) 'current result


'Load font`
fz1=15 'font multiplier horizontal
fz2=20 'font  multiplier vertical
fz3=fz1*4+3 'charater spacing
restore to FONT
for a=0 to 30
 for b=0 to 6
  for c=0 to 1
   read f(a,b,c)
  next c
 next b
next a



 
MAIN:

TEXT: 'christmas song

data "                 "," i love carols !"
data "      ...        "
data "  god rest you   "," merry gentlemen"
data "  let nothing    ","   you dismay  "
data "      ...        ","i miss the music"
data "                 ","end"

get screen size x,y
fz3=x/(16)!fz2=fz1*1.5!fz1=fz3/4.5
x=3!y=y/2-fz2*3.5
col=1
restore to TEXT
read tx1$
tx2$=tx1$

for z=1 to 50
  tx1$=tx2$
  read tx2$
	if tx2$="end" then end
  tx2$=capstr$(tx2$)
  le=max(len(tx1$),len(tx2$))+1
  gosub MORPH
Time reset
LOOP1:
if timer()<1000 then goto LOOP1
  next z
end



MORPH:
'load origin
For a=0 to le-1
 as=asc(tx1$,a)
 if as=32 or as=0 then as=64
 if as=asc(",")then as=64+27
 if as=asc(".")then as=64+28
 if as=asc("!")then as=64+29
 if as=asc("?")then as=64+30
 as=as-64
  for b=0 to 6
   o1(a*7+b)=f(as,b,0)*fz1+a*fz3+x
   o2(a*7+b)=f(as,b,1)*fz2+y
  next b
next a

'load destiny
For a=0 to le-1
 as=asc(tx2$,a)
 if as=32 or as=0 then as=64
 if as=asc(",")then as=64+27
 if as=asc(".")then as=64+28
 if as=asc("!")then as=64+29
 if as=asc("?")then as=64+30
 as=as-64
  for b=0 to 6
   d1(a*7+b)=f(as,b,0)*fz1+a*fz3+x
   d2(a*7+b)=f(as,b,1)*fz2+y
  next b
next a


'morphing!!

for a=0 to 1 step 0.02

time reset
for b=0 to le*7-7
 r1(b)=o1(b)*(1-a)+d1(b)*a
 r2(b)=o2(b)*(1-a)+d2(b)*a
next b

'print result
graphics lock
fill color 0,0,0
fill rect x,y to x+le*68,y+140
if col=1 then fill color 0,0.5,a
if col=-1 then fill color 0,0.5,1-a
for c=0 to len(tx1$)-1
fill poly r1,r2 count 7 start c*7
next c 
graphics unlock

LOOP2:
if timer()<80 then goto LOOP2

 next a
col=-col
return


FONT:
data 2,3, 2,3, 2,3, 2,3, 2,3, 2,3, 2,3 'SPACE
data 2,0, 2,0, 4,6, 4,6, 2,4, 2,4, 0,6 'A
data 1,0, 1,0, 4,2, 2,3, 4,5, 0,6, 0,6 'B
data 4,0, 4,0, 2,3, 2,3, 4,6, 4,6, 0,3 'C
data 1,0, 1,0, 4,3, 4,3, 3,5, 3,5, 0,6 'D
data 0,1, 4,0, 1,2, 3,3, 1,4, 4,6, 0,5 'E
data 1,1, 1,1, 4,0, 2,2, 3,3, 1,4, 0,6 'F
data 4,0, 2,3, 2,3, 3,4, 4,3, 4,6, 0,3 'G
data 1,0, 1,0, 2,3, 4,0, 3,6, 2,4, 0,6 'H
data 2,0, 2,0, 3,6, 3,6, 3,6, 1,6, 1,6 'I
data 1,0, 4,5, 4,5, 1,6, 0,4, 1,5, 2,4 'J
data 0,0, 1,2, 4,0, 1,3, 4,6, 1,4, 0,6 'K
data 1,0, 2,2, 2,2, 1,5, 1,5, 4,6, 0,6 'L
data 0,1, 4,1, 4,6, 3,1, 2,5, 1,2, 0,6 'M
data 1,0, 2,4, 4,0, 4,0, 3,6, 1,4, 0,6 'N
data 1,1, 2,0, 4,2, 4,2, 3,5, 2,6, 0,5 'O
data 1,0, 1,0, 4,2, 4,3, 4,3, 1,4, 0,6 'P
data 3,0, 4,3, 3,5, 4,6, 2,5, 1,6, 0,3 'Q
data 1,0, 4,2, 2,3, 2,3, 3,6, 1,4, 0,6 'R
data 0,2, 0,2, 4,0, 2,2, 4,5, 0,6, 2,4 'S
data 0,1, 4,0, 4,0, 3,1, 3,1, 2,6, 2,2 'T
data 0,1, 2,4, 4,0, 4,0, 3,5, 2,6, 1,5 'U
data 0,1, 0,1, 2,3, 2,3, 4,0, 4,0, 2,6 'V
data 0,1, 1,5, 2,1, 3,4, 4,0, 4,5, 0,6 'W
data 0,1, 2,2, 4,0, 3,6, 2,4, 0,6, 2,3 'X
data 0,1, 2,2, 4,0, 4,0, 3,2, 2,6, 2,3 'Y
data 0,0, 4,1, 4,1, 2,4, 4,6, 0,5, 2,2 'Z
data 1,5, 1,5, 2,5, 2,5, 2,5, 1,7, 1,7 ',
data 1,5, 1,5, 2,5, 2,5, 2,6, 2,6, 1,6 '.
data 1,0, 3,0, 3,0, 2,4, 3,6, 1,6, 2,4 '!
data 2,0, 4,1, 1,6, 3,6, 2,5, 2,2, 0,2 '?

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: TextMorph

Post by Mr. Kibernetik »

Looks very cool. Especially if to make morphing speed faster.

Post Reply