Porting GWBasic source to Locomotive

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

0 Members and 1 Guest are viewing this topic.

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.718231830 def fnw(x)=k-fix(e^(-x/80)*cos(x/8)*60)40 for j=0 to 255:m(j)=212:next50 mode 0:cls60 for k=180 to 0 step -870 d2=(k*4/3-128)^280 x=sqr(d2+16384):y=fnw(x)90 if y<m(0) then m(0)=y else y=m(0)100 plot 0,y110 for j=1 to 255: l2=(j-128)^2120 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:next170 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]]
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 EXP30 DEF FNw(x)=k-FIX(EXP(1)^(-x/80)*COS(x/8)*60)40 FOR j=0 TO 255:m(j)=212:NEXT50 MODE 0:CLS60 FOR k=180 TO 0 STEP -870 d2=(k*4/3-128)^280 x=SQR(d2+16384):y=FNw(x)90 IF y<m(0) THEN m(0)=y ELSE y=m(0)100 PLOT 0,y110 FOR j=1 TO 255: l2=(j-128)^2120 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,y150 NEXT:NEXT170 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,y145 plot j,y`

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 EXP30 DEF FNw(x)=k-FIX(EXP(1)^(-x/80)*COS(x/8)*60)40 FOR j=0 TO 255:m(j)=212:NEXT50 MODE 0:CLS60 FOR k=180 TO 0 STEP -870 d2=(k*4/3-128)^280 x=SQR(d2+16384):y=FNw(x)90 IF y<m(0) THEN m(0)=y ELSE y=m(0)100 PLOT 0,y110 FOR j=1 TO 255: l2=(j-128)^2120 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,y150 NEXT:NEXT170 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,y145 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 EXP30 DEF FNw(x)=k-FIX(EXP(1)^(-x/80)*COS(x/8)*60)40 FOR j=0 TO 255:m(j)=212:NEXT50 MODE 0:CLS60 FOR k=180 TO 0 STEP -870 d2=(k*4/3-128)^280 x=SQR(d2+16384):y=FNw(x)90 IF y<m(0) THEN m(0)=y ELSE y=m(0)100 PLOT 0,y110 FOR j=1 TO 255: l2=(j-128)^2120 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,y150 NEXT:NEXT170 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,y145 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)=0145   PLOT j,y146 WEND`

could be used.

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

Home Computing Weekly Programs
Popular Computing Weekly Programs