1. Gradient Background??

I'm having a hard time creating a gradient background. I want it to fill in
the background from black at top to a dark blue at the bottom. I keep
getting a "Trying to redefine intY" error. Here's the code I'm using.

procedure gradientbg()
    atom intY
    sequence gradcolor
    for intY = 1 to 480 by 1
    gradcolor = {0, 0, floor(intY / 480) * 255}
    draw_line(gradcolor, {{1, intY},{640, intY}})
    next
    end for
End Procedure

Any ideas why this is happening?

Draw line repeated 480 times seems a little inefficient. Any ideas on a
better way of doing this?

Thanks,
Brian

new topic     » topic index » view message » categorize

2. Re: Gradient Background??

Hi Brian,

>>Any ideas why this is happening?

  remove:
    atom IntY
  from the program.  Loop vars dont have to be declared.

>>Draw line repeated 480 times seems a little inefficient. Any ideas on a
better way of doing this?

  yes, move to Window platform, then you can draw a bitmap and display that
  as the background.


good luck with it.

--Al

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

3. Re: Gradient Background??

On Sun, 10 Dec 2000 12:51:55 -0500, Brian <impee3 at EXCITE.COM> wrote:

>I'm having a hard time creating a gradient background. I want it to fill in
>the background from black at top to a dark blue at the bottom. I keep
>getting a "Trying to redefine intY" error. Here's the code I'm using.
>
>procedure gradientbg()
>    atom intY
>    sequence gradcolor
>    for intY = 1 to 480 by 1
>    gradcolor = {0, 0, floor(intY / 480) * 255}
>    draw_line(gradcolor, {{1, intY},{640, intY}})
>    next
>    end for
>End Procedure
>
>Any ideas why this is happening?


Brian:

   You have 2 varibles in the procedure:

   1. atom intY

   2. The for loop is creating it's own variable intY

   In other words the variable you use in the for loop
   is automatically declared.

   Comment out the atom intY.


   Bernie

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

4. Re: Gradient Background??

Brian wrote:

> "Trying to redefine intY"

Loop variables are *automatically* declared. Remove the statement:

>     atom intY

> Draw line repeated 480 times seems
> a little inefficient. Any ideas on a
> better way of doing this?

Make the lines thicker. In Win32Lib, use setPenWidth. In DOS32, use poly()
to draw a filled rectangle.

-- David Cuny

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

5. Re: Gradient Background??

On Sun, 10 Dec 2000 12:51:55 -0500, Brian wrote:

>I'm having a hard time creating a gradient background. I want it to fill in
>the background from black at top to a dark blue at the bottom. I keep
>getting a "Trying to redefine intY" error. Here's the code I'm using.
>
>procedure gradientbg()
>    atom intY
>    sequence gradcolor
>    for intY = 1 to 480 by 1
>    gradcolor = {0, 0, floor(intY / 480) * 255}
>    draw_line(gradcolor, {{1, intY},{640, intY}})
>    next
>    end for
>End Procedure
>
>Any ideas why this is happening?
>
>Draw line repeated 480 times seems a little inefficient. Any ideas on a
>better way of doing this?

I'm hoping that you are not actually running the above code.

  - As David mentioned, you don't need to declare loop variables
  - you don't need to specify "by 1" in your loop, that is the default
  - you are missing a "do" in your "for"
  - there is no "next" in Euphoria
  - in DOS, you have to work with the DOS palette to set your colors

Here is a working demo:
------------------------
include graphics.e
include get.e

-- set graphics mode (missing error message)
if graphics_mode( 257 ) then
  abort(1)
end if

procedure gradientbg()
  sequence gradcolor

  for i = 0 to 63 do
    -- use palette range 192 (black) to 255 (blue)
    gradcolor = palette( i+192, {0, 0, i} )
    for j = 1 to 8 do
      draw_line( i+192, {{0, i*8+j},{639, i*8+j}})
    end for
  end for
end procedure

gradientbg()
-- wait for user to end program, look at pretty gradient
if wait_key() then
  abort(0)
end if

-- restore graphics mode (missing error message)
if graphics_mode(-1) then
  abort(1)
end if

-- good luck,
--  Brian

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

6. Re: Gradient Background??

Oops, my gradientbg() was a bit of an overkill since it draws lines that
are off of the screen.  You really only need to use 60 palette indexes for
this (not 64).  So using this procedure will do the same thing (only
slightly faster):

procedure gradientbg()
  sequence gradcolor

  for i = 0 to 59 do
    -- use palette range 196 (black) to 255 (blue)
    gradcolor = palette( i+196, {0, 0, i} )
    for j = 1 to 8 do
      draw_line( i+196, {{0, i*8+j},{639, i*8+j}})
    end for
  end for
end procedure

-- Brian

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

7. Re: Gradient Background??

Thanks alot everyone! Brian Broker's gradient worked great. I'm new to
Euphoria and still trying to figure out what works and what doesn't.
Sometimes it's easier to write it in VB or C first, then translate it.
That's why that snippet of code looked like it did.

Thanks again,
Brian

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

8. Re: Gradient Background??

--  gradient.ex
--  jbabor at paradise.net.nz
--  00-12-11

include image.e             -- get_al_palette(), includes graphics.e
include get.e               -- wait_key()

sequence pal
integer i, y, y1

if graphics_mode(257) then
    puts(1, "Error: couldn't set the required graphics mode!\n")
    abort(1)
end if

pal = get_all_palette()     -- get default palette
i = 4                       -- very dark blue, almost black
for c = 196 to 255 do       -- set last 60 colors to shades of blue
    pal[c] = {0,0,i}
    i += 1
end for
all_palette(pal)            -- reset colors using modified palette

y = 0
for c = 196 to 255 do
    y1 = y + 7
    polygon(c, 1, {{0, y}, {639, y}, {639, y1}, {0, y1}})
    y += 8
end for

i = wait_key()
i = graphics_mode(-1)

----- Original Message -----
From: "Brian" <impee3 at EXCITE.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Monday, December 11, 2000 6:51 AM
Subject: Gradient Background??


> I'm having a hard time creating a gradient background. I want it to
fill in
> the background from black at top to a dark blue at the bottom. I
keep
> getting a "Trying to redefine intY" error. Here's the code I'm
using.
>
> procedure gradientbg()
>     atom intY
>     sequence gradcolor
>     for intY = 1 to 480 by 1
>     gradcolor = {0, 0, floor(intY / 480) * 255}
>     draw_line(gradcolor, {{1, intY},{640, intY}})
>     next
>     end for
> End Procedure
>
> Any ideas why this is happening?
>
> Draw line repeated 480 times seems a little inefficient. Any ideas
on a
> better way of doing this?
>
> Thanks,
> Brian
>

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

9. Re: Gradient Background??

Sorry, I made a mistake in my previous post. The last polygon is drawn
in incorrect color. The line

    for c = 196 to 255 do       -- set last 60 colors to shades of
blue

should read

    for c = 197 to 256 do       -- set last 60 colors to shades of
blue

because, regrettably, Euphoria sequence indexing is '1' based, just to
be different from the rest of the world, which is, of course, zero
('0') based.

jiri


----- Original Message -----
From: "jiri babor" <jbabor at PARADISE.NET.NZ>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Monday, December 11, 2000 10:50 AM
Subject: Re: Gradient Background??


> --  gradient.ex
> --  jbabor at paradise.net.nz
> --  00-12-11
>
> include image.e             -- get_al_palette(), includes graphics.e
> include get.e               -- wait_key()
>
> sequence pal
> integer i, y, y1
>
> if graphics_mode(257) then
>     puts(1, "Error: couldn't set the required graphics mode!\n")
>     abort(1)
> end if
>
> pal = get_all_palette()     -- get default palette
> i = 4                       -- very dark blue, almost black
> for c = 196 to 255 do       -- set last 60 colors to shades of blue
>     pal[c] = {0,0,i}
>     i += 1
> end for
> all_palette(pal)            -- reset colors using modified palette
>
> y = 0
> for c = 196 to 255 do
>     y1 = y + 7
>     polygon(c, 1, {{0, y}, {639, y}, {639, y1}, {0, y1}})
>     y += 8
> end for
>
> i = wait_key()
> i = graphics_mode(-1)
>
> ----- Original Message -----
> From: "Brian" <impee3 at EXCITE.COM>
> To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
> Sent: Monday, December 11, 2000 6:51 AM
> Subject: Gradient Background??
>
>
> > I'm having a hard time creating a gradient background. I want it
to
> fill in
> > the background from black at top to a dark blue at the bottom. I
> keep
> > getting a "Trying to redefine intY" error. Here's the code I'm
> using.
> >
> > procedure gradientbg()
> >     atom intY
> >     sequence gradcolor
> >     for intY = 1 to 480 by 1
> >     gradcolor = {0, 0, floor(intY / 480) * 255}
> >     draw_line(gradcolor, {{1, intY},{640, intY}})
> >     next
> >     end for
> > End Procedure
> >
> > Any ideas why this is happening?
> >
> > Draw line repeated 480 times seems a little inefficient. Any ideas
> on a
> > better way of doing this?
> >
> > Thanks,
> > Brian
> >
>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu