CanvasViewport¶
-
class
visualife.core.CanvasViewport(canvas, width, height)¶ Bases:
objectCreates a Canvas drawing
It has been created by the following code:
from browser import document from visualife.core import CanvasViewport from visualife.core.styles import known_color_scales cnvs = document["canvas"].getContext("2d") drawing = CanvasViewport(cnvs,400,100) j=1 i=1 width=30 height=30 xx,yy=[],[] c=known_color_scales["magma"] for z in range(40): x = 1.5 * width * i y = height/2 * j if j % 2 == 0: x += 0.75 * width i += 1 if i == 9: j += 1 i = 1 xx.append(x) yy.append(y) drawing.rhomb_group("rhombs",xx,yy,c,15)
Defines a drawing area
Methods Summary
binary_map(matrix_or_string, dimension_rows, …)Draws a graphic representation of 2D matrix circle(id_str, x, y, r, **kwargs)Draws a circle circles_group(gid, x, y, c, r, **kwargs)Draws a circles group clear([x, y])Clears viewport close()Does nothing; implemented to comply with the base class interface ellipse(id_str, x, y, rx, ry, **kwargs)Draws an ellipse error_msg(msg)Prints error message get_height()Returns viewport height get_width()Returns viewport width line(id_str, xb, yb, xe, ye, **kwargs)Draws a line polygon(id_str, points, **kwargs)Draws a polygon rect(id_str, x, y, w, h, **kwargs)Draws a rect rhomb(id_str, x, y, r, **kwargs)Draws a rhomb rhomb_group(gid, x, y, c, r, **kwargs)Draws a rhomb group square(id_str, x, y, a, **kwargs)Draws a square squares_grid(gid, x0, y0, w, h, rows, …)Draws a squares group squares_group(id_str, x, y, c, a, **kwargs)Draws a squares group text(id_str, x, y, text, **kwargs)Draws a text translate(delta_x, delta_y)Sets delta_x and delta_y as new (0,0) point triangle(id_str, x, y, r, **kwargs)Draws a tiangle triangle_group(gid, x, y, c, r, **kwargs)Draws a triangle group viewport_name()Returns the name if this viewport, which is always “CANVAS” Methods Documentation
-
binary_map(matrix_or_string: list, dimension_rows: int, dimension_columns: int, cmap)¶ Draws a graphic representation of 2D matrix
Parameters: - matrix_or_string –
list[list]or astringholding the data - dimension_rows – number of rows
- dimension_columns – number of columns
- cmap – ColorMap object used to convert values into colors
- matrix_or_string –
-
circle(id_str, x, y, r, **kwargs)¶ Draws a circle
Parameters: - id_str – id of this circle
- x – x coordinate
- y – y coordinate
- r – radius length
Returns: None
-
circles_group(gid, x, y, c, r, **kwargs)¶ Draws a circles group
Parameters: - id_str – id of this group
- x – list of x coordinates
- y – list of y coordinates
- r – radius length or a list of radius lengths
Returns: None
-
clear(x=0, y=0)¶ Clears viewport
-
close()¶ Does nothing; implemented to comply with the base class interface
-
ellipse(id_str, x, y, rx, ry, **kwargs)¶ Draws an ellipse
Parameters: - id_str – id of this ellipse
- x – x coordinate of a center
- y – y coordinate of a center
- rx – x radius length
- ry – y radius length
Returns: None
-
error_msg(msg)¶ Prints error message
Prints error message to screen or browser’s console
-
get_height()¶ Returns viewport height
-
get_width()¶ Returns viewport width
-
line(id_str, xb, yb, xe, ye, **kwargs)¶ Draws a line
Parameters: - id_str – id of this line
- xb – x coordinate of line begin
- yb – y coordinate of line begin
- xe – side length of line end
- ye – side length of line end
Returns: None
-
polygon(id_str, points, **kwargs)¶ Draws a polygon
Parameters: - id_str – id of this polygon
- points – list of points
Returns: None
-
rect(id_str, x, y, w, h, **kwargs)¶ Draws a rect
Parameters: - id_str – id of this rect
- x – x coordinate
- y – y coordinate
- w – width of this rect
- h – height of this rect
Returns: None
-
rhomb(id_str, x, y, r, **kwargs)¶ Draws a rhomb
Parameters: - id_str – id of this rhomb
- x – x coordinate of a center
- y – y coordinate of a center
- r – side length
Returns: None
-
rhomb_group(gid, x, y, c, r, **kwargs)¶ Draws a rhomb group
Parameters: - id_str – id of this group
- x – list of x coordinates
- y – list of y coordinates
- r – side length
Returns: None
-
square(id_str, x, y, a, **kwargs)¶ Draws a square
Parameters: - id_str – id of this square
- x – x coordinate of the center of this square
- y – y coordinate of the center of this square
- a – side length
Returns: None
-
squares_grid(gid, x0, y0, w, h, rows, columns, **kwargs)¶ Draws a squares group
Parameters: - id_str – id of this group
- x – list of x coordinates
- y – list of y coordinates
- c – list of colors for the squares
- a – side length
Returns: None
-
squares_group(id_str, x, y, c, a, **kwargs)¶ Draws a squares group
Parameters: - id_str – id of this group
- x – list of x coordinates
- y – list of y coordinates
- c – list of colors for the squares
- a – side length
Returns: None
-
text(id_str, x, y, text, **kwargs)¶ Draws a text
Parameters: - id_str – id of this text
- x – x coordinate of a center
- y – y coordinate of a center
- text – text to be written
Returns: None
-
translate(delta_x, delta_y)¶ Sets delta_x and delta_y as new (0,0) point
-
triangle(id_str, x, y, r, **kwargs)¶ Draws a tiangle
Parameters: - id_str – id of this triangle
- x – x coordinate of a center
- y – y coordinate of a center
- r – side length
Returns: None
-
triangle_group(gid, x, y, c, r, **kwargs)¶ Draws a triangle group
Parameters: - id_str – id of this group
- x – list of x coordinates
- y – list of y coordinates
- r – side length
Returns: None
-
viewport_name()¶ Returns the name if this viewport, which is always “CANVAS”
-