lejmer

Canvas

Library "Canvas"
A library implementing a kind of "canvas" using a table where each pixel is represented by a table cell and the pixel color by the background color of each cell.
To use the library, you need to create a color matrix (represented as an array) and a canvas table.
The canvas table is the container of the canvas, and the color matrix determines what color each pixel in the canvas should have.

max_canvas_size() Function that returns the maximum size of the canvas (100). The canvas is always square, so the size is equal to rows (as opposed to not rows multiplied by columns).
  Returns: The maximum size of the canvas (100).

get_bg_color(color_matrix) Get the current background color of the color matrix. This is the default color used when erasing pixels or clearing a canvas.
  Parameters:
    color_matrix: The color matrix.
  Returns: The current background color.

get_fg_color(color_matrix) Get the current foreground color of the color matrix. This is the default color used when drawing pixels.
  Parameters:
    color_matrix: The color matrix.
  Returns: The current foreground color.

set_bg_color(color_matrix, bg_color) Set the background color of the color matrix. This is the default color used when erasing pixels or clearing a canvas.
  Parameters:
    color_matrix: The color matrix.
    bg_color: The new background color.

set_fg_color(color_matrix, fg_color) Set the foreground color of the color matrix. This is the default color used when drawing pixels.
  Parameters:
    color_matrix: The color matrix.
    fg_color: The new foreground color.

color_matrix_rows(color_matrix, rows) Function that returns how many rows a color matrix consists of.
  Parameters:
    color_matrix: The color matrix.
    rows: (Optional) The number of rows of the color matrix. This can be omitted, but if used, can speed up execution.
  Returns: The number of rows a color matrix consists of.

pixel_color(color_matrix, x, y, rows) Get the color of the pixel at the specified coordinates.
  Parameters:
    color_matrix: The color matrix.
    x: The X coordinate for the pixel. Must be between 0 and "color_matrix_rows() - 1".
    y: The Y coordinate for the pixel. Must be between 0 and "color_matrix_rows() - 1".
    rows: (Optional) The number of rows of the color matrix. This can be omitted, but if used, can speed up execution.
  Returns: The color of the pixel at the specified coordinates.

draw_pixel(color_matrix, x, y, pixel_color, rows) Draw a pixel at the specified X and Y coordinates. Uses the specified color.
  Parameters:
    color_matrix: The color matrix.
    x: The X coordinate for the pixel. Must be between 0 and "color_matrix_rows() - 1".
    y: The Y coordinate for the pixel. Must be between 0 and "color_matrix_rows() - 1".
    pixel_color: The color of the pixel.
    rows: (Optional) The number of rows of the color matrix. This can be omitted, but if used, can speed up execution.

draw_pixel(color_matrix, x, y, rows) Draw a pixel at the specified X and Y coordinates. Uses the current foreground color.
  Parameters:
    color_matrix: The color matrix.
    x: The X coordinate for the pixel. Must be between 0 and "color_matrix_rows() - 1".
    y: The Y coordinate for the pixel. Must be between 0 and "color_matrix_rows() - 1".
    rows: (Optional) The number of rows of the color matrix. This can be omitted, but if used, can speed up execution.

erase_pixel(color_matrix, x, y, rows) Erase a pixel at the specified X and Y coordinates, replacing it with the background color.
  Parameters:
    color_matrix: The color matrix.
    x: The X coordinate for the pixel. Must be between 0 and "color_matrix_rows() - 1".
    y: The Y coordinate for the pixel. Must be between 0 and "color_matrix_rows() - 1".
    rows: (Optional) The number of rows of the color matrix. This can be omitted, but if used, can speed up execution.

init_color_matrix(rows, bg_color, fg_color) Create and initialize a color matrix with the specified number of rows. The number of columns will be equal to the number of rows.
  Parameters:
    rows: The number of rows the color matrix should consist of. This can be omitted, but if used, can speed up execution. It can never be greater than "max_canvas_size()".
    bg_color: (Optional) The initial background color. The default is black.
    fg_color: (Optional) The initial foreground color. The default is white.
  Returns: The array representing the color matrix.

init_canvas(color_matrix, pixel_width, pixel_height, position) Create and initialize a canvas table.
  Parameters:
    color_matrix: The color matrix.
    pixel_width: (Optional) The pixel width (in % of the pane width). The default width is 0.35%.
    pixel_height: (Optional) The pixel width (in % of the pane height). The default width is 0.60%.
    position: (Optional) The position for the table representing the canvas. The default is "position.middle_center".
  Returns: The canvas table.

clear(color_matrix, rows) Clear a color matrix, replacing all pixels with the current background color.
  Parameters:
    color_matrix: The color matrix.
    rows: The number of rows of the color matrix. This can be omitted, but if used, can speed up execution.

update(canvas, color_matrix, rows) This updates the canvas with the colors from the color matrix. No changes to the canvas gets plotted until this function is called.
  Parameters:
    canvas: The canvas table.
    color_matrix: The color matrix.
    rows: The number of rows of the color matrix. This can be omitted, but if used, can speed up execution.
파인 라이브러리

트레이딩뷰 정신에 따라 오써는 이 파인 코드를 오픈 소스 라이브러리로 퍼블리쉬하여 당사 커뮤니티의 다른 파인 프로그래머들이 쓸 수 있도록 하였습니다. 오써에게 찬사를! 여러분은 이 라이브러리를 프라이빗 또는 오픈 소스 퍼블리케이션에 쓸 수 있지만 퍼블리케이션에 재사용은 하우스룰을 따릅니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

이 라이브러리를 쓰시겠습니까?

텍스트를 클립보드에 카피한 뒤 님의 스크립트에 붙여 넣기.