This forum is in archive mode. You will not be able to post new content.

Author Topic: Re-writing a code in C-language  (Read 1405 times)

0 Members and 1 Guest are viewing this topic.

Offline Infinityexists

  • Peasant
  • *
  • Posts: 74
  • Cookies: 1
    • View Profile
Re-writing a code in C-language
« on: May 12, 2012, 12:17:08 PM »
Hello,
 
I  need somebdy help who is good in GWBASIC and C-language,
actually I want someone to write this little GWBASIC code into C-Language
 
Code: [Select]

 10 DIM SAT(6000)
20   ON ERROR GOTO 20
30 SCREEN 9
40 RANDOMIZE TIMER
50 PAPPOG=20000
60 APERIG=8000
70 PANGINC=40
80 COL = 2
90 CLS
100 CIRCLE(5,5),3,COL
110 PAINT(5,5),COL,COL
120   LINE (0,0)-(10,10),COL
130   LINE (0,10)-(10,0),COL
140   GET(0,0)-(10,10),SAT
150   ON KEY(1) GOSUB 1040
160   KEY(1) ON
170  CLS
180   A$=""
190   LOCATE 23,20
200   INPUT "ENTER  APPOGEE (DEFAULT=20000 Km)..";APPOG
210   IF APPOG=0 THEN APPOG=PAPPOG
220   IF APPOG < 6400 OR APPOG > 60000! THEN SOUND 530,1:GOTO 170
230  CLS:LOCATE 23,20
240    INPUT "ENTER  PERIGEE (DEFAULT=8000 Km)..";PERIG
250    IF PERIG=0 THEN PERIG=APERIG
260    IF PERIG < 6400 OR PERIG > 12000 THEN SOUND 530,1:GOTO 230
270  CLS:LOCATE 23,20
280    INPUT "ENTER  ANGLE OF INCLINITION (DEFAULT=40 Deg)..";ANGINC
290    IF ANGINC=0 THEN ANGINC=PANGINC
300    IF ANGINC < 0 OR ANGINC > 360 THEN SOUND 530,1:GOTO 270
310    CLS
320    LOCATE 20,55:PRINT "APPOGEE (Km) = ";APPOG
330    LOCATE 21,55:PRINT "PERIGEE (Km) = ";PERIG
340    LOCATE 22,41:PRINT "ANGLE OF INCLINITION (Deg) = ";ANGINC
350    LOCATE 24,30:PRINT "PRESS  < C >  TO ALTER THE PARAMETERS.."
360    LOCATE 20,30:PRINT "PRESS  < F1 >  TO STOP...."
370    LINE(5,5)-(645,5),1
380    LINE -(645,195),1
390    LINE(5,5)-(5,195),1
400    LINE -(645,195),1
410    PAINT(3,3),0,0
420    CENTREX = 300
430    CENTREY = 100
440    APPOGEE = INT(APPOG/100)
450    PERIGEE = INT(PERIG/100)
460    EARTHRAD = INT(6370/100)
470    PI=3.141593:A=INT((APPOGEE+PERIGEE)/2):B=20
480    FOCUS = A - PERIGEE
490    EARTHX1 = FOCUS*COS(PI)
500    EARTHY1 = FOCUS*SIN(PI)
510    EARTHX = EARTHX1*COS((ANGINC-23)*PI/180)+EARTHY1*SIN((ANGINC-23)*PI/180)+CENTREX
520    EARTHY = EARTHY1*COS((ANGINC-23)*PI/180)-EARTHX1*SIN((ANGINC-23)*PI/180)+CENTREY
530    CIRCLE (EARTHX,EARTHY),EARTHRAD,1
540    PAINT (EARTHX,EARTHY),6,1
550    LINE ((EARTHRAD+5)*COS(113*PI/180)+EARTHX,(EARTHRAD+5)*SIN(113*PI/180)*8.76/12+EARTHY)-(EARTHRAD*COS(113*PI/180)+EARTHX,EARTHRAD*SIN(113*PI/180)*8.76/12+EARTHY),14
560    LINE ((EARTHRAD+5)*COS(293*PI/180)+EARTHX,(EARTHRAD+5)*SIN(293*PI/180)*8.76/12+EARTHY)-((EARTHRAD-2)*COS(293*PI/180)+EARTHX,(EARTHRAD-2)*SIN(293*PI/180)*8.76/12+EARTHY),14
570    FOR T=0 TO 360
580    X2=INT((RND*310)+5)
590   Y2=INT((RND*190)+5)
600    IF X2>(EARTHX-EARTHRAD) AND X2<(EARTHX+EARTHRAD) AND Y2>(EARTHY-EARTHRAD) AND Y2<(EARTHY+EARTHRAD) THEN 630
610    PCOL=1
620    PSET(X2,Y2),PCOL
630    X=A*COS(T*PI/180)
640    Y=B*SIN(T*PI/180)
650    X1=X*COS((ANGINC-23)*PI/180)+Y*SIN((ANGINC-23)*PI/180)+300
660    Y1=Y*COS((ANGINC-23)*PI/180)-X*SIN((ANGINC-23)*PI/180)+100
670    IF X1 > 630 THEN X1=630
680    IF X1 < 10 THEN X1=10
690    IF Y1 > 190 THEN Y1=190
700    IF Y1 < 10 THEN Y1=10
710    V= POINT(X1,Y1)
720    IF T>180 AND V>0 THEN 740
730    PSET(X1,Y1),14
740    NEXT
750    C=2000:D=100:E=3000:V=0
760   FOR T=360 TO 0 STEP -1
770 REM Z=T/90
780 REM IF Z=1 OR Z=3 OR Z=4 THEN DU=5 ELSE DU=.2
790     A$=INKEY$
800     IF A$="C" OR A$="c" THEN 170
810     X=A*COS(T*PI/180)
820     Y=B*SIN(T*PI/180)
830     X1=X*COS((ANGINC-23)*PI/180)+Y*SIN((ANGINC-23)*PI/180)+300
840     Y1=Y*COS((ANGINC-23)*PI/180)-X*SIN((ANGINC-23)*PI/180)+100
850     IF X1 > 630 THEN X1=630
860     IF X1 < 10 THEN X1=10
870     IF Y1 > 190 THEN Y1=190
880     IF Y1 < 10 THEN Y1=10
890     V= POINT(X1,Y1)
900     IF T>180 AND V<>14 THEN 910 ELSE 940
910   FOR I=1 TO C:NEXT
920 REM C=C-3
930     GOTO 1000
940   PUT(X1-5,Y1-5),SAT,XOR
950     IF T>30 AND T<310 THEN 955 ELSE 960
955     IF T>130 AND T<230 THEN 980 ELSE 965
960     FOR I= 1 TO E:NEXT: SOUND 5000,5
962 GOTO 990
965     FOR I= 1 TO C:NEXT
970 GOTO 990
980     FOR I= 1 TO D:NEXT
985     D=D+1
990     PUT(X1-5,Y1-5),SAT,XOR
1000   SOUND 6000,DU
1010     NEXT
1020     GOTO 760
1030 END
1040 RETURN 1030

I could have done this myself but since i've never used GWBASIC and have a very basic knowldge of C-Language I couldn't be able to understand the code.
 
I'd very glad if somebody would help me with this.
 
P.S: the thread is posted with the permission of one the Admin.

Offline gh0st

  • Sir
  • ***
  • Posts: 575
  • Cookies: 8
  • #DEDSec
    • View Profile
Re: Re-writing a code in C-language
« Reply #1 on: May 13, 2012, 12:21:44 AM »
this is a program that asks for 2 inputs in Km and 1 in degrees what does it do with them? that math algorithm does something of physics or some sort of that and ofcourse it does a graphic in the cartesian plane


the work hard part I guess will just be to reveal the algorithm which is on line 510 to 840


its about trigonometry the topic of finding the complement of an angle or something like this
« Last Edit: May 13, 2012, 02:05:05 AM by gh0st »

Offline xzid

  • Knight
  • **
  • Posts: 329
  • Cookies: 41
    • View Profile
Re: Re-writing a code in C-language
« Reply #2 on: May 13, 2012, 01:12:37 PM »
tried running it but gwbasic wouldn't stop giving me very uninformative error messages. anyway this doesn't require any skill in BASIC, it's just translation:

Code: (c) [Select]
_170:
        printf("ENTER  APPOGEE (DEFAULT=20000 Km)..");
        scanf("%d", &appog);
        if(appog == 0) appog = pappog;
        if(appog < 6400 || appog > 60000)
                goto _170;

Code: [Select]
170  CLS
180   A$=""
190   LOCATE 23,20
200   INPUT "ENTER  APPOGEE (DEFAULT=20000 Km)..";APPOG
210   IF APPOG=0 THEN APPOG=PAPPOG
220   IF APPOG < 6400 OR APPOG > 60000! THEN SOUND 530,1:GOTO 170

could make it C-style, but just a pure copy would work.

even the math, you don't need to understand what it does. you could drop all the UI stuff, or re-create it with ncurses.

either way I don't have the time to do this. also why do you need this in C?

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.