mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
examples: improve the pendulum simulation, with several modes and diagrams (#13446)
This commit is contained in:

committed by
GitHub

parent
a74d28ae5f
commit
4391ae563d
30
examples/pendulum-simulation/sequential.v
Normal file
30
examples/pendulum-simulation/sequential.v
Normal file
@ -0,0 +1,30 @@
|
||||
module main
|
||||
|
||||
import benchmark
|
||||
import sim
|
||||
import sim.args as simargs
|
||||
import sim.img
|
||||
|
||||
fn main() {
|
||||
args := simargs.parse_args(sequential: true) ? as simargs.SequentialArgs
|
||||
|
||||
mut bmark := benchmark.start()
|
||||
defer {
|
||||
bmark.measure(@FN)
|
||||
}
|
||||
|
||||
mut writer := img.ppm_writer_for_fname(args.filename, img.image_settings_from_grid(args.grid)) ?
|
||||
defer {
|
||||
writer.close()
|
||||
}
|
||||
|
||||
handle_request := fn [mut writer] (request &sim.SimRequest) ? {
|
||||
result := sim.compute_result(request)
|
||||
pixel := img.compute_pixel(result)
|
||||
return writer.handle_pixel(pixel)
|
||||
}
|
||||
|
||||
sim.run(args.params, grid: args.grid, on_request: sim.SimRequestHandler(handle_request))
|
||||
|
||||
writer.write() ?
|
||||
}
|
Reference in New Issue
Block a user