Genie applications: an example of calculating logarithms
Introduction
This example demonstrates the simplest interactive applications for calculating logarithms:
Where:
- — the base of the logarithm
- — the logarithm argument
- — the value of the logarithm.
In other words, the following condition is satisfied:
The reactive interface
Consider an application script with a reactive interface.
using GenieFramework, Stipple
@genietools
@app begin
@in x = 2.0
@in y = 8.0
@out a = 3.0
@onchange x, y begin
a = log(x, y)
end
end
function ui()
row([column([ textfield("Основание:", :x, type="number", min=0),
textfield("Число:", :y, type="number", min=0),
textfield("Значение логарифма:", :a, readonly=true) ])])
end
@page("/", ui)
Let’s launch the app.
genie_app1 = engee.genie.start("$(@__DIR__)/log_app1.jl")
display("text/html", """<a href="$(string(genie_app1.url))" target="_blank">Open in a new tab</a>""")
The user simply needs to enter the base in the first line and the logarithm argument in the second. The value of the logarithm is calculated automatically once the initial data has been entered.
Starting from a button
Let’s consider an application script in which calculations are performed at the click of a button.
using GenieFramework, Stipple
@genietools
@app begin
@in x = 2.0
@in y = 8.0
@in кнопка = false
@out a = 3.0
@onchange кнопка begin
if кнопка
a = log(x, y)
кнопка = false
end
end
end
function ui()
row([ column([ textfield("Основание:", :x, type="number", min=0),
textfield("Число:", :y, type="number", min=0),
textfield("Значение логарифма:", :a, readonly=true),
btn("Вычислить", @click(:кнопка)) ])])
end
@page("/", ui)
Let’s launch the app.
genie_app2 = engee.genie.start("$(@__DIR__)/log_app2.jl")
display("text/html", """<a href="$(string(genie_app2.url))" target="_blank">Open in a new tab</a>""")
As in the previous application, the user needs to enter the source data in the first two lines. However, here the calculation takes place after clicking the ‘Calculate’ button.
Stop the applications.
engee.genie.stop("$(@__DIR__)/log_app1.jl");
engee.genie.stop("$(@__DIR__)/log_app2.jl");
Conclusion
The examples provided clearly demonstrate Genie’s flexibility in creating interactive tools, ranging from reactive, instantaneous calculation to classic button control. This approach opens up great opportunities for rapid prototyping of engineering calculators, educational widgets and enterprise utilities directly within the Genie environment. You can use the applications presented here as a basis for your future projects.