Author Topic: I've asked this before... but...  (Read 1849 times)

johnno56

  • Guest
I've asked this before... but...
« on: April 16, 2015 »
I'm going to raise the "Tutorial" subject again.

I have asked before for any step-by-step tutorials on how to program with Naalaa. You guys have been more than generous with your programs and suggestions. I am not as clever as most of you, and as a result, it takes me longer to learn. I have tried many types of "Basic" in the past and have found Naalaa to be one of the best.

I will try to explain my difficulties. I have been directed to the "Examples" a number of times and at times I can pick apart the necessary code that I need. Without a step-by-step I feel as though I have been handed a dictionary and instructed to write a book. I am not sure if I am making any sense. I am desperately trying to forget basic with line numbers and trying to learn how to code properly but most of the time I get too frustrated and give up. Mainly because of lack of knowledge. "Google" will only go so far... For me, the best way to learn, is repetition.

There are a LOT of commands in Naalaa to learn. Is there a complete list of them, with sample code for each, that can be referenced? This would help greatly.

If I am the only one with difficulty in this area then feel free to ignore my request. I will not be offended. I will still learn, it may take me longer, but I will learn.

J

kcfb

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: I've asked this before... but...
« Reply #1 on: April 17, 2015 »
I seem to remember that there used to be a very good reference manual for NaaLaa 5 that listed the commands with examples, but I think I lost it with a lot of other files when a flashdrive failed ages ago - much of that may still be relevant if someone has a copy saved somewhere?

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #2 on: April 18, 2015 »
I'm going to raise the "Tutorial" subject again.

I have asked before for any step-by-step tutorials on how to program with Naalaa. You guys have been more than generous with your programs and suggestions. I am not as clever as most of you, and as a result, it takes me longer to learn. I have tried many types of "Basic" in the past and have found Naalaa to be one of the best.

I will try to explain my difficulties. I have been directed to the "Examples" a number of times and at times I can pick apart the necessary code that I need. Without a step-by-step I feel as though I have been handed a dictionary and instructed to write a book. I am not sure if I am making any sense. I am desperately trying to forget basic with line numbers and trying to learn how to code properly but most of the time I get too frustrated and give up. Mainly because of lack of knowledge. "Google" will only go so far... For me, the best way to learn, is repetition.

There are a LOT of commands in Naalaa to learn. Is there a complete list of them, with sample code for each, that can be referenced? This would help greatly.

If I am the only one with difficulty in this area then feel free to ignore my request. I will not be offended. I will still learn, it may take me longer, but I will learn.

J

I am curious if this is a Basic-like dialect, what Basic(s) are most similar to NaaLaa or from which NaaLaa was inspired. For example which familiar keywords are still around. In first example I see PRINT is gone and two others replace it, write and wln.

How similar is write to print? do ; and , and nothing still work?
wln much more sophisticated with many associate keywords

Oh there is documentation in Help, oh and there is Input/Output. I will start there. Try old programs in new language.

Can anyone say if this language complete makeover of, say, a QB?

B+
B+

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #3 on: April 19, 2015 »
Quick question,

Is this board best to put code for learning NaaLaa, first attempts and discussion?
I do not want to show off some neat new trick or tip (Snippet) or latest game.

I just want to share with folks getting started with NaaLaa.

B+
B+

Peter

  • Guest
Re: I've asked this before... but...
« Reply #4 on: April 19, 2015 »
Quote
I just want to share with folks getting started with NaaLaa.

B+,
you got my vote.




B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #5 on: April 19, 2015 »
Quote
I just want to share with folks getting started with NaaLaa.

B+,
you got my vote.

OK with that overwhelming approval, I will float a test case:
Code: [Select]
rem Simple Sieve.txt 2015-04-18 B+ test translation from other Basic's
d=1000
wln "Primes to "+str$(d)+":"
wln
c[d+1]
for i=2 to d
if c[i]=0
     write str$(i)+" "
             cnt=cnt+1 
             if cnt % 15=0 then wln
       for j= i to d
               m=i*j
                   if m>d then break
                 c[m]=1
         next
endif
next
wln
wln
wln "prime count is "+str$(cnt)
rem better be 168 for 1000
wait keydown

EDIT: Wow the forum software is different (you can select the code! here) and the code is not how it looks in my file but close enough.
EDIT: fixed indents
« Last Edit: April 20, 2015 by B+ »
B+

johnno56

  • Guest
Re: I've asked this before... but...
« Reply #6 on: April 19, 2015 »
Quote
I just want to share with folks getting started with NaaLaa.

B+,
you got my vote.

My guess would be, "If you want to share it, simple or complex, go for it."

But, as for me, I need all the learning I can get. Simple for me is good. Complex is a goal to work towards.

J

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #7 on: April 20, 2015 »
Hi J,

I spent a half hour writing about float including making up a table of sign values in code and lost it with forum software...?

You need to know about floats mainly when the sub or function calls for them in parameters.
Trig functions are good example:

Code: [Select]
do
i#=i#+10.0
a#=sin#(i#)
wln "sin(" +str$(i#)+") = "+str$(a#)
until i#>=90.0
wait keydown
« Last Edit: April 20, 2015 by B+ »
B+

johnno56

  • Guest
Re: I've asked this before... but...
« Reply #8 on: April 20, 2015 »
Please correct me if I am wrong...
(... I know about the circle command. This to help me understand the differences between integer and floating point and when to use them ...)

Code: [Select]
rem
rem Circle test
rem

set window 0,0,400,400

i# = 0.0
x = 200
y = 200
r = 200

do
xpos# = sin#(i#) * float(r)
ypos# = cos#(i#) * float(r)
rem float(r) converts integer 200 to decimal 200.0?
rem that way the entire line is a decimal calculation?
set color 255,0,0
rem ... and the int() converts the decimal into an integer
rem so that the entire line would be an integer calculation?
draw pixel int(xpos#)+x,int(ypos#)+y
i# = i# + 0.1
until i# > 360.0
rem so... using 360.0 or float(360) is correct
rem whereas using only 360 will cause an error because
rem i# is decimal and 360 is integer?

rem ... my brain hurts ...

wait keydown

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #9 on: April 20, 2015 »
Hi J,

It is getting late for me and my brain is going foggy but...

Just a glance at your code and I see maybe it should be float#(r) as it should be the consistent habit of functions to be typed with the same junk they are expected to return.

So a right$ string function is expected to return a string,
a len(string$) is expected to return an integer,
therefore a float#(integer) is expected to return the float# type for r
same thing for float#("1234.4321") return a float of a string that happens to look like a float#.

B+
B+

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #10 on: April 20, 2015 »
I fixed up my own right$ function:

Code: [Select]
function rite$(stringy$,amount)
l=len(stringy$)
return mid$(stringy$,l-amount,amount)
endfunc

I added this to my Simple Sieve program and now I can display a nice neat table:
PS: I also had to initialize my counter to 0 and figure out how to enlarge the screen with set window, much better, more room!

B+
« Last Edit: April 20, 2015 by B+ »
B+

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #11 on: April 20, 2015 »
Code: [Select]
rem
rem Circle test, question posed by J at Naalaa 2015-04-19 1.39 AM to B+
rem first B+ had to see what pixel procedure expects x,y are integers
rem ah B+ also sees Naalaa lacks a circle function for crying out loud!
rem so good idea to make a reusable procedure here
sq=450
set window 0,0,sq,sq
rem origin
x0 = int(sq/2)
y0 = int(sq/2)

for r=200 to 225
proc circle x0,y0,r
next
r=200
do
proc circle x0,y0,r
r=r-25
until r<=10
for r=0 to 25
proc circle x0,y0,r
next
x1=int(x0/2)
for r=0 to 20
  proc circle x1,x1,r
next
x2=x0+x1
for r=0 to 20
  proc circle x1,x2,r
next
for r=0 to 20
  proc circle x2,x1,r
next
for r=0 to 20
  proc circle x2,x2,r
next

wait keydown
end
procedure circle(x,y,r)
i#=0.0
do
  rem set up x,y as integers for set pixel call with just integers to add
xpos = int(sin#(i#) * float#(r))
ypos = int(cos#(i#) * float#(r))
rem float#(r) converts integer 200 to decimal 200.0? yeah
rem that way the entire line is a decimal calculation? yeah good for rounding errors
set color 255,0,0
rem ... and the int() converts the decimal into an integer? yeah
rem so that the entire line would be an integer calculation? now next line has 0 floats to deal with
draw pixel xpos+x,ypos+y
i# = i# + 0.2
  rem so... using 360.0 or float#(360) is correct? yeah probably gives smoother circle
  rem whereas using only 360 will cause an error because
  rem i# is decimal and 360 is integer?

  rem ... my brain hurts ...
  rem  yeah 2.04 AM now for me too! I like incrementing by .something but .1 is really too fine? try .5 first
until i# >= 360.0
endproc
B+

johnno56

  • Guest
Re: I've asked this before... but...
« Reply #12 on: April 20, 2015 »
Cool. Thanks, B+.

J

johnno56

  • Guest
Re: I've asked this before... but...
« Reply #13 on: April 20, 2015 »
Here is a different circle routine - not mine, just modified for N6.

Code: [Select]
rem
rem Bresenham's circle plot
rem

set window 0,0,400,400

xc = 200
yc = 200
r = 150
x = 0
y = r
d = 3 - 2* r

procedure drawcircle(xc,yc,x,y)
draw pixel xc + x, yc + y
draw pixel xc - x, yc + y
draw pixel xc + x, yc - y
draw pixel xc - x, yc - y
draw pixel xc + y, yc + x
draw pixel xc - y, yc + x
draw pixel xc + y, yc - x
draw pixel xc - y, yc - x
endproc

do
proc drawcircle xc,yc,x,y
x = x + 1
if d < 0 then
d = d + 4 * x + 6
else
y = y - 1
d = d + 4 * (x - y) + 10
endif
proc drawcircle xc,yc,x,y
rem wait
until x >= y

wait keydown

J

Peter

  • Guest
Re: I've asked this before... but...
« Reply #14 on: April 20, 2015 »
Hi Johno56

here's the difference between FLOAT & INT.

rem
rem   Bresenham's circle plot
rem
Code: [Select]
set window 0,0,400,400
set redraw off

xc# = 200.0
yc# = 200.0
r#  = 150.0
x#  = 0.0
y#  = r
d#  = 3.0 - 2.0 * r

procedure drawcircle(xc#,yc#,x#,y#)
draw pixel int(xc + x), int(yc + y)
draw pixel int(xc - x), int(yc + y)
draw pixel int(xc + x), int(yc - y)
draw pixel int(xc - x), int(yc - y)
draw pixel int(xc + y), int(yc + x)
draw pixel int(xc - y), int(yc + x)
draw pixel int(xc + y), int(yc - x)
draw pixel int(xc - y), int(yc - x)
endproc

do
proc drawcircle xc,yc,x,y
x = x + 1.0
if d < 0.0 then
d = d + 4.0 * x + 6.0
else
y = y - 1.0
d = d + 4.0 * (x - y) + 10.0
endif
_drawcircle xc,yc,x,y
rem wait
until x >= y
redraw
wait keydown