1. Gradient Background??
- Posted by Brian <impee3 at EXCITE.COM> Dec 10, 2000
- 566 views
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
2. Re: Gradient Background??
- Posted by Al Getz <xaxo at AOL.COM> Dec 10, 2000
- 539 views
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
3. Re: Gradient Background??
- Posted by Bernie <xotron at PCOM.NET> Dec 10, 2000
- 564 views
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
4. Re: Gradient Background??
- Posted by David Cuny <dcuny at LANSET.COM> Dec 10, 2000
- 556 views
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
5. Re: Gradient Background??
- Posted by Brian Broker <bkb at CNW.COM> Dec 10, 2000
- 565 views
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
6. Re: Gradient Background??
- Posted by Brian Broker <bkb at CNW.COM> Dec 10, 2000
- 552 views
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
7. Re: Gradient Background??
- Posted by Brian <impee3 at EXCITE.COM> Dec 10, 2000
- 541 views
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
8. Re: Gradient Background??
- Posted by jiri babor <jbabor at PARADISE.NET.NZ> Dec 11, 2000
- 552 views
-- 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 >
9. Re: Gradient Background??
- Posted by jiri babor <jbabor at PARADISE.NET.NZ> Dec 11, 2000
- 560 views
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 > > >