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.
Pine脚本库

本着真正的TradingView精神,作者将此Pine代码以开源脚本库发布,以便我们社区的其他Pine程序员可以重用它。向作者致敬!您可以私下或在其他开源出版物中使用此库,但在出版物中重用此代码受网站规则约束。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想使用这个脚本库吗?

复制以下行并将其粘贴到您的脚本中。