Skip to content

Commit

Permalink
color tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonOresten committed Nov 15, 2023
1 parent e3efb21 commit 3e1d8c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ribbon/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function ribbon!(
protein::Protein,
colorscheme::ColorScheme = ColorSchemes.jet,
)
color_vectors = [chain_color_vector(chain, colorscheme) for chain in protein]
color_vectors = [smooth_color_vector(colorscheme, length(chain)) for chain in protein]
ribbon!(container, protein, color_vectors)
end

Expand Down
24 changes: 17 additions & 7 deletions src/ribbon/utils.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# expand vector to have length N while keeping the same discrete color gradient
function smooth_color_vector(colorscheme::ColorScheme, N::Integer)
return colorscheme[LinRange(0, 1, N)]
end

# expand vector to have length N while keeping the same discrete color scheme
function expand_colors(colors::Vector, N::Integer)
L = length(colors)
color_matrix = reshape(repeat(colors, inner=ceil(Int, N/L))[1:N], :, 1)
return color_matrix
end
repeats = ceil(Int, N / L)
total_elements = repeats * L
extra_elements = total_elements - N

# Distribute the extra elements evenly across the vector
result = Vector{eltype(colors)}()
for i in 1:L
# Calculate the number of repeats for this element
current_repeats = repeats - (i <= extra_elements ? 1 : 0)
append!(result, fill(colors[i], current_repeats))
end

function chain_color_vector(chain::Chain, colorscheme::ColorScheme)
#return repeat([colorant"red", colorant"blue"], length(chain) ÷ 2 + 1)[1:length(chain)]
return colorscheme[LinRange(0, 1, length(chain))]
return reshape(result[1:N], :, 1)
end

0 comments on commit 3e1d8c5

Please sign in to comment.