Author Topic: Worm Screw  (Read 2493 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
Worm Screw
« on: December 25, 2013, 02:09:32 PM »
Deleted
« Last Edit: April 25, 2015, 03:23:41 AM by Peter »

JRS

  • Guest
Re: Worm Screw
« Reply #1 on: December 25, 2013, 02:44:04 PM »
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().


Charles Pegge

  • Guest
Re: Worm Screw
« Reply #2 on: December 25, 2013, 02:47:19 PM »
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.
« Last Edit: December 25, 2013, 02:54:26 PM by Charles Pegge »

JRS

  • Guest
Re: Worm Screw
« Reply #3 on: December 25, 2013, 04:59:11 PM »
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.

Quote
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);

Code: [Select]
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.

Code: [Select]
 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$
« Last Edit: December 25, 2013, 09:50:37 PM by John »

JRS

  • Guest
Re: Worm Screw
« Reply #4 on: December 25, 2013, 10:00:40 PM »
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.



.

Charles Pegge

  • Guest
Re: Worm Screw
« Reply #5 on: December 26, 2013, 06:28:00 AM »
Adjusting negative angles to positive:

Code: [Select]
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

JRS

  • Guest
Re: Worm Screw
« Reply #6 on: December 26, 2013, 11:06:10 AM »
Still can't get it to work. (seg. fault on Draw_FillCircle)