Re: Converting qbasic to Euphoria?

new topic     » goto parent     » topic index » view thread      » older message » newer message

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu