Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local xratio = 10.0
- local yratio = 10.0
- local number = 10000
- local wmin = 1.0
- local hmin = 1.0
- local detalization = 1000
- local wmax = wmin * xratio
- local hmax = hmin * yratio
- local points = {}
- for i = 0, detalization do
- local xi = i * wmax / detalization
- table.insert(points, {xi, 0.0})
- end
- for i = 1, number do
- local w = wmin + (wmax - wmin) * math.random()
- local h = hmin + (hmax - hmin) * math.random()
- local l = (wmax - w) * math.random()
- local r = l + w
- local mean = (l + r) / 2.0
- for _, point in ipairs(points) do
- if l <= point[1] and point[1] <= r then
- local y
- if point[1] < mean then
- local x = (point[1] - l) / (mean - l)
- y = math.sqrt((2.0 - x) * x)
- else
- local x = (point[1] - mean) / (r - mean)
- y = 1.0 - math.sqrt((2.0 - x) * x)
- end
- point[2] = point[2] + y * h
- end
- end
- end
- local gnuplot = io.popen('gnuplot', 'w')
- gnuplot:write('reset;\n')
- gnuplot:write('set terminal wxt 1;\n')
- gnuplot:write(string.format('set xrange [%f:%f];\n', 0.0, wmax))
- gnuplot:write(string.format('set yrange [%f:%f];\n', 0.0, hmax * number))
- gnuplot:write('set size square;\n')
- gnuplot:write(string.format('set xtics %f;\n', wmax / 10.0))
- gnuplot:write(string.format('set ytics %f;\n', hmax * number / 10.0))
- gnuplot:write('set grid xtics ytics;\n')
- gnuplot:write('plot "-" using 1:2 notitle with lines;\n')
- for _, point in ipairs(points) do
- gnuplot:write(string.format('%f %f\n', point[1], point[2]))
- end
- gnuplot:write('e\n')
- gnuplot:flush();
- os.execute('pause');
- gnuplot:write('exit\n');
- gnuplot:flush();
- gnuplot:close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement