|
Post by tailoredreaction on Dec 23, 2020 17:59:53 GMT
How do I rotate text in a graphic window. I need to write plain text in a graphic window that is rotated 90 deg to the left.
Anyone?
|
|
|
Post by tsh73 on Dec 23, 2020 20:50:54 GMT
I have this code saved from old forum long ago It is by Mazinger - I have no idea who is he but wish him all the luck.
Who knows, it might be enough for you? (it definitely needs digits added, though)
'mazinger JUST BASIC ROTATE FONT
'here is a function that generate the string comand for rotate text to graphics windows:
'Rotext$(Angle,Size,text)
nomainwin
WindowWidth = 800 WindowHeight = 600
open "" for Graphics as #main
#main "trapclose [quit]"
#main "place 10 50; "+Rotext$(0,8,"ABCDEFGHYJKLMN
|
|
|
Post by tsh73 on Dec 23, 2020 21:06:56 GMT
|
|
|
Post by tailoredreaction on Dec 23, 2020 23:01:13 GMT
'Rotext$(Angle,Size,text)
nomainwin
WindowWidth = 800
WindowHeight = 600
open "" for Graphics as #main
#main "trapclose [quit]"
#main "place 10 50; "+Rotext$(0,8,"ABCDEFGHYJKLMN
I can't make it work no matter how I try and manipulate it. I am stuck getting syntax errors for everything I try.
Rotext$ (Angle,Size,text) <--- looks exactly like what I need! I can't find any reference to it anywhere, nor am I able to find an example someone has used that worked.
When I do this test,
'#1.g, "up"
'#1.g, "goto 270 60"
'#1.g, "down"
'#1.g, "color black"
'#1.g, "Rotext$(90,18,ABC)"
I've tried with spaces, without, using your original post with +Rotext$ etc....
It at least stops giving me a syntax error notice but now its a runtime error notice "bad command".
Any ideas?
|
|
|
Post by B+ on Dec 23, 2020 23:11:15 GMT
Ha! Looks like tsh73 miss-posted, leaving half the code uncopied.
In the 80's (was it?) they had commercial in USA, famous line: "Where's the beef?" (Competing burger joints) some places you get a burger that is all bun and no burger.
Looks like tsh73 left out the meat of his post ;-))
Could you make any sense of the link to my masterpiece? (just kidding! my Christmas shopping is done and I am now enjoying the season.) I was drawing rotated letters but it's so long ago I have to study code myself to see what I was doing.
Another way to try if you can rotate bitmap images is to put letters into bitmaps and rotate them.
|
|
|
Post by tailoredreaction on Dec 23, 2020 23:37:21 GMT
Hey B+.
Thank you for that. I didn't want to say it too out loud.
I could go the bitmap route, although I haven't tried out adding any bitmaps yet. I was hoping I could just use the graphics here though. It seems like a simple little thing that must pop up a lot of times.
And lol, I couldn't possibly manipulate pixels to draw my own text. Not yet. Not ever I hope!
Have a good holiday.
Gord
|
|
|
Post by B+ on Dec 24, 2020 1:30:13 GMT
Hey B+. Thank you for that. I didn't want to say it too out loud. I could go the bitmap route, although I haven't tried out adding any bitmaps yet. I was hoping I could just use the graphics here though. It seems like a simple little thing that must pop up a lot of times. And lol, I couldn't possibly manipulate pixels to draw my own text. Not yet. Not ever I hope! Have a good holiday. Gord Yeah I did draw my own text and you can keep that! too much tedious work, but really should try it once when you've got time for the merit badge. So the idea is to print the text on screen and then steal err, ah, barrow the point locations. Trouble with that idea though, is that JB has no POINT function. But tsh73 to the rescue, he has, in that link, a work around that will give you pixel readings of points x, y on screen. Now if you don't want regular letters on screen in the final app, you will have to then save the patterns into arrays or some data file which wouldn't be bad to have around as would come in handy. Then you would only have to do the letters once! (It's pretty much what font files already!) Once you have the points patterns, it's easy peasy rotating the points through a rotation function like that found in the link. Reminder about JB, it is really meant to be beginner's introduction to programming freebee and to it's big brother Liberty Basic with the really advanced bells and whistles. That link again is justbasiccom.proboards.com/thread/233/flip-mirror
|
|
|
Post by tsh73 on Dec 24, 2020 3:18:04 GMT
sorry guys. There is symbol chr$(209) in code, and it breaks forum somehow. (and is inserted as several characters) So I modified the code explicitly showing chr$(209)
'mazinger JUST BASIC ROTATE FONT
'here is a function that generate the string comand for rotate text to graphics windows:
'Rotext$(Angle,Size,text)
nomainwin
WindowWidth = 800 WindowHeight = 600
open "" for Graphics as #main
#main "trapclose [quit]"
#main "place 10 80; "+Rotext$(0,8,"ABCDEFGHYJKLMN"+chr$(209)+"OPQRSTUVWXYZ") #main "place 80 80; "+Rotext$(30,8,"JUST ")+Rotext$(30,14,"BASIC")+Rotext$(30,8," ROTATE FONT") #main "place 10 100;"+Rotext$(90,6,"HELLO") #main "place 80 550;"+Rotext$(-45,10,"HAPPY NEW YEAR") #main "place 650 400;"+Rotext$(-80,6,"FELIZ A"+chr$(209)+"O NUEVO") #main "place 80 400;"+Rotext$(-80,20,"BLAH") #main "place 160 390;"+Rotext$(-80,16,"BLAH") #main "place 220 350;"+Rotext$(-80,10,"BLAH") #main "place 600 250;"+Rotext$(-90,22,"YES") #main "place 450 200;"+Rotext$(-80,16,"YES") #main "place 500 400;"+Rotext$(185,16,"SETUP") #main "flush"
wait'--------------------------------
function Rotext$(ang,size,txt$)
diagonal=sqr(2*(size^2))
U$="up;" D$="down;"
N$ ="north;turn "; ang;";go ";size; ";" 'North NE$="north;turn "; 45+ang;";go ";diagonal;";" 'North East E$ ="north;turn "; 90+ang;";go ";size; ";" 'East SE$="north;turn ";135+ang;";go ";diagonal;";" 'South East S$ ="north;turn ";180+ang;";go ";size; ";" 'South SW$="north;turn ";225+ang;";go ";diagonal;";" 'South West W$ ="north;turn ";-90+ang;";go ";size; ";" 'West NW$="north;turn ";-45+ang;";go ";diagonal;";" 'North West
for i=1 to len(txt$)
letter$=mid$(txt$,i,1)
select case letter$
case " ":t$= U$+E$+E$+E$
case "A":t$= D$+N$+N$+N$+NE$+SE$+S$+W$+W$+E$+E$+S$+S$+U$+E$ case "B":t$= D$+E$+E$+N$+N$+W$+W$+E$+NE$+N$+W$+W$+S$+S$+S$+S$+U$+E$+E$+E$ case "C":t$= E$+D$+E$+W$+NW$+N$+N$+NE$+E$+U$+S$+S$+S$+S$+E$
case "D":t$= D$+E$+NE$+N$+N$+NW$+W$+S$+S$+S$+S$+U$+E$+E$+E$ case "E":t$= D$+E$+E$+W$+W$+N$+N$+E$+E$+W$+W$+N$+N$+E$+E$+U$+S$+S$+S$+SE$ case "F":t$= D$+N$+N$+E$+E$+W$+W$+N$+N$+E$+E$+U$+S$+S$+S$+SE$
case "G":t$= D$+N$+N$+N$+NE$+E$+U$+SW$+S$+D$+E$+S$+SW$+W$+U$+E$+E$+E$ case "H":t$= D$+N$+N$+N$+N$+S$+S$+E$+E$+N$+N$+S$+S$+S$+S$+U$+E$ case "I":t$= D$+E$+N$+N$+N$+N$+W$+E$+E$+W$+S$+S$+S$+S$+E$+U$+E$
case "J":t$= N$+D$+SE$+NE$+N$+N$+N$+W$+U$+S$+S$+S$+S$+E$+U$+E$ case "K":t$= E$+E$+D$+N$+N$+W$+W$+E$+NE$+N$+U$+W$+W$+D$+S$+S$+S$+S$+U$+E$+E$+E$ case "L":t$= N$+N$+N$+N$+D$+S$+S$+S$+S$+E$+E$+U$+E$
case "M":t$= D$+N$+N$+N$+N$+SE$+S$+N$+NE$+S$+S$+S$+S$+U$+E$ case "N":t$= D$+N$+N$+N$+N$+SE$+SE$+N$+N$+S$+S$+S$+S$+U$+E$ case chr$(209):t$= D$+N$+N$+N$+SE$+SE$+N$+N$+U$+NE$+W$+D$+W$+W$+E$+E$+U$+S$+D$+S$+S$+S$+U$+E$
case "O":t$= D$+N$+N$+N$+NE$+E$+S$+S$+S$+SW$+W$+U$+E$+E$+E$ case "P":t$= D$+N$+N$+N$+N$+E$+E$+S$+S$+W$+W$+S$+S$+U$+E$+E$+E$ case "Q":t$= D$+N$+N$+N$+NE$+E$+S$+S$+S$+SW$+W$+U$+NE$+D$+SE$+U$+E$
case "R":t$= E$+E$+D$+N$+N$+W$+W$+E$+NE$+N$+W$+W$+S$+S$+S$+S$+U$+E$+E$+E$ case "S":t$= D$+E$+NE$+N$+W$+W$+N$+NE$+E$+U$+S$+S$+S$+SE$ case "T":t$= N$+N$+N$+N$+D$+E$+E$+W$+S$+S$+S$+S$+U$+E$+E$
case "U":t$= N$+D$+N$+N$+N$+S$+S$+S$+S$+E$+E$+N$+N$+N$+N$+U$+S$+S$+S$+S$+E$ case "V":t$= N$+D$+N$+N$+N$+S$+S$+S$+SE$+NE$+N$+N$+N$+U$+S$+S$+S$+S$+E$ case "W":t$= N$+N$+N$+N$+D$+S$+S$+S$+S$+NE$+SE$+N$+N$+N$+N$+S$+S$+S$+U$+SE$
case "X":t$= D$+N$+NE$+NE$+N$+U$+W$+W$+D$+S$+SE$+SE$+S$+U$+E$ case "Y":t$= E$+D$+N$+N$+NW$+N$+U$+E$+E$+D$+S$+SW$+U$+SE$+SE$ case "Z":t$= N$+N$+N$+N$+D$+E$+E$+S$+SW$+SW$+S$+E$+E$+U$+E$
end select
text$ = text$+t$
next
Rotext$=text$
end function'------------------
[quit] close #main end
|
|
|
Post by B+ on Dec 24, 2020 4:42:58 GMT
Ah so that's a drawn font! That's not a bad sized function for a drawn font!
I was just doing something with 7 segment digits, it would probably work like this or with this.
Update: well I didn't find anything about rotating anything. For Lander, we drew lander in different rotations and saved bmp's that way now that my brain has started digging into this problem and it also remembered I have the dot patterns for Ascii letters somewhere in my code collection which is looking more and more like it will be needed.
|
|
|
Post by Rod on Dec 24, 2020 9:47:57 GMT
Just to say, drawing text in it's normal orientation is no mean feat. Drawing at an angle is possible with Liberty BASIC. It uses the API and create font call which generates text in tenths of a degree rotation. libertybasiccom.proboards.com/thread/559/text-any-angleFor Just BASIC we need a work round, a few have been shown but they don't work like the API. The API manages the next character placement. So you only need specify the starting x,y.
|
|
|
Post by Rod on Dec 24, 2020 14:42:06 GMT
This is a simple rotation for vertical text placement. Best using a monospaced font. Set the width and height to suit the desired font, you can experiment. Calculating the actual width and height would take a lot of code.
nomainwin WindowWidth=800 WindowHeight=600 UpperLeftX=(DisplayWidth-WindowWidth)/2 UpperLeftY=(DisplayHeight-WindowHeight)/2 open "Rotate Text" for graphics_nsb as #1 #1 "down ; trapclose [quit]"
#1 "font courier 12" call rotate 50,50,100,300,9,12,"Hello this is verticle text " #1 "font courier_new 8" call rotate 50,50,120,300,7,9,"Hello this is verticle text " wait
[quit] close #1 end
sub rotate xx,yy,x,y,w,h, c$ 'xx,yy a conveniant location to draw the letter to be copied 'x,y the location to start drawing from 'w,h width height of font, experiment. 'if c$ ends with a space it will blank temporary drawing out for n= 1 to len(c$) #1 "place ";xx;" ";yy;" ;\";mid$(c$,n,1) for xn = 0 to w for yn= 0 to h #1 "getbmp bmp ";xx+xn;" ";yy-yn;" 1 1 " #1 "drawbmp bmp ";x-yn;" ";y-xn next next y=y-w next end sub
|
|
|
Post by B+ on Dec 24, 2020 15:53:45 GMT
From OP (original post)
Looks like Rod just did it! You can probably put the letters you are copying from to make the rotation any where on screen and/or put a little decoration over that spot when you are done printing.
Dang I was all set to try and do letters at any angle, but Rod's right, that will take quite some processing even if I have the dot data for letters and digits dug up.
|
|
andya
New Member
Posts: 14
|
Post by andya on Dec 24, 2020 16:59:07 GMT
Here's a simple SUB to rotate text 90 degrees clockwise or counter-clockwise Side Write SUB. Just download, unzip and run, to see a sample demo. It doesn't use anti-aliased font data, just simple bitmapped font data to rotate the text, so it will display slightly jagged text compared to windows text. The upside is that at smaller font sizes it will do in a pinch.
|
|
|
Post by Rod on Dec 24, 2020 17:53:43 GMT
Thanks B+ and Andya. Andya I had been searching for your text rotation code, I remembered you had posted. In the end I did the quick and fixed rotate. One reason was that it does preserve the antialiasing. Nice to see you are still reading.
|
|
andya
New Member
Posts: 14
|
Post by andya on Dec 24, 2020 19:06:08 GMT
Hi Rod,
The rotating of program printed text looks a lot nicer since it's anti-aliased. The only downside is that all the reading of the pixel data from the windows text takes a little longer.
The overall time used from that method can be reduced (for large amounts of rotated text) by reading the entire character set for a given font once for each of the individual letters, store in an array of rotated individual letters and then just look up the ASCII value of the input text and display. So if the text you want to output rotated 90/270 degrees is more than 128 characters, you will end up with a net savings of time over reading each character of the text.
So in a nutshell, read and rotate the characters of a font at a given size, save the rotated bitmaps for each font character and finally display the text to rotate by reading ASCII value of text to rotate and display the corresponding saved rotated bitmap.
Two related spin-offs come to mind: ___ 1) Allow you to make a SUB or Function that saves those rotated characters to avoid having to calculate on the fly for each character of text. ___ 2) I can envision where this method can be use to create rotated character sets of different fonts and sizes. As long as a format for the stored rotated bitmaps is defined, users can generate, save, and share different fonts and sizes.
I could do these things myself but, life seems to get in the way of my programming free time.
|
|