Oxygen Basic
Programming => Example Code => Topic started by: Peter on December 25, 2013, 02:09:32 PM
-
Deleted
-
Peter,
I tried to convert your example to SB/SDL and the SB RAD() function errors when getting a value range of -254. (first iteration value for a - i) I'm surprised that O2 allows a negative value for RAD().
-
This is what you may dream of, after eating too much plum pudding. :o
Yes, negative degs and rads are okay with the FPU trig, but should of course, be modulated to avoid building up huge values.
-
Using your Radians() function. The SB SDL Draw_FillCircle() function is seg faulting on the call. :-[ I changed the radius (i) to a hard coded 30 and it drew a filled circle. The value of 255 causes the seg. fault. Maybe the SDL_draw library doesn't like drawing off the screen surface.
Note: *super (screen surface) is handled internally as a global variable.
Draw a filled circle with center x0,y0 and radius r.
void Draw_FillCircle(SDL_Surface *super,
Sint16 x0, Sint16 y0, Uint16 r,
Uint32 color);
DECLARE SUB Window ALIAS "SB_Window" LIB "sdl"
DECLARE SUB CLS ALIAS "SB_CLS" LIB "sdl"
DECLARE SUB RGB ALIAS "SB_RGB" LIB "sdl"
DECLARE SUB WaitKey ALIAS "SB_WaitKey" LIB "sdl"
DECLARE SUB Draw_FillCircle ALIAS "SB_Draw_FillCircle" LIB "sdl"
DECLARE SUB UpdateRect ALIAS "SB_UpdateRect" LIB "sdl"
Function Radians(radius)
Radians = radius*pi/180
End Function
Window 640,480, "Worm Screw"
FOR a = 1 TO 360 STEP 5
CLS(RGB(0,0,255))
FOR i = 255 TO 1 STEP -1
PRINT Radians(a-i),"\n"
Draw_FillCircle(200+SIN(Radians(a-i))*40, 120+COS(Radians(a-i))*40, i, RGB(i, i, i))
Draw_FillCircle(200+COS(Radians(a-i))*40, 120+SIN(Radians(-a-i))*40, i, RGB(i, i, i))
Draw_FillCircle(200+SIN(Radians(a-i))*40, 120+COS(Radians(a-i))*40, i, RGB(i, i, i))
NEXT
UpdateRect
NEXT
WaitKey
jrs@laptop:~/sb/sb22/sdl$ scriba wormscrew.sb
-4.433136e+00
Segmentation fault (core dumped)
jrs@laptop:~/sb/sb22/sdl$
If I wrap the X,Y positions with an INT(), it still seg faults.
FOR i = 255 TO 1 STEP -1
PRINT INT(200+SIN(Radians(a-i))*40),"\n"
PRINT INT(120+COS(Radians(a-i))*40),"\n"
Draw_FillCircle(INT(200+SIN(Radians(a-i))*40), INT(120+COS(Radians(a-i))*40), i, RGB(i, i, i))
Draw_FillCircle(INT(200+COS(Radians(a-i))*40), INT(120+SIN(Radians(-a-i))*40), i, RGB(i, i, i))
Draw_FillCircle(INT(200+SIN(Radians(a-i))*40), INT(120+COS(Radians(a-i))*40), i, RGB(i, i, i))
NEXT
jrs@laptop:~/sb/sb22/sdl$ scriba wormscrew.sb
238
108
Segmentation fault (core dumped)
jrs@laptop:~/sb/sb22/sdl$
-
I just ran your example under O2 to see what it is suppose to look like and the X,Y positions I'm getting aren't even close. It could be the COS/SIN functions. With negative values being used I don't know where to start. Anyways I have waste too much time on this already and attached the screen shot of it running under O2 under Wine.
.
-
Adjusting negative angles to positive:
include "sw.inc"
Window 640,480,1
sys a1,a2
while Key(27)=0
For a=1 to 360 step 5
Cls sw_blue
For i=255 to 1 step -1
a1=a-i
a2=-a-i
while a1<0 : a1+=360 : wend
while a2<0 : a2+=360 : wend
FillCircle 200+sin(Rad(a1))*40,120+cos(Rad(a1))*40,i, RGB i, i, i
FillCircle 200+cos(Rad(a1))*40,120+sin(Rad(a2))*40,i,RGB i, i, i
FillCircle 200+sin(Rad(a1))*40,120+cos(Rad(a1))*40,i, RGB i, i, i
Next
DoEvents
Sync
Next
Wend
CloseWindow
-
Still can't get it to work. (seg. fault on Draw_FillCircle)