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.
Thư viện Pine

Với tinh thần TradingView thực sự, tác giả đã xuất bản mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác từ cộng đồng của chúng tôi có thể sử dụng lại nó. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này một cách riêng tư hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc sử dụng lại mã này trong một ấn phẩm chịu sự điều chỉnh của Nội quy chung.

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.

Bạn muốn sử dụng thư viện này?

Sao chép văn bản vào khay nhớ tạm và dán nó vào tập lệnh của bạn.