Draw Text in any Angle direction

Post Reply
Erg2
Posts: 18
Joined: Sat Dec 10, 2016 8:58 pm
My devices: ipad2
Flag: Australia

Draw Text in any Angle direction

Post by Erg2 »

Hello All,

Can someone help me how text in the graphics mode can be drawn at a certain angle off the horizontal or vertical

Draw text "Hello World, draw text any direction" at location 450,500 'how can this whole sentence be drawn, say at an angle of 30 degrees to the horizontal or for that matter any angle within 360 degrees

I was thinking
Draw text "Hello World, draw text any direction" at location 450,500 ANGLE 30
Doesn't work :(

I looked in the manual and forum but couldn't find any thing.

Thank you
Erg

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: Draw Text in any Angle direction

Post by Mr. Kibernetik »

You can do it in sprite

Code: Select all

sprite 0 begin 100,50
draw text "the text" at 0,0
sprite 0 end

graphics
for x=0 to screen_width() step 100
  sprite 0 at x,100 angle x
  sprite 0 stamp
next x
image.jpg
image.jpg (48 KiB) Viewed 1843 times

Erg2
Posts: 18
Joined: Sat Dec 10, 2016 8:58 pm
My devices: ipad2
Flag: Australia

Re: Draw Text in any Angle direction

Post by Erg2 »

Fantastic :)
Thank you Mr. Kibernenik

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

Re: Draw Text in any Angle direction

Post by Henko »

option base 1 ! option angle degrees ! randomize
dim tok(40,10,2)
tokens(tok)
graphics ! graphics clear .8,.8,.8 ! fill color .8,.8,.8
graphics lock
for angl=0 to 340 step 22
alph=.3+rnd(.7) ! c=rnd(100) ! siz=3+int(angl/20)
if c<25 then ! col$="z" ! goto lab ! end if
if c<50 then ! col$="r" ! goto lab ! end if
if c<75 then ! col$="b" ! goto lab ! end if
col$="g"
lab:
r=30+angl/15 ! x=r*cos(-angl) ! y=r*sin(-angl)
draw_text("can you read this ?",col$,siz,alph,340+x,400+y,angl,tok)
next angl
graphics unlock
end

def draw_text(txt$,col$,siz,alph,x,y,angl,tok(,,))
set_color(col$)
draw alpha alph ! lt=len(txt$) ! fac=siz/4
ca=cos(-angl) ! sa=sin(-angl) ! draw size 1+int(siz/10)
for i=1 to lt
t$=substr$(txt$,i,i) ! t=asc(t$)
if t>96 then ! k=t-82 ! goto dt_loop1 ! end if
if t>47 and t<58 then ! k=t-44 ! goto dt_loop1 ! end if
if t=32 then k=1 ! if t=44 then k=2
if t=46 then k=3 ! if t=63 then k=14
dt_loop1:
r=siz*(i-1) ! xd=x+r*ca ! yd=y+r*sa
for j=1 to 10
xl=fac*tok(k,j,1) ! yl=fac*tok(k,j,2)
if xl<0 then dt_loop2
xp=xd+xl*ca-yl*sa ! yp=yd+xl*sa+yl*ca
if j=1 then draw to xp,yp else draw line to xp,yp
next j
dt_loop2:
next i
end def

def set_color(col$)
if col$="z" then draw color 0,0,0
if col$="r" then draw color 1,0,0
if col$="g" then draw color 0,.6,0
if col$="b" then draw color 0,0,1
if col$="w" then draw color 1,1,1
end def

def tokens(tok(,,))
for i=1 to 40 ! for j=1 to 10 ! for k=1 to 2
read tok(i,j,k)
next k ! next j ! next i
data -1,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 '
data 1.5,3, 2,3, 2,3.5, 1,4, 1.5,3.5, 1.5,3, -1,0,0,0,0,0,0,0 ',
data 1,3.5, 1.5,3.5, 1.5,4, 1,4, -1,0,0,0,0,0,0,0,0,0,0,0 '.
data 0,1, 0,3, 1,4, 2,4, 3,3, 3,1, 2,0, 1,0, 0,1, -1,0 '0
data 1,1, 2,0, 2,4, 1,4, 3,4, -1,0, 0,0, 0,0, 0,0, 0,0 '1
data 0,1, 1,0, 2,0, 3,1, 0,4, 3,4, -1,0, 0,0, 0,0, 0,0 '2
data 0,0, 3,0, 2,1, 3,2, 3,3, 2,4, 1,4, 0,3, -1,0, 0,0 '3
data 3,3, 0,3, 2,0, 2,4, 2,3, 3,3, -1,0, 0,0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5,2, 3,0, 3,4, -1,0, 0,0, 0,0, 0,0, 0,0 'm
data 0,4, 0,0, 3,4, 3,0, -1,0, 0,0, 0,0, 0,0, 0,0, 0,0 'n
data 0,1, 0,3, 1,4, 2,4, 3,3, 3,1, 2,0, 1,0, 0,1, -1,0 'o
data 0,4, 0,0, 2,0, 3,1, 2,2, 0,2, -1,0, 0,0, 0,0, 0,0 'p
data 2,4, 1,4, 0,3, 0,1, 1,0, 2,0, 3,1, 3,3, 2,3, 3,4 'q
data 0,4, 0,0, 2,0, 3,1, 2,2, 0,2, 1,2, 3,4, -1,0, 0,0 'r
data 3,0, 1,0, 0,1, 1,2, 2,2, 3,3, 2,4, 0,4, -1,0, 0,0 's
data 0,0, 3,0, 1.5,0, 1.5,4, -1,0, 0,0, 0,0, 0,0, 0,0, 0,0 't
data 0,0, 0,3, 1,4, 2,4, 3,3, 3,4, 3,0, -1,0, 0,0, 0,0 'u
data 0,0, 1.5,4, 3,0, -1,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 'v
data 0,0, 0,4, 1.5,2, 3,4, 3,0, -1,0, 0,0, 0,0, 0,0, 0,0 'w
data 0,0, 3,4, 1.5,2, 0,4, 3,0, -1,0, 0,0, 0,0, 0,0, 0,0 'x
data 0,0, 1.5,2, 0,4, 3,0, -1,0, 0,0, 0,0, 0,0, 0,0, 0,0 'y
data 0,0, 3,0, 0,4, 3,4, -1,0, 0,0, 0,0, 0,0, 0,0, 0,0 'z
end def
IMG_1390.PNG
IMG_1390.PNG (431.43 KiB) Viewed 1837 times

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Draw Text in any Angle direction

Post by rbytes »

One suggestion for making text point in the desired direction is to use the command OPTION ANGLE DEGREES early in your code. That way you will understand better where your text should point when you set the sprite angle. It will be in the normal horizontal position at 0 degrees, and then can be rotated up to 360 degrees to turn a full circle. At 360 degrees it will point in the same direction as 0 degrees.

Here's a bit of code that builds on Mr. K's example. There are three sprites created, one for each row, to stamp text in a different color.

Code: Select all

OPTION ANGLE DEGREES
GRAPHICS
DRAW COLOR 1,0,0
DRAW TEXT "90 degree text" AT 400,190
n=1 
SPRITE n BEGIN 100,50
DRAW TEXT "the text" AT 0,0
SPRITE n END
FOR x=20 TO SCREEN_WIDTH()-40 STEP 90
  SPRITE n AT x,100 ANGLE x-20
  SPRITE n STAMP
NEXT x
DRAW COLOR 0,.9,0
DRAW TEXT "45 degree text" AT 400,390
n+=1
SPRITE n BEGIN 100,50
DRAW TEXT "the text" AT 0,0
SPRITE n END
FOR x=20 TO SCREEN_WIDTH()-40 STEP 90
  SPRITE n AT x,300 ANGLE x+25
  SPRITE n STAMP
NEXT x
DRAW COLOR .3,.3,1
DRAW TEXT "random degree text" AT 380,590
n+=1
SPRITE n BEGIN 100,50
DRAW TEXT "the text" AT 0,0
SPRITE n END
FOR x=20 TO SCREEN_WIDTH()-40 STEP 90
  SPRITE n AT x,500 ANGLE RND(360)
  SPRITE n STAMP
NEXT x
Attachments
IMG_2245.PNG
IMG_2245.PNG (149.21 KiB) Viewed 1827 times
The only thing that gets me down is gravity...

Post Reply