Skip to content

Instantly share code, notes, and snippets.

@User4574
Created March 20, 2022 14:20
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 User4574/c304784e391365557584a3467fb5c2b3 to your computer and use it in GitHub Desktop.
Save User4574/c304784e391365557584a3467fb5c2b3 to your computer and use it in GitHub Desktop.
Output cartesian coordinates for the tickmarks along a log scale around a circle
#!/usr/bin/env ruby
Maths = Math
Intervals = ARGV.shift&.to_i || 2
Radius = ARGV.shift&.to_i || 25
Decimals = ARGV.shift&.to_i || 3
Scale = Maths::PI * 2 / Intervals
Width = 1 + Maths.log10(Radius).to_i + 1 + 1 + Decimals
def a_tick(mantissa, exponent)
tick = mantissa * (10 ** exponent)
loc = Scale * (exponent + Maths.log10(mantissa))
x = Radius * Maths.cos(loc)
y = Radius * Maths.sin(loc)
puts "%#{Intervals + 1}d: (%4.2fr) %#{Width}.#{Decimals}f %#{Width}.#{Decimals}f" % [tick, loc, x, y]
end
puts "Max #{10 ** Intervals} (#{Intervals} intervals), radius #{Radius}, #{Decimals} decimals"
Intervals.times do |exponent|
(1..9).each do |mantissa|
a_tick(mantissa, exponent)
end
end
a_tick(1, Intervals)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment