Skip to content

Instantly share code, notes, and snippets.

@emlun
Last active July 15, 2019 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emlun/0458a601031546ea9596d63427b1a6e6 to your computer and use it in GitHub Desktop.
Save emlun/0458a601031546ea9596d63427b1a6e6 to your computer and use it in GitHub Desktop.
Factorio: Speed vs productivity modules visualisation
speedf_speed = 0.5;
speedf_prod = -0.15;
countf_prod = 0.1;
n_bcn_speed = 0:12;
n_mod_prod = 0:4;
n_mod_speed = 4 - n_mod_prod;
function [spd_diff_percent] = compute_speeds (
speedf_speed, speedf_prod, countf_prod,
n_bcn_speed, n_mod_prod, n_mod_speed
)
tot_mod_speed = repmat(n_bcn_speed, size(n_mod_speed, 2), 1) + repmat(n_mod_speed', 1, size(n_bcn_speed, 2));
tot_mod_prod = repmat(n_mod_prod', 1, size(n_bcn_speed, 2));
spd_no_prod = 1 + speedf_speed * (4 + n_bcn_speed)
spd = (1 + speedf_speed * tot_mod_speed + speedf_prod * tot_mod_prod) .* (1 + countf_prod * tot_mod_prod)
spd_diff = spd - spd_no_prod
spd_diff_percent = spd_diff ./ repmat(spd_no_prod, size(n_mod_prod, 2), 1) * 100
end
function [cmap, cbar_ticks] = compute_colormap (spd_diff)
colormap_n = 64;
max_spd = max(max(spd_diff));
min_spd = min(min(spd_diff));
spd_range = max_spd - min_spd;
index_of_zero = (colormap_n - 1) * (-min_spd / spd_range);
colormap_midpoint = [1 1 1];
colormap_front = linspace([1 0 0], colormap_midpoint, index_of_zero + 1);
colormap_tail = linspace(colormap_midpoint, [0 0 1], colormap_n - index_of_zero + 1);
cmap = [colormap_front, colormap_tail(:, 2:size(colormap_tail, 2))]';
colorbar_n_ticks = 10;
colorbar_zero_index = (colorbar_n_ticks - 1) * (-min_spd / spd_range);
cbar_ticks_front = linspace(min_spd, 0, colorbar_zero_index + 1);
cbar_ticks_tail = linspace(0, max_spd, colorbar_n_ticks - colorbar_zero_index + 1);
cbar_ticks = [cbar_ticks_front, cbar_ticks_tail(:, 2:size(cbar_ticks_tail, 2))];
end
function [] = draw_figure (spd_diff, n_bcn_speed, n_mod_prod)
surf(n_bcn_speed, n_mod_prod, spd_diff);
[cmap, cbar_ticks] = compute_colormap(spd_diff);
colormap(cmap);
cbar = colorbar;
axis auto;
xlabel("Speed 3 beacons");
ylabel("Productivity 3 modules");
zlabel("Output speed % rel. all speed modules");
set(cbar, 'YTick', cbar_ticks);
end
spd_diff = compute_speeds(
speedf_speed, speedf_prod, countf_prod,
n_bcn_speed, n_mod_prod, n_mod_speed
);
figure(1);
clf;
draw_figure(spd_diff, n_bcn_speed, n_mod_prod);
view([-37.5 + 90*3, 30]);
title("View 1")
figure(2);
clf;
draw_figure(spd_diff, n_bcn_speed, n_mod_prod);
view([-37.5 + 90*0, 30]);
hold on;
mesh(n_bcn_speed, n_mod_prod, zeros(5, size(n_bcn_speed, 2)));
title("View 2 with zero plane")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment