Below is a condensed program that has resulted from my attempt to rotate text around the circumference of a circle. I would like to solicit ideas for making the speed of the subroutine, (containing the x and y loops), faster. On the hardware device, the program is taking just over 6 seconds to complete, currently.
The program works by placing twelve known 30° data points in a word list. Each data point is placed at the G1 origin, and passed to the subroutine, whereby each pixel in that string gets analyzed, its location on the circle determined (in the x,y loops), and affixed to G1; then when all is ready, transferred to GO for final display.
The x-y subroutine is slower than molasses in winter. The prime chokes, until it eventually coughs up the display. After trying several things that are slower yet, I wonder if there are still better, faster ways to accomplish this? If you patiently wait out the six-seven seconds watching a beautiful blank screen, this program should reward you with the graphic of my efforts, thus far.
Help is both needed and appreciated! This project is for fun(?) only, with no commercial intentions. You can see the run-time from Home. Enter: time(Atest); once the display shows up, push the HOME button. I'm seeing around 6.05 seconds.
Code:
wrt();
EXPORT Atest()
BEGIN
LOCAL a,b,j,ang, sa,ca;
LOCAL word; // local var rot was used to rotate legends 90° to circle
HAngle:=0; // Radians mode
// rot:=pi/2; // Rotate 90° for legends
// Word{list} pre-calculated legend parameters: {"Deg", ca, sa, a, b} is (12,5), 60 elements
// ca:=COS(ang-rot); sa:=SIN(ang-rot); Text rotation angle
word:={
"0.0°",0,-1,269,102,
"30°",0.5,-0.87,251,46,
"60°",0.87,-0.5,208,7,
"90°",1.0,0,150,0,
"120°",0.87,0.5,90,15,
"150°",0.5,0.87,53,59,
"180°",0,1,43,118,
"-150°",-0.5,0.87,64,178,
"-120°",-0.87,0.5,111,215,
"-90°",-1,0,169,219,
"-60°",-0.87,-0.5,224,201,
"-30°",-0.5,-0.87,260,156
};
DIMGROB(G1,320,240); // G1 workspace
RECT_P(); // Clear screen
ang:=0; // Initial starting angle
FOR j FROM 1 to 60 STEP 5 do
TEXTOUT_P(word(j),G1,0,0,1); // Temporary workspacet G1 origin (0,0)
ca:=word(j+1);
sa:=word(j+2);
a:=word(j+3);
b:=word(j+4);
wrt(ca,sa,a,b); // Compute legend location on screen
LINE_P(G1,156,109,105*COS(ang)+156,105*-SIN(ang)+109,RGB(255,0,0)); // 30° spokes in circle
RECT_P(G1,0,0,30,24); // Clear textout temporary workspace on G1
ang:=ang+pi/6; // Increment angle 30°
END; // For ang 30° step
ARC_P(G1,156,109,105,RGB(255,0,0)); // Draw outer circle
BLIT_P(G0,G1); // Draw legend on screen
DRAWMENU("","","","","",""); // Add Softmenu keys
freeze; // Pause for viewing
END; // Atest()
// =============================< Subroutines >=======================================
wrt(ca,sa,a,b)
BEGIN
LOCAL x,y;
// String is (24 pixels W x 10 pixels H), occuping ±25 pixels total when rotated. Circle: 210 pixel diameter, 105 pixel radius, center at (156, 109)
FOR x:=-25 TO 25 DO
FOR y:=-25 TO 25 DO
PIXON_P(G1,x+a,y+b,GETPIX_P(G1,x*ca-y*sa,x*sa+y*ca)); // Places legend at (x,y), rotated by ang-pi/2
END; // end y-height pixels
END; // end x-width pixels
END;