World Conquest Chronicles

World Conquest Chronicles

luaplot, v1.2

The library that implements a model of a 2D plot with support for displaying functions of time (as in an oscilloscope).

Calculating a difference (a distance) between two 2D plots/oscillograms in the same index.

Change Log

  • models:
    • 2D plot:
      • operations:
        • iterating over values:
          • via the __ipairs metamethod (for Lua 5.2):
            • using the __index metamethod for accessing by index;
          • via the __index metamethod (for Lua 5.3+):
            • support of fractional indexes;
  • global operations:
    • calculating a difference (a distance) between two 2D plots/oscillograms in the same index:
      • returning a difference (a distance) by modulo (optionally);
  • refactoring:
    • adding the maths.lerp() function;
    • adding the Iterable mixin.

Features

  • models:
    • 2D plot:
      • storing:
        • values of a displayed function;
        • limits for these values;
        • default value;
      • operations:
        • initializing:
          • filling a specified count of values by a specified default value;
        • iterating over values:
          • via the __ipairs metamethod (for Lua 5.2);
          • via the __index metamethod (for Lua 5.3+):
            • support of fractional indexes;
        • adding a new value:
          • specific;
          • with a shift from the last value:
            • with a specific shift;
            • with a random shift;
            • using a specified default value as the last value if no values;
          • clamping the added value to specified limits;
        • removing the first value:
          • returning the removed value:
            • returning a specified default value if no values;
    • 2D oscillogram:
      • extending the 2D plot model;
      • kinds:
        • custom (adding a specific new value);
        • linear (adding a new value with a specific shift from the last value);
        • random (adding a new value with a random shift from the last value);
      • operations:
        • updating:
          • first step: adding a new value;
          • second step: removing the first value;
    • 2D plot/oscillogram iterator:
      • storing:
        • 2D plot/oscillogram;
        • transformer for iterated values;
      • iterating over values of 2D plot/oscillogram:
        • via the __ipairs metamethod (for Lua 5.2);
        • via the __index metamethod (for Lua 5.3+);
      • applying transformations to iterated values via a specified transformer;
    • factory of a 2D plot/oscillogram iterator:
      • storing:
        • transformer for iterated values;
      • generating a 2D plot/oscillogram iterator for a specific 2D plot/oscillogram;
  • global operations:
    • calculating a difference (a distance) between two 2D plots/oscillograms in the same index:
      • returning a difference (a distance) by modulo (optionally).

Examples

Fractional indexes:

local iterators = require("luaplot.iterators")
local Plot = require("luaplot.plot")

local plot_one = Plot:new(0)
for i = 1, 5 do
  plot_one:push(i / 10)
end

local plot_two = Plot:new(0)
for i = 1, 5 do
  plot_two:push(i / 16)
end

local item_one = plot_one[3.2]
print(string.format("plot_one[3.2] = %g", item_one))

local item_two = plot_two[3.2]
print(string.format("plot_two[3.2] = %g", item_two))

local difference = iterators.difference(plot_one, plot_two, 3.2)
print(string.format("difference = %g", difference))

Repository

Link: https://github.com/thewizardplusplus/luaplot/tree/v1.2.

Content: code.

License: MIT.