1. A Little QBasic help

Dear Euphoria Folks,

I was wondering if anyone could give me a hand
with a little bit of Qbasic code. I was attempting
to port a simple little program to Eu, and got stuck.
Here's the beginning of the code I'm talking about :

DEFINT A-Z
RANDOMIZE TIMER
CONST  anzbee = 100
DIM g(anzbee, 1), p(anzbee, 1), pa(anzbee, 1), pa2(anzbee, 1)
FOR a = 0 TO anzbee
g(a, 0) = INT(RND * 7 - 3)
g(a, 1) = INT(RND * 7 - 3)
p(a, 0) = INT(RND * 640)
p(a, 1) = INT(RND * 480)
pa(a, 0) = INT(RND * 640)
pa(a, 1) = INT(RND * 480)
NEXT
SCREEN 12

That's the bulk of it -- and one last line :

g(0,0) = (g(0,0) + RND * 2 - 1) MOD 10

If anybody could help me out with this, it
would be much appreciated. Thanks!

Chris Cox
cox.family at sk.sympatico.ca

new topic     » topic index » view message » categorize

2. Re: A Little QBasic help

Doug Cox wondered about converting aQBasic program.

Here's a go at it. I didn't test it, though. Note that the you have to add 1
to all the indexes, since Euphoria does not support indexes starting at
zero.

--- untested code ---

constant anzbee = 100

sequence g, p, pa, pa2

for a = 0 to anzbee do


    g = append( g, { rand(7)-3, rand(7)-3 } )
    p = append( p, { rand(640), rand(480) } )
    pa = append( pa, { rand( 640 ), rand( 480 ) } )
    pa2 = append( pa2, { 0, 0 } )


end for

if graphics_mode( 12 ) then
    puts( 1, "Unable to set screen mode\n" )
    abort(0)
end if


g[1,1] = remainder( (g[1,1] + rand(2)-1), 10 )

-- end untested code

 the arguments to remainder might be backwards, and you might need to
subtract 1 from the random number equation, too.

Some people might prefer initializing the arrays as:

    g = repeat( { 0, 0 }, anzbee )

or

    g = repeat( repeat( 0, 2 ), anzbee )

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

3. A Little QBasic help

>>>>>
I was wondering if anyone could give me a hand
with a little bit of Qbasic code. I was attempting
to port a simple little program to Eu, and got stuck.
Here's the beginning of the code I'm talking about :
<<<<<

Chris,

I was a QBasic programmer for a month, before I got into Euphoria.  Looki=
ng
at your code, I went "Wow, looks so awkward".  Would have to actually go
into help and look up all that stuff (think someone else is giving you a
hand?  haven't read this message yet).

Anyway, in general, now I'm kind of scared, because I'm taking a high
school QBasic course in the fall (signed up for it before I know Euphoria=
).
 Its a prereq to Visual Basic.

Last thing.  A better title from "euphoria folks" would be Euphorians.  W=
e
are really another race, come to liberate the Earth from the C empire and=

the BASIC minions.

--Alan
 =

new topic     » goto parent     » topic index » view message » categorize

4. Re: A Little QBasic help

At 18:34 06-08-98 -0700, you wrote:
>Dear Euphoria Folks,
>
>I was wondering if anyone could give me a hand
>with a little bit of Qbasic code. I was attempting
>to port a simple little program to Eu, and got stuck.
>Here's the beginning of the code I'm talking about :
>
>DEFINT A-Z
>RANDOMIZE TIMER
>CONST  anzbee = 100
>DIM g(anzbee, 1), p(anzbee, 1), pa(anzbee, 1), pa2(anzbee, 1)
>FOR a = 0 TO anzbee
>g(a, 0) = INT(RND * 7 - 3)
>g(a, 1) = INT(RND * 7 - 3)
>p(a, 0) = INT(RND * 640)
>p(a, 1) = INT(RND * 480)
>pa(a, 0) = INT(RND * 640)
>pa(a, 1) = INT(RND * 480)
>NEXT
>SCREEN 12
>
>That's the bulk of it -- and one last line :
>
>g(0,0) = (g(0,0) + RND * 2 - 1) MOD 10
>
>If anybody could help me out with this, it
>would be much appreciated. Thanks!
>
>Chris Cox
>cox.family at sk.sympatico.ca
>
include graphics.e

constant anzbee = 100
sequence g,p,pa,pa2
g = repeat({0,0},anzbee)  -- this replace DIM statement
p = repeat({0,0},anzbee)
pa = repeat({0,0},anzbee)
pa2 = repeat({0,0},anzbee)

for a = 1 to anzbee do
 g[a][1] = rand(7)-3   -- in euphoria index begin at 1 not 0
 p[a][1] = rand(640)
 p[a][2] = rand(480)
 pa[a][1] = rand(640)
 pa[a[2] = rand(480)
end for
g[1][1] = remainder(g[1][1]+rand(2)-1,10) -- this replace:  g(0,0) = (g(0,0) +
RND * 2 - 1) MOD 10

if graphics_mode(18) then  -- replace SCREEN 12
  abort(1)
end if

I hope I did it right,




Jacques Deschenes
Baie-Comeau, Quebec
Canada
desja at globetrotter.qc.ca

new topic     » goto parent     » topic index » view message » categorize

5. Re: A Little QBasic help

I understood the code perfectly, and I still say QBasic is easier than
Euphoria in some ways. I can't really convert QBasic to Eu, but you should
try this guy's EBasic (I forgot his name). It does a pretty good job
converting QB to Eu.

Oh yeah, I'm gonna code my tutorial in a language called MoonRock, because I
simply don't have the routines nessicary to create the version I want in
Euphoria.

- Nate

-----Original Message-----
From: Jacques Deschenes <desja at GLOBETROTTER.QC.CA>
To: EUPHORIA at LISTSERV.MUOHIO.EDU <EUPHORIA at LISTSERV.MUOHIO.EDU>
Date: August 6, 1998 9:31 PM
Subject: Re: A Little QBasic help


>At 18:34 06-08-98 -0700, you wrote:
>>Dear Euphoria Folks,
>>
>>I was wondering if anyone could give me a hand
>>with a little bit of Qbasic code. I was attempting
>>to port a simple little program to Eu, and got stuck.
>>Here's the beginning of the code I'm talking about :
>>
>>DEFINT A-Z
>>RANDOMIZE TIMER
>>CONST  anzbee = 100
>>DIM g(anzbee, 1), p(anzbee, 1), pa(anzbee, 1), pa2(anzbee, 1)
>>FOR a = 0 TO anzbee
>>g(a, 0) = INT(RND * 7 - 3)
>>g(a, 1) = INT(RND * 7 - 3)
>>p(a, 0) = INT(RND * 640)
>>p(a, 1) = INT(RND * 480)
>>pa(a, 0) = INT(RND * 640)
>>pa(a, 1) = INT(RND * 480)
>>NEXT
>>SCREEN 12
>>
>>That's the bulk of it -- and one last line :
>>
>>g(0,0) = (g(0,0) + RND * 2 - 1) MOD 10
>>
>>If anybody could help me out with this, it
>>would be much appreciated. Thanks!
>>
>>Chris Cox
>>cox.family at sk.sympatico.ca
>>
>include graphics.e
>
>constant anzbee = 100
>sequence g,p,pa,pa2
>g = repeat({0,0},anzbee)  -- this replace DIM statement
>p = repeat({0,0},anzbee)
>pa = repeat({0,0},anzbee)
>pa2 = repeat({0,0},anzbee)
>
>for a = 1 to anzbee do
> g[a][1] = rand(7)-3   -- in euphoria index begin at 1 not 0
> p[a][1] = rand(640)
> p[a][2] = rand(480)
> pa[a][1] = rand(640)
> pa[a[2] = rand(480)
>end for
>g[1][1] = remainder(g[1][1]+rand(2)-1,10) -- this replace:  g(0,0) =
(g(0,0) + RND * 2 - 1) MOD 10
>
>if graphics_mode(18) then  -- replace SCREEN 12
>  abort(1)
>end if
>
>I hope I did it right,
>
>
>
>
>Jacques Deschenes
>Baie-Comeau, Quebec
>Canada
>desja at globetrotter.qc.ca
>

new topic     » goto parent     » topic index » view message » categorize

6. Re: A Little QBasic help

Doug Cox wrote:
>
> Dear Euphoria Folks,
>
> I was wondering if anyone could give me a hand
> with a little bit of Qbasic code. I was attempting
> to port a simple little program to Eu, and got stuck.
> Here's the beginning of the code I'm talking about :
>
> DEFINT A-Z -- declares any a => z to be an integer variable, not needed for
> the code
shown below.

> RANDOMIZE TIMER -- seeds the random number generator with the current time,
> not
needed in Euphoria, since rand() is automatically randomly seeded.

> CONST  anzbee = 100 -- replace with
constant anzbee = 101 -- assuming you really want 101 random numbers

> DIM g(anzbee, 1), p(anzbee, 1), pa(anzbee, 1), pa2(anzbee, 1) -- creates
> arrays
of 101 x 2 integers.  Replace with:

sequence g, p, pa, pa2 -- declares these variables
g = repeat({0,0},anzbee) -- creates 101 instances of {0,0}
p = g pa = g pa2 = g -- creates more just like it.

> FOR a = 0 TO anzbee -- don't need to pre-declare the loop counter (a)
for a = 1 to anzbee -- Euphoria uses 1 based array addressing, not zero
based

> g(a, 0) = INT(RND * 7 - 3)
> g(a, 1) = INT(RND * 7 - 3)
g[a] = {rand(7)-4,rand(7)-4} -- this returns numbers between -3 and + 3

> p(a, 0) = INT(RND * 640)
> p(a, 1) = INT(RND * 480)
p[a] = {rand(640)-1,rand(480)-1} -- return random integer between 0 and
639/479

> pa(a, 0) = INT(RND * 640)
> pa(a, 1) = INT(RND * 480)
pa[a] = {rand(640)-1, rand(380)-1} -- same

> NEXT
end for -- ends the for loop.

> SCREEN 12 -- this is 640 x 480 x 16 color VGA mode, replace with
graphics_mode(18) -- try also 19, 256, or 257 for nicer (256 color)
modes
>
> That's the bulk of it -- and one last line :
>
> g(0,0) = (g(0,0) + RND * 2 - 1) MOD 10
-- you're not going to have a zero element in a Euphoria array, so
g[0][0] is
invalid. Your Euphoria array will start at g[1][1]. Remember this in any
code that uses these arrays.
RND * 2 - 1 MOD 10 returns a number between -1 and 0, replace with

 rand(2)-2 -- returns either 1 or 2, minus 2 equals either zero or minus
1

Hope this helps.

Regards,

Irv



>
> If anybody could help me out with this, it
> would be much appreciated. Thanks!
>
> Chris Cox
> cox.family at sk.sympatico.ca

new topic     » goto parent     » topic index » view message » categorize

7. Re: A Little QBasic help

Alan Tu wrote:
>
> >>>>>
> I was wondering if anyone could give me a hand

> Chris,
>
> I was a QBasic programmer for a month, before I got into Euphoria.  Looking
> at your code, I went "Wow, looks so awkward".  Would have to actually go
> into help and look up all that stuff

Believe it. I haven't programmed in Basic in about 10 years, so I _did_
go look it up. Not all that bad, just some awkward conversions.

> Anyway, in general, now I'm kind of scared, because I'm taking a high
> school QBasic course in the fall (signed up for it before I know Euphoria).
>  Its a prereq to Visual Basic.

One good thing - you'll have a big head-start, since you are already
in the habit of structuring your programs. Something Basic doesn't
require, but I'll bet the instructor does!

> Last thing.  A better title from "euphoria folks" would be Euphorians.  We
> are really another race, come to liberate the Earth from the C empire and
> the BASIC minions.
>
He,he... I like that.

Irv

new topic     » goto parent     » topic index » view message » categorize

8. Re: A Little QBasic help

Irv wrote:
>
> Doug Cox wrote:
> >
> > Dear Euphoria Folks,
> >
> > I was wondering if anyone could give me a hand
> > with a little bit of Qbasic code.

<snip previously posted code>

Well, since everyone else included a disclaimer, i.e. "untested code",
I thought I should add:
I tested my code - both in Basic and in Euphoria.
They function similarly, as best I can tell. However,
as everyone knows, there are many places where bugs can pop up.
Objects in the mirror may be closer than they appear.
It ain't over 'til the fat lady sings.
Your mileage may vary,
etc.

Please feel free to ask again if there are problems.

Irv

new topic     » goto parent     » topic index » view message » categorize

9. Re: A Little QBasic help

Irv wrote:
>
> RND * 2 - 1 MOD 10 returns a number between -1 and 0, replace with
>
>  rand(2)-2 -- returns either 1 or 2, minus 2 equals either zero or minus
> 1
>
OOPS! Actually, that returns a real ranging from -1 to +1, but since it
is being assigned to an integer (thru addition), you can just as easily
use rand(3) - 2 -- which will be either 1,0,or -1.
At least, I think so. Does this program do some neat graphics?

Corrections encouraged.

Irv

new topic     » goto parent     » topic index » view message » categorize

10. Re: A Little QBasic help

Dear Euphorians,

Thanks for all the help. It's very much appreciated.
I've found the original source for the program, so
I've posted it below. I've had a little problem with
drawing lines (it tells me I can't do it with sequences)
and with the IF statement, which it says it requires
an atom for. Here's the code, and thanks again!

Chris Cox
cox.family at sk.sympatico.ca

BEE.BAS

DEFINT A-Z
RANDOMIZE TIMER
CONST anzbee = 100
DIM g(anzbee, 1), p(anzbee, 1), pa(anzbee, 1), pa2(anzbee, 1)
FOR a = 0 TO anzbee
g(a, 0) = INT(RND * 7 - 3)
g(a, 1) = INT(RND * 7 - 3)
p(a, 0) = INT(RND * 640)
p(a, 1) = INT(RND * 480)
pa(a, 0) = INT(RND * 640)
pa(a, 1) = INT(RND * 480)
NEXT
SCREEN 12
DO
LINE (pa2(0, 0), pa2(0, 1))-(pa(0, 0), pa(0, 1)), 0
LINE (pa(0, 0), pa(0, 1))-(p(0, 0), p(0, 1)), 14
pa2(0, 0) = pa(0, 0)
pa2(0, 1) = pa(0, 1)
pa(0, 0) = p(0, 0)
pa(0, 1) = p(0, 1)
p(0, 0) = p(0, 0) + g(0, 0)
p(0, 1) = p(0, 1) + g(0, 1)
g(0, 0) = (g(0, 0) + RND * 2 - 1) MOD 10
IF p(0, 0) < 8 OR p(0, 0) > 632 THEN g(0, 0) = -g(0, 0)
g(0, 1) = (g(0, 1) + RND * 2 - 1) MOD 10
IF p(0, 1) < 8 OR p(0, 1) > 472 THEN g(0, 1) = -g(0, 1)
FOR a = 1 TO anzbee
LINE (pa2(a, 0), pa2(a, 1))-(pa(a, 0), pa(a, 1)), 0
LINE (pa(a, 0), pa(a, 1))-(p(a, 0), p(a, 1)), 12
pa2(a, 0) = pa(a, 0)
pa2(a, 1) = pa(a, 1)
pa(a, 0) = p(a, 0)
pa(a, 1) = p(a, 1)
p(a, 0) = p(a, 0) + g(a, 0)
p(a, 1) = p(a, 1) + g(a, 1)
g(a, 0) = (g(a, 0) + ((p(0, 0) - p(a, 0)) \ 100)) MOD 10
g(a, 1) = (g(a, 1) + ((p(0, 1) - p(a, 1)) \ 100)) MOD 10
NEXT
LOOP WHILE INKEY$ = ""
SYSTEM

new topic     » goto parent     » topic index » view message » categorize

11. Re: A Little QBasic help

Chris,

I don't have your Euphoria code.  But I have a lead on your two problems.=


1.  The if thing.  I suspect it tells you that true/false conditions have=

to be an atom, or something like that.  Check your atoms to see they are
actually atoms.  Use 'atom' instead of "atom".  Without seeing the code,
I'm not sure, as this has always been an allusive error with me.  You cou=
ld
also send us the ex.err file.

2.  Euphoria does have routines to draw lines.  Check the end of Section
2.12 in LIBRARY.doc.

Hope this helps.

--Alan
 =

new topic     » goto parent     » topic index » view message » categorize

12. Re: A Little QBasic help

Chris,
I tried to create an Euphoria version of your program. Here it is. It
is not perfect, but you can improve it. Since many calculations were
done with both the first and the second atoms of the pair, I used a
single line to do them. The program could be further optimized, but the
line drawing command already takes about 70% of the total running time
(at least in my computer), so it would not be much faster.

-- begin code --
--DEFINT A-Z
--RANDOMIZE TIMER
include graphics.e

--CONST anzbee = 100
constant anzbee=100

--DIM g(anzbee, 1), p(anzbee, 1), pa(anzbee, 1), pa2(anzbee, 1)
sequence g,p,pa,pa2

g=repeat({0,0},anzbee+1)
p=repeat({0,0},anzbee+1)
pa=repeat({0,0},anzbee+1)
pa2=repeat({0,0},anzbee+1)

--FOR a = 0 TO anzbee
for a=1 to anzbee+1 do

    --g(a, 0) = INT(RND * 7 - 3)
    --g(a, 1) = INT(RND * 7 - 3)
    g[a]=rand({7,7})-4

    --p(a, 0) = INT(RND * 640)
    --p(a, 1) = INT(RND * 480)
    p[a]=rand({640,480})-1

    --pa(a, 0) = INT(RND * 640)
    --pa(a, 1) = INT(RND * 480)
    pa[a]=rand({640,480})-1

--NEXT
end for

--SCREEN 12
if graphics_mode(18) then
    abort(1)
end if


--DO
while get_key()=-1 do

    --LINE (pa2(0, 0), pa2(0, 1))-(pa(0, 0), pa(0, 1)), 0
    draw_line(0,{pa2[1],pa[1]})

    --LINE (pa(0, 0), pa(0, 1))-(p(0, 0), p(0, 1)), 14
    draw_line(14,{pa[1],p[1]})

    --pa2(0, 0) = pa(0, 0)
    --pa2(0, 1) = pa(0, 1)
    pa2[1]=pa[1]

    --pa(0, 0) = p(0, 0)
    --pa(0, 1) = p(0, 1)
    pa[1]=p[1]

    --p(0, 0) = p(0, 0) + g(0, 0)
    --p(0, 1) = p(0, 1) + g(0, 1)
    p[1]=p[1]+g[1]

    --g(0, 0) = (g(0, 0) + RND * 2 - 1) MOD 10
    --g(0, 1) = (g(0, 1) + RND * 2 - 1) MOD 10
    g[1]=remainder(g[1]+(rand({1000,1000})/500)-1,10)
    -- This line uses fractional randomic numbers. A line like the following
one, that
    -- uses integers, could also be used. I did not see any difference in the
animation
    -- when I tried it.
    -- g[1]=remainder(g[1]+rand(3)-2,10)


    --IF p(0, 0) < 8 OR p(0, 0) > 632 THEN g(0, 0) = -g(0, 0)
    if p[1][1]<8 or p[1][1]>632 then g[1][1]=-g[1][1] end if

    --IF p(0, 1) < 8 OR p(0, 1) > 472 THEN g(0, 1) = -g(0, 1)
    if p[1][2]<8 or p[1][2]>472 then g[1][2]=-g[1][2] end if

    --FOR a = 1 TO anzbee
    for a=2 to anzbee+1 do

        --LINE (pa2(a, 0), pa2(a, 1))-(pa(a, 0), pa(a, 1)), 0
        draw_line(0,{pa2[a],pa[a]})

        --LINE (pa(a, 0), pa(a, 1))-(p(a, 0), p(a, 1)), 12
        draw_line(12,{pa[a],p[a]})

        --pa2(a, 0) = pa(a, 0)
        --pa2(a, 1) = pa(a, 1)
        pa2[a]=pa[a]

        --pa(a, 0) = p(a, 0)
        --pa(a, 1) = p(a, 1)
        pa[a]=p[a]

        --p(a, 0) = p(a, 0) + g(a, 0)
        --p(a, 1) = p(a, 1) + g(a, 1)
        p[a]=p[a]+g[a]

        --g(a, 0) = (g(a, 0) + ((p(0, 0) - p(a, 0)) \ 100)) MOD 10
        --g(a, 1) = (g(a, 1) + ((p(0, 1) - p(a, 1)) \ 100)) MOD 10
        g[a] = remainder((g[a]+((p[1]-p[a])/100)),10)

    --NEXT
    end for



--LOOP WHILE INKEY$ = ""
end while

--SYSTEM
if graphics_mode(-1) then
    abort(1)
end if

-- end code --

Regards,
Davi T. Figueiredo
davitf at usa.net


____________________________________________________________________
Get free e-mail and a permanent address at http://www.amexmail.com/?A=1

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu