Porting GWBasic source to Locomotive

Started by Fabrizio Radica, 20:28, 01 October 17

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Fabrizio Radica

HI ^_^
i would like to port this code in Lovomotive Basic, from GWBasic but i've a littel problem with LINE (Draw in locomotive) command:





10 defint m,j,k,y:dim m(255)
20 e=2.7182318
30 def fnw(x)=k-fix(e^(-x/80)*cos(x/8)*60)
40 for j=0 to 255:m(j)=212:next
50 mode 0:cls
60 for k=180 to 0 step -8
70 d2=(k*4/3-128)^2
80 x=sqr(d2+16384):y=fnw(x)
90 if y<m(0) then m(0)=y else y=m(0)
100 plot 0,y
110 for j=1 to 255: l2=(j-128)^2
120 x=sqr(d2+l2):y=fnw(x)
130 if y<m(j) then m(j)=y else y=m(j)
140 draw (j-1,m(j-1))-(j,y)
150 next:next
170 if inkey$="" then 170



I've already converted PSET in PLOT
but the problem is on line 140

the original is:
LINE (j-1,m(j-1))-(j,y)
LINE (j-1,m(j-1))-(j,y)

how can convert it?

tnx :)

HAL6128

#1

According to the GWBasic user manual:
Syntax:
LINE [(x1,y1)]-(x2,y2) [,[attribute][,B[F]][,style]]
Comments:
x1,y1 and x2,y2 specify the end points of a line

normally you should do something like this:
move (x1,y1) > from (with x1=j-1 and y1=m(j-1))
draw (x2,y2) > to (with x2= j; y2=y)
...proudly supported Schnapps Demo, Pentomino and NQ-Music-Disc with GFX

SRS

10 DEFINT m,j,k,y:DIM m(255)
20 REM e=2.7182318 ' we dont need that on a CPC we have EXP
30 DEF FNw(x)=k-FIX(EXP(1)^(-x/80)*COS(x/8)*60)
40 FOR j=0 TO 255:m(j)=212:NEXT
50 MODE 0:CLS
60 FOR k=180 TO 0 STEP -8
70 d2=(k*4/3-128)^2
80 x=SQR(d2+16384):y=FNw(x)
90 IF y<m(0) THEN m(0)=y ELSE y=m(0)
100 PLOT 0,y
110 FOR j=1 TO 255: l2=(j-128)^2
120 x=SQR(d2+l2):y=FNw(x)
130 IF y<m(j) THEN m(j)=y ELSE y=m(j)
140 MOVE j-1,m(j-1):DRAW j,y
150 NEXT:NEXT
170 IF INKEY$="" THEN 170


But it is incredible slow ...

Seems you don't need to move/draw - its all about one pixel so just "plot j,y" should do the work, too

140 rem MOVE j-1,m(j-1):DRAW j,y
145 plot j,y



Fabrizio Radica

Quote from: SRS on 21:13, 01 October 17
10 DEFINT m,j,k,y:DIM m(255)
20 REM e=2.7182318 ' we dont need that on a CPC we have EXP
30 DEF FNw(x)=k-FIX(EXP(1)^(-x/80)*COS(x/8)*60)
40 FOR j=0 TO 255:m(j)=212:NEXT
50 MODE 0:CLS
60 FOR k=180 TO 0 STEP -8
70 d2=(k*4/3-128)^2
80 x=SQR(d2+16384):y=FNw(x)
90 IF y<m(0) THEN m(0)=y ELSE y=m(0)
100 PLOT 0,y
110 FOR j=1 TO 255: l2=(j-128)^2
120 x=SQR(d2+l2):y=FNw(x)
130 IF y<m(j) THEN m(j)=y ELSE y=m(j)
140 MOVE j-1,m(j-1):DRAW j,y
150 NEXT:NEXT
170 IF INKEY$="" THEN 170


But it is incredible slow ...

Seems you don't need to move/draw - its all about one pixel so just "plot j,y" should do the work, too

140 rem MOVE j-1,m(j-1):DRAW j,y
145 plot j,y



thank you!
it's really slow... but is normal, it make occlusions

AMSDOS

Quote from: SRS on 21:13, 01 October 17
10 DEFINT m,j,k,y:DIM m(255)
20 REM e=2.7182318 ' we dont need that on a CPC we have EXP
30 DEF FNw(x)=k-FIX(EXP(1)^(-x/80)*COS(x/8)*60)
40 FOR j=0 TO 255:m(j)=212:NEXT
50 MODE 0:CLS
60 FOR k=180 TO 0 STEP -8
70 d2=(k*4/3-128)^2
80 x=SQR(d2+16384):y=FNw(x)
90 IF y<m(0) THEN m(0)=y ELSE y=m(0)
100 PLOT 0,y
110 FOR j=1 TO 255: l2=(j-128)^2
120 x=SQR(d2+l2):y=FNw(x)
130 IF y<m(j) THEN m(j)=y ELSE y=m(j)
140 MOVE j-1,m(j-1):DRAW j,y
150 NEXT:NEXT
170 IF INKEY$="" THEN 170


But it is incredible slow ...

Seems you don't need to move/draw - its all about one pixel so just "plot j,y" should do the work, too

140 rem MOVE j-1,m(j-1):DRAW j,y
145 plot j,y



I noticed as one colour is being used (and some overlap occurring), if a simple test to check if the ink is only equal to zero to only plot at that stage. Would that help make it faster?


So perhaps something like this:



145 IF TEST(j,y)=0 THEN PLOT j,y



or perhaps?



140 WHILE TEST(j,y)=0
145   PLOT j,y
146 WEND



could be used.

* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Powered by SMFPacks Menu Editor Mod