Question: Translate the code from the BASIC idiom to Java and then compile and run. You should see a Rainbow gradually appearing, point by point, in
Translate the code from the BASIC idiom to Java and then compile and run. You should see a Rainbow gradually appearing, point by point, in the Display window. /* Notes: PRINT becomes system.out.println ( ) ; PRINT USING is formatted output, you can likely ignore the formatting REM is a comment INPUT is a combination of System.out.println ( prompt) then use a Scanner to getNext ( ) the needed value. ^ means exponentiation, or "raising to a power" : allows multiple BASIC statements on the same line. GOSUB was a way to run a function. */ // Global floating points -- like BASIC float R, RC, R0, X, Y, B, C, N, I, T1, T2, RS, RP, RB, Rc, I1, I2, TH ; int NP = 0 ; // REM PLOT ON SCREEN void plot ( ) { /* 180 REM PLOT ON SCREEN 185 TH=ABS(TH) 190 IF TH>60 THEN RETURN 195 XP=320+320*(TH/60)*(X/B) 200 YP=325-300*(TH/60)*ABS(Y/B) 205 PSET(XP,YP),C: NP=NP+1 210 LOCATE 1,1: PRINT NP: RETURN */ if ( TH > 60.0 ) { return ; } float XP=139+139*(TH/60)*(X/B) ; float YP=159-159*(TH/60)*abs(Y/B) ; stroke ( C, 100, 100 ) ; point( XP + 300, 600 - YP ) ; NP ++ ; println ( NP + "," + XP + "," + YP + "," + C ) ; return ; } void setup ( ) { size ( 900, 600 ) ; background ( 0 ) ; // https://processing.org/reference/colorMode_.html colorMode(HSB, 100); } void draw ( ) { // Convert this BASIC to Java here: // Notes: for gosub 180, use // plot ( ) ; // // for the goto 30, use a do/while loop // // find Java/Processing equivalents for ATN, SIN, SQR, RND and ^ /* 25 R0=180/3.14159 30 REM RANDOM IMPACT PARAMETER 35 X=-1+2*RND(1) 40 Y=-1+2*RND(1) 45 B=SQR(X*X+Y*Y) 50 IF B>=1 THEN 30 55 REM COLOR & INDEX OF REFR. 60 C=1+INT(3*RND(1)) 65 N=1.33+.01*(C-1) 70 REM COMPUTE ANGLES 75 I=ATN(B/SQR(1-B*B)) 80 R=ATN(B/SQR(N*N-B*B)) 85 T1=(4*R-2*I)*R0 90 T2=(6*R-2*I)*R0-180 95 REM INTENSITY FACTORS 100 RS=(SIN(I-R)/SIN(I+R))^2 105 RP=(TAN(I-R)/TAN(I+R))^2 110 RB=(1-RP)*(1-RP) 115 RC=(1-RS)*(1-RS) 120 I1=(RS*RC+RP*RB)/2 125 I2=(RS*RS*RC+RP*RP*RB)/2 130 IF I1<.04*RND(1) THEN 140 135 TH=T1: GOSUB 180 140 IF I2<.02*RND(1) THEN 150 145 TH=T2: GOSUB 180 150 GOTO 30 */ } Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
