draw a function

edited April 2015 in Layout
Hello
Is it possible to draw a path behaving according to specific function,like sin(x)?

thanks
shirly

Comments

  • edited April 2015

    Yes. Open a new layout with a new layer 1, and run this:

    include RBA
    lv = Application.instance.main_window.current_view
    layout = lv.active_cellview.layout
    dbu = layout.dbu
    out_cell = lv.active_cellview.cell
    out_layer = layout.layer(1,0)
    width = 1 # um
    x_start = 0 # um
    x_end = 4*Math::PI # Two cycles of 2pi
    x_inc = 0.1 # um
    x = (x_start..x_end).step(x_inc).to_a
    y = x.map { |xx| Math.sin(xx) }
    pts = []
    x.length.times { |i| 
      pts << Point.new(x[i]/dbu,y[i]/dbu)
    }
    path = Path.new(pts,width/dbu)
    out_cell.shapes(out_layer).insert(path)
    
  • edited November -1
    Hi David
    Thanks
    I am sorry for the maybe stupid question (this is first time for me working with the klayout scripting)
    Trying to run the script you gave me,i recieve an error saying "undefined method 'layer' for the layout"
    What should i do?
    Thanks again (i know this is very basic questions)
    shirly
  • edited April 2015

    Probably you are running an old version of KL. The Layout.layer method was introduced in version 0.23. Did that fix it?

    There is a way to do the same thing on pre-0.23, but I recommend just upgrading.

    No question is silly! Here to help! I think you'll find KL scripting to be extremely powerful tool! For me it is the #1 attraction of KL.

  • edited November -1
    Hi David,

    I tested your script, it's working for me.
    I don't know that we can do that in KL.

    Thank you
Sign In or Register to comment.