1. Converting qbasic to Euphoria?
- Posted by Ed Davis <ed_davis2 at yahoo.com> Jul 28, 2004
- 627 views
Can the following qbasic code be easily converted to Euphoria? Note that I am not looking for an exact translation. My goal is to be able to use Euphoria to graph some simple algebraic equations. Using DOS (as opposed to Linux or Windows) is ok too. Thanks for any help! DIM a, b, c, x AS DOUBLE SCREEN (12) WINDOW (-8, 6)-(8, -6) LINE (-8, 0)-(8, 0) 'X axis LINE (0, 6)-(0, -6) 'Y axis FOR x = -8 TO 8 STEP .025 a = x ^ 2 b = SIN(x) c = COS(x) PSET (x, a) PSET (x, b) PSET (x, c) NEXT x
2. Re: Converting qbasic to Euphoria?
- Posted by Tommy Carlier <tommy.carlier at pandora.be> Jul 28, 2004
- 637 views
Ed Davis wrote: > DIM a, b, c, x AS DOUBLE > SCREEN (12) > WINDOW (-8, 6)-(8, -6) > LINE (-8, 0)-(8, 0) 'X axis > LINE (0, 6)-(0, -6) 'Y axis > FOR x = -8 TO 8 STEP .025 > a = x ^ 2 > b = SIN(x) > c = COS(x) > PSET (x, a) > PSET (x, b) > PSET (x, c) > NEXT x The (untested) code below should create a (maximized) window and draw the 3 graphs in different colors: - bright white background - black X and Y axis - red x ^ 2 - blue sin(x) - green cos(x)
include win32lib.ew constant win = create(Window, "Graph", 0, 0, 0, 300, 200, 0) procedure winPaint(integer self, integer event, sequence params) sequence rect atom a, b, c, delta_x, delta_y, mult_x, mult_y integer width, height -- get the size of the drawing canvas: rect = getClientRect(self) width = rect[3] height = rect[4] -- translate WINDOW (-8, 6) - (8, -6): delta_x = 8 delta_y = 6 mult_x = width / 16 -- -8 .. 8 = 0 .. 16 mult_y = height / -12 -- 6 .. -6 = 12 .. 0 -- clearing the window setPenColor(self, BrightWhite) drawRectangle(self, w32True, 0, 0, width, height) setPenColor(self, Black) -- drawing the X and Y axis drawLine(self, 0, floor(height/2), width, floor(height/2)) drawLine(self, floor(width/2), 0, floor(width/2), height) for x = -8 to 8 by 0.025 do a = x * x b = sin(x) c = cos(x) setPixel(self, floor((x + delta_x) * mult_x), floor((a + delta_y) * mult_y), BrightRed) setPixel(self, floor((x + delta_x) * mult_x), floor((b + delta_y) * mult_y), BrightBlue) setPixel(self, floor((x + delta_x) * mult_x), floor((c + delta_y) * mult_y), BrightGreen) end for end procedure setHandler(win, w32HPaint, routine_id("winPaint")) WinMain(win, Maximized)
-- tommy online: http://users.pandora.be/tommycarlier Euphoria Message Board: http://uboard.proboards32.com
3. Re: Converting qbasic to Euphoria?
- Posted by Matt Lewis <matthewwalkerlewis at yahoo.com> Jul 28, 2004
- 619 views
Ed Davis wrote: > > Can the following qbasic code be easily converted to Euphoria? > Note that I am not looking for an exact translation. My goal is > to be able to use Euphoria to graph some simple algebraic > equations. Using DOS (as opposed to Linux or Windows) is ok too. > > Thanks for any help! > > DIM a, b, c, x AS DOUBLE > SCREEN (12) > WINDOW (-8, 6)-(8, -6) > LINE (-8, 0)-(8, 0) 'X axis > LINE (0, 6)-(0, -6) 'Y axis > FOR x = -8 TO 8 STEP .025 > a = x ^ 2 > b = SIN(x) > c = COS(x) > PSET (x, a) > PSET (x, b) > PSET (x, c) > NEXT x You could do this fairly easily using matheval. You'll need to update the grapheval.e file: The line towards the top (add CONSTANT, VAR):
integer INVALID, DATA, GRAPH, CGRAPH, RANGE, CONSTANT, VAR
And graph_init() should look like:
procedure graph_init() INVALID = resolve_math_ref( "INVALID" ) DATA = resolve_math_ref( "DATA" ) CONSTANT = resolve_math_ref( "CONSTANT" ) VAR = resolve_math_ref( "VAR") GRAPH = reg_math_func( "GRAPH", routine_id("Graph") ) CGRAPH = reg_math_func( "CGRAPH", routine_id("CGraph") ) RANGE = reg_math_func( "RANGE", routine_id("Range") ) end procedure
Then try the following (uses Win32Lib):
without warning include win32lib.ew include matheval.e include grapheval.e constant win = create( Window, "Graph", 0, Default, Default, 500, 420, 0 ) sequence graph, func, colors integer GRAPH procedure win_paint( integer self, atom event, sequence params ) setPenColor( win, BrightWhite ) drawPolygon( win, 1, { 10, 10, 490, 10, 490, 390, 10, 390 } ) for i = 1 to 3 do drawLines( win, colors[i] & graph[i] ) end for setPenColor( win, Black ) drawPolygon( win, 0, { 10, 10, 490, 10, 490, 390, 10, 390 } ) drawLine( win, 250, 10, 250, 390) drawLine( win, 10, 200, 490, 200) end procedure setHandler( win, w32HPaint, routine_id("win_paint")) procedure setup() sequence g matheval_init() GRAPH = resolve_math_ref( "GRAPH" ) func = { Parse( "x^2" ), Parse( "sin(x)" ), Parse( "cos(x)" ) } colors = {Blue, Green, Red} graph = repeat( 0, 3 ) SetScreen( {480, 380}) SetOrigin({10,10}) for i = 1 to 3 do g = Evaluate({ GRAPH, { func[i], "X"}, {-8, 8, 0.1, -6, 6} }) g = floor(g[2]) g[2] = g[1] & g[2] graph[i] = g[2..length(g)] end for end procedure setup() WinMain( win, Normal )
Matt Lewis
4. Re: Converting qbasic to Euphoria?
- Posted by "Igor Kachan" <kinz at peterlink.ru> Jul 28, 2004
- 618 views
Hi Ed, ---------- > From: Ed Davis <guest at RapidEuphoria.com> > To: EUforum at topica.com > Subject: Converting qbasic to Euphoria? > Sent: 28 jul 2004 y. 22:22 > > > Can the following qbasic code be easily > converted to Euphoria? > Note that I am not looking for an exact > translation. My goal is to be able to > use Euphoria to graph some simple algebraic > equations. > Using DOS (as opposed to Linux or Windows) > is ok too. > > Thanks for any help! > > DIM a, b, c, x AS DOUBLE > SCREEN (12) > WINDOW (-8, 6)-(8, -6) > LINE (-8, 0)-(8, 0) 'X axis > LINE (0, 6)-(0, -6) 'Y axis > FOR x = -8 TO 8 STEP .025 > a = x ^ 2 > b = SIN(x) > c = COS(x) > PSET (x, a) > PSET (x, b) > PSET (x, c) > NEXT x Try please this DOS32 program, works for me.
include graphics.e atom a, b, c if graphics_mode(18) then end if -- > WINDOW (-8, 6)-(8, -6) -- there is no -- WINDOW in the standard EU, but -- there is one lib in The Archive with -- that WINDOW feature. -- So, I just mapped your task into 640x480 screen draw_line(5,{{0,239},{639,239}}) -- X axis draw_line(5,{{319,0},{319,479}}) -- Y axis for x = -8 to 8 by .025 do a = power(x, 2) b = sin(x) c = cos(x) pixel(11,{x * 80 + 319, a * 80 + 239}) pixel(12,{x * 80 + 319, b * 80 + 239}) pixel(14,{x * 80 + 319, c * 80 + 239}) end for
Regards, Igor Kachan kinz at peterlink.ru