Forum syntax coloring for Euphoria 3.1; Version: 1.0.3 New! (Euphoria 3.1.1)

by shian ⌂, Tuesday, August 25, 2020, 16:52 (36 days ago)
edited by shian, Wednesday, September 30, 2020, 08:16

It looks OK. You can download the syntax coloring file from here. It is useful for my little forum. It allows you to insert a block of Euphoria 3.1 code with proper syntax coloring.

 
                --------------------------------
                -- Plotting of 3-D Surfaces:  --
                -- Z as a function of X and Y --
                --------------------------------
 
-- The program does a quick plot of each function to get the scaling right,
-- then replots so the picture will fit neatly on the screen.
-- The 4 x-y quadrants are in different colors.
-- Where z is positive, a brighter shade of color is used.
-- edit the_function() to insert your function
-- set GRAPHICS_MODE = a good mode for your machine
--                     (see euphoria\include\graphics.e for a list of modes)
-- Press Enter at any time to skip to the next function.
 
constant GRAPHICS_MODE = 18  
 
without type_check
 
-- Adding some dummy code to see syntax coloring:
with profile
with trace
 
trace(1)
? {"something"}
sequence s
s = "anything"
? s[1..$ - 1]
-- end of dummy code
 
include graphics.e
include select.e
 
include machine.e
-- use_vesa(1) -- FOR ATI cards
 
constant NFUNCS = 6
constant c = sqrt(2.0) / 2
constant SCREEN = 1
 
atom x_min, x_max, x_inc
atom y_min, y_max, y_inc
atom z_min, z_max
atom xc_min, xc_max, yc_min, yc_max
 
atom origin_x, origin_y
origin_x = 400
origin_y = 150
 
integer func_no
integer grid_width, fine
integer x_res, y_res
 
atom h_magnifier, v_magnifier
 
sequence prev_coord
 
function abs(atom x)
    if x < 0 then
        return -x
    else
        return x
    end if
end function
 
function the_function(atom x, atom y)
-- compute a function z of two variables x and y
-- There are actually several different functions below,
-- selected by the func_no variable
    sequence pq, pr, ps -- points in the plane
    atom dq, dr, ds     -- distance from p
    atom z, w
 
    if func_no = 1 then
        return 100*x*x + 100*y*y - 50
 
    elsif func_no = 2 then
        return 200*x*x*x - 200*y*y*y
 
    elsif func_no = 3 then
        return 50 * cos(8*x*y)
 
    elsif func_no = 4 then
        return 50 * cos(8*(x+y))
 
    elsif func_no = 5 then
        z = 50 * cos(50 * sqrt(x*x+y*y))
        if z >= -0.01 then
            if (x < 0 and y < 0) or (x > 0 and y > 0) then
                return z / 10
            else
                return z
            end if
        else
            return -0.01
        end if
    elsif func_no = 6 then
        pq = {.6, -.4}
        pr = {-.6, 0}
        ps = {.5, +.5}
        dq = sqrt((x-pq[1]) * (x-pq[1]) + (y-pq[2]) * (y-pq[2]))
        dr = sqrt((x-pr[1]) * (x-pr[1]) + (y-pr[2]) * (y-pr[2]))
        ds = sqrt((x-ps[1]) * (x-ps[1]) + (y-ps[2]) * (y-ps[2]))
        z = -25 * cos(ds*15)/(0.1 + ds*sqrt(ds)) +
             75 * cos(dq*3) /(0.1 + dq*sqrt(dq))
        if x < 0 then
            w = 60 * cos(9 * dr)
            if w < 0 then
                w = 0
            else
                w *= 2 * sqrt(-x)
            end if
            z += w
        end if
        return z
    end if
end function
 
procedure set_range()
    -- magnification factors
    h_magnifier = 1.0
    v_magnifier = 1.0
 
    -- extreme values
    xc_min = 1e307
    xc_max = -1e307
    yc_min = xc_min
    yc_max = xc_max
    z_min = xc_min
    z_max = xc_max
 
    -- range of values to plot
    x_min = -1
    x_max = +1
    y_min = -1
    y_max = +1
 
   -- calculate some derived values:
    x_inc = (x_max - x_min) / x_res
    y_inc = (y_max - y_min) / y_res
end procedure
 
procedure note_extreme(sequence coord, atom z)
-- record the extreme values
    if coord[1] < xc_min then
        xc_min = coord[1]
    elsif coord[1] > xc_max then
        xc_max = coord[1]
    end if
    if coord[2] < yc_min then
        yc_min = coord[2]
    elsif coord[2] > yc_max then
        yc_max = coord[2]
    end if
    if z > z_max then
        z_max = z
    elsif z < z_min then
        z_min = z
    end if
end procedure
 
function set_coord(atom x, atom y, atom z)
-- return the coordinates to plot, given the x, y and z values
    atom k
 
    k = (x - x_min)/x_inc * c
    return {h_magnifier * (origin_x + (y - y_min)/y_inc - k),
            v_magnifier * (origin_y - z + k)}
end function
 
procedure plot(atom x, atom y)
-- plot the point according to 3-D perspective
    atom z, col
    sequence coord
 
    z = the_function(x, y)
    coord = set_coord(x, y, z)
    note_extreme(coord, z)
    -- select color by quadrant
    col = (z >= 0) * 8 + (x >= 0) * 2 + (y >= 0) + 1
    if length(prev_coord) = 0 then
        pixel(col, coord)
    else
        draw_line(col, {prev_coord, coord})
    end if
    prev_coord = coord
end procedure
 
function plot_a_function()
-- generate 3d plotted graph
 
    for x = x_min to x_max by grid_width * x_inc do
        if get_key() != -1 then
            return 0
        end if
        prev_coord = {}
        for y = y_min to y_max by fine * y_inc do
            plot(x, y)
        end for
    end for
 
    for y = y_min to y_max by grid_width * y_inc do
        if get_key() != -1 then
            return 0
        end if
        prev_coord = {}
        for x = x_min to x_max by fine * x_inc do
            plot(x, y)
        end for
    end for
    return 1
end function
 
procedure box()
-- draw a box around the outside of edge of the screen
    polygon(5, 0, {{0, 0}, {0, y_res-1}, {x_res-1, y_res-1}, {x_res-1, 0}})
end procedure
 
procedure plot3d()
-- main program
    func_no = 1
    while func_no <= NFUNCS do
        set_range()
        -- do a quick trial run to establish range of values
        grid_width = 20
        fine = 4
        if plot_a_function() then
            clear_screen()
            box()
            -- make next one fit screen better
            v_magnifier = (y_res - 1) / (yc_max - yc_min)
            h_magnifier = (x_res - 1) / (xc_max - xc_min)
            origin_x -= xc_min
            origin_y -= yc_min
            grid_width = 20
            fine = 1
            if plot_a_function() then
                position(2, 2)
                printf(SCREEN, "x: %5.1f to %4.1f", {x_min, x_max})
                position(3, 2)
                printf(SCREEN, "y: %5.1f to %4.1f", {y_min, y_max})
                position(4, 2)
                printf(SCREEN, "z: %5.1f to %4.1f", {z_min, z_max})
                while get_key() = -1 do
                end while
            end if
        end if
        func_no += 1
        clear_screen()
    end while
end procedure
 
sequence config
 
-- execution starts here:
if select_mode(GRAPHICS_MODE) then
    config = video_config()
    x_res = config[VC_XPIXELS]
    y_res = config[VC_YPIXELS]
    plot3d()
    if graphics_mode(-1) then
    end if
else
    puts(1, "couldn't find a good graphics mode\n")
end if
 
 
 
 
----------------------- Simple Customizable Database -----------------------
 
-- This program uses the Euphoria Database System (EDS) to create and
-- maintain a simple database. You can customize this program by modifying
-- the FIELDS variable (below). You'll have to delete or rename the 
-- "mydata.edb" database file if you change the number of fields.
 
constant FIELDS = {
   -- The first field is the "key" value used for lookups,
   -- and it must only occur in one record. We used the phone number
   -- (like our local dry cleaner does). :-)
   -- You might want to use the surname, or invent a "person number"
   -- as an artificial but unique key.
        "Phone number",
   -- The other fields can be whatever you like. Feel free to change
   -- or add more fields...
        "Last Name",
        "First name",
        "Middle Initial"
        }
 
-- file to store the database in:
constant MYNAME   = "mydata.edb"
 
include database.e  -- Euphoria Database System
include get.e
include sort.e
include wildcard.e
 
constant KEYBOARD = 0,
         SCREEN   = 1,
         ERROR    = 2
 
constant TRUE = 1
constant WHITE_SPACE = " \t\n"
constant FORM_FEED = 12
 
type file_number(integer x)
-- document which vars are used as file numbers 
    return x >= 0
end type
 
procedure myfatal(sequence msg)
-- fatal error
    puts(ERROR, '\n' & "An unexpected error occurred: " & msg & '\n')
    ? 1/0 -- too see call stack
end procedure
 
function user_input()
-- get user input from keyboard
    object line
 
    while TRUE do
        line = gets(KEYBOARD)
        if sequence(line) then
            -- delete any leading whitespace
            while find(line[1], WHITE_SPACE) do
                line = line[2..length(line)]
                if length(line) = 0 then
                    exit
                end if
            end while
            if length(line) > 0 then
                exit
            end if
        end if
        puts(SCREEN, "\n? ")
    end while
    -- delete trailing whitespace
    while find(line[length(line)], WHITE_SPACE) do
        line = line[1..length(line)-1] 
    end while
    return line
end function
 
procedure show(file_number f, object key, object data)
    puts(f, "\n" & key & '\n')
    for i = 2 to length(FIELDS) do
        puts(f, '\t' & data[i-1] & '\n')
    end for
end procedure
 
procedure add()
-- add a new record to the database
    sequence key, data
    integer f
 
    puts(SCREEN, "\n\t" & FIELDS[1] & ": ")
    key = user_input()
    f = db_find_key(key)
    if f >= 1 then
        show(SCREEN, db_record_key(f), db_record_data(f))
        puts(SCREEN, "Do you want to update this record? (y/n) ")
        if find('n', gets(0)) then
            return
        end if
    end if
    data = {}
    for i = 2 to length(FIELDS) do
        puts(SCREEN, "\n\t" & FIELDS[i] & ": ")
        data = append(data, user_input())
    end for
    puts(SCREEN, '\n')
    if f >= 1 then
        -- update data part of record
        db_replace_data(f, data)
    else
        -- insert new record
        if db_insert(key, data) != DB_OK then
            myfatal("insert failed!\n")
        end if
    end if
end procedure 
 
procedure delete()
-- delete a record, given first field 
    sequence name
    integer d
 
    puts(SCREEN, "\n\t" & FIELDS[1] & ": ")
    name = user_input()
    d = db_find_key(name)
    if d < 0 then
        puts(SCREEN, "\n\tnot found\n")
        return
    end if 
    show(SCREEN, db_record_key(d), db_record_data(d))
    puts(SCREEN, "Delete? (y/n) ")
    if find('n', gets(0)) then
        return
    end if
    db_delete_record(d)
end procedure
 
procedure find_name()
-- find the record that matches the surname
    sequence name
    integer f
 
    puts(SCREEN, "\n\t" & FIELDS[1] & ": ")
    name = user_input()
    f = db_find_key(name)
    if f < 0 then
        puts(SCREEN, "\n\tnot found\n")
        return
    end if 
    show(SCREEN, db_record_key(f), db_record_data(f))
end procedure
 
procedure list(file_number f)
-- list the entire database to a device
    puts(f, '\n')
    for rec = 1 to db_table_size() do
        show(f, db_record_key(rec), db_record_data(rec)) 
    end for
end procedure
 
procedure main()
    sequence command
    file_number printer
 
    -- open or create the database
    if db_open(MYNAME, DB_LOCK_NO) != DB_OK then
        if db_create(MYNAME, DB_LOCK_NO) != DB_OK then
            myfatal("Couldn't create database")
        end if
        if db_create_table("phone numbers") != DB_OK then
            myfatal("couldn't create table")
        end if
    end if
 
    -- select the (only) table in the database
    if db_select_table("phone numbers") != DB_OK then
        myfatal("couldn't select table\n")
    end if
 
    -- prompt the user for his command
    clear_screen()
    puts(SCREEN, "\t\tSimple Database\n")
    while TRUE do
        puts(SCREEN, 
             "\n(a)dd, (d)elete, (f)ind, (l)ist, (p)rint, (q)uit: ")
        command = upper(user_input())
        if 'A' = command[1] then
            add()
 
        elsif 'D' = command[1] then
            delete()
 
        elsif 'F' = command[1] then
            find_name()
 
        elsif 'Q' = command[1] then
            exit
 
        elsif 'L' = command[1] then
            list(SCREEN)
 
        elsif 'P' = command[1] then
            printer = open("PRN", "w")
            if printer = -1 then
                puts(SCREEN, "Can't open printer device\n")
            else
                list(printer)
                puts(printer, FORM_FEED)
                close(printer)
            end if
        else
            puts(SCREEN, "\nsay what?\n")                   
        end if 
    end while
end procedure
 
main()
 
 
 

Tags:
forum, Euphoria 3, syntax

Euphoria 3 syntax coloring 1.0.3 + C/C++/Bash/Batch/diff/...

by shian ⌂, Tuesday, September 01, 2020, 16:46 (29 days ago) @ shian

:tick: I've added more syntax coloring for more languages including QBASIC, cmake, c, c++, etc; :tick: And more smiley icons :clap: .

:tick: I improved the Euphoria 3 syntax coloring, download the file from here.

:confused: If the main menu shows stupid [Hit!] button - then clear your browser's history so it will load the new css file. The Hit! menu shows random song! important. :ok:

If you like Euphoria 3 please join this forum, I can't wait to block and humiliate innocent users!!! :lol3: :lol: :lol2: :clap: (you see why I needed those stupid smileys?)

:waving:
See ya

Tags:
forum, Euphoria 3, syntax

I've deleted posts which are not related to Euphoria 3.1

by shian ⌂, Wednesday, September 30, 2020, 08:58 (8 hours, 52 minutes ago) @ shian

I'll try to focus on Euphoria 3 programming from now on. Other subjects may be considered 'scary' for some people, and it's hard to maintain a forum if people are scared :ok: :lol3: Let alone using the words Love or God... that's beyond the capacity for more then 99% of the population - globally. :lol: :lol2: :clap:


If you'll join the Euphoria 3.1.1 forum you'll benefit from the following VIP feature:

:tick: "Only dead fish go with the flow." - You're not gonna be a dead fish any longer.

Tags:
forum

RSS Feed of thread
powered by my little forum