Codea 에서 기본적으로 제공해주는 예제인 Lines이다.

function setup()
    -- Expose parameters to control our line

    -- The start point
    parameter.number("x1",0,WIDTH,100)
    parameter.number("y1",0,HEIGHT,100)

    -- The end point
    parameter.number("x2",0,WIDTH,WIDTH-100)
    parameter.number("y2",0,HEIGHT,HEIGHT-100)

    -- The stroke width
    parameter.number("width",1,100,10)
    
    -- The line cap type
    parameter.integer("lineCap",0,2,0)
end

function draw()
    background(10,10,20)

    -- Set stroke and fill color to white
    fill(255,0,0)
    stroke(255)

    -- Update stroke width
    strokeWidth(width)

    if width < 3 then
        -- Disable smoothing for low widths
        noSmooth()
    else
        smooth()
    end

    -- Set the line cap mode
    lineCapMode(lineCap)

    -- Draw the line
    line(x1,y1,x2,y2)
end

SQL 문법처럼 대시 두개가 주석의 역할을 하는 것 같다.

background를 주석처리 해봤더니 이전의 선들이 안지워진다. 프레임 워크 자체 버그인지 백그라운드가 저 선들을 가려주는 건지는 아직 모르겠다.  관련 커뮤니티에 질문을 남겨봤다. 백그라운드 함수 자체가 이전 화면을 클리어시켜주고, 그 이후에 백그라운드 색을 채색시키는 함수였다. 그래서 이전의 선들이 그대로 남아있던 것이다.

setup 함수에 파라미터들을 넣어주고 선을 자유롭게 변경할 수 있도록 되어있다.
parameter로 만들수 있게끔 해주는 자체 기능인것 같다.

Codea의 Parameter에 대해서는 다음 글에 포스팅을 해 두었다.

+ Recent posts