Skip to content

Instantly share code, notes, and snippets.

@alexisvl
Created March 21, 2015 14:38
Show Gist options
  • Save alexisvl/874a544854e1527c842f to your computer and use it in GitHub Desktop.
Save alexisvl/874a544854e1527c842f to your computer and use it in GitHub Desktop.
KiCad eeschema sine wave symbol generator
#!/usr/bin/ruby
# Generates a 'sine wave' KiCad schematic symbol, for annotation
print("Amplitude (mils)? ")
amp = gets.to_i
print("Period (mils)? ")
per = gets.to_i
print("Number of cycles? ")
cycles = gets.to_i
print("Number of segments? ")
segs = gets.to_i
print("Component name? ")
name = gets.strip
puts (%(#
# #{name}
#
DEF ~#{name} #SYM 0 40 Y Y 1 F N
F0 "#SYM" 0 0 60 H I C CNN
F1 "#{name}" 0 0 60 H I C CNN
F2 "" 0 0 60 H V C CNN
F3 "" 0 0 60 H V C CNN
DRAW))
start_x = -per * (cycles / 2)
seg_delta = (per * cycles) / segs
(0..segs).each do |nseg|
seg_x_start = start_x + (seg_delta * nseg)
seg_x_end = seg_x_start + seg_delta
seg_y_start = amp * Math::sin(seg_x_start * 2.0 * Math::PI / per)
seg_y_end = amp * Math::sin(seg_x_end * 2.0 * Math::PI / per)
puts "P 2 0 1 10 #{seg_x_start.to_i} #{seg_y_start.to_i} #{seg_x_end.to_i} #{seg_y_end.to_i}"
end
puts("ENDDRAW\nENDDEF")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment