Drawing method and device based on turtle library, equipment and storage medium

CN116485923BActive Publication Date: 2026-08-07CHINA PETROLEUM & CHEMICAL CORP +1
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CHINA PETROLEUM & CHEMICAL CORP
Filing Date
2022-01-13
Publication Date
2026-08-07

AI Technical Summary

Technical Problem

[0004]在工业领域进行数据分析制图时,需要投入大量的工作量来针对多幅图形进行多次的编程工作来将图形的函数程序与Turtle库的画布(canvas)各种参数相匹配,从而造成工作效率很低

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116485923B_ABST
    Figure CN116485923B_ABST
Patent Text Reader

Abstract

The application discloses a drawing method and device based on a Turtle library, equipment and a storage medium. The method comprises the following steps: acquiring drawing setting values; acquiring original coordinate data of each to-be-drawn figure; generating an X list and a Y list according to the original coordinate data of each to-be-drawn figure; the sublists in the X list and the Y list correspond to each other one by one, and the two sublists corresponding to each other in the X list and the Y list are the original coordinate data of the same to-be-drawn figure; taking the drawing setting values as parameters, performing operation conversion on the data of each sublist in the X list and the Y list according to a preset formula, and converting the original coordinate data in the sublists into drawing coordinate data in a canvas coordinate system; when multiple images are drawn in the same canvas, the application no longer needs to invest a large amount of workload to perform multiple programming operations on multiple figures to match the function program of the figures with various parameters of the canvas of the Turtle library, and thus the drawing efficiency can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial drawing, and in particular to drawing methods, apparatus, devices, and storage media based on the Turtle library. Background Technology

[0002] The Turtle library is a popular image drawing library in the Python language. Its principle is like a little turtle. Starting from the origin (0,0) in a coordinate system with the horizontal axis as x and the vertical axis as y, it moves on the plane coordinate system of the canvas according to a set of function instructions, thereby drawing graphics on its trajectory.

[0003] The inventors discovered through research that existing drawing methods based on the Turtle library have at least the following drawbacks:

[0004] In industrial data analysis and charting, a significant amount of work is required to program multiple times for multiple charts to match the chart functions with the various parameters of the Turtle library's canvas, resulting in very low work efficiency.

[0005] The information disclosed in this background section is intended only to enhance the understanding of the overall background of the invention and should not be construed as an admission or in any way implying that the information constitutes prior art known to those skilled in the art. Summary of the Invention

[0006] The purpose of this invention is to improve the efficiency of data analysis and charting in the industrial field.

[0007] This invention provides a drawing method based on the Turtle library, comprising the following steps:

[0008] S11. Obtain drawing settings; the drawing settings include the number of graphics to be drawn in each row of the canvas, the coordinates of the first starting point of the first graphic to be drawn on the canvas, and the horizontal and vertical spacing between adjacent graphics to be drawn.

[0009] S12. Obtain the original coordinate data of each of the graphics to be drawn, wherein the original coordinate data includes X-axis data and Y-axis data;

[0010] S13. Generate an X list and a Y list based on the original coordinate data of each of the graphics to be drawn; each sublist of the X list is the X-axis dataset in the original coordinate data of each of the graphics to be drawn; each sublist of the Y list is the Y-axis dataset in the original coordinate data of each of the graphics to be drawn; the sublists in the X list and the Y list correspond one-to-one, and two corresponding sublists in the X list and the Y list are the original coordinate data of the same graphics to be drawn;

[0011] S14. Using the drawing settings as parameters, perform calculations and transformations on the data of each sublist in the X list and the Y list according to the preset formula, and convert the original coordinate data in the sublist into drawing coordinate data in the canvas coordinate system.

[0012] Preferably, in this invention, it further includes:

[0013] The drawing commands from the turtle library are used to convert the data into drawing coordinates in the canvas coordinate system, which are then used to draw the data on the canvas.

[0014] Preferably, in this invention, the step of using the drawing setting value as a parameter to perform calculations and transformations on the data of each sublist in the X list and the Y list according to a preset formula, converting the original coordinate data in the sublists into drawing coordinate data in the canvas coordinate system, includes:

[0015] S21. Based on the number of single-row graphics, the coordinates of the first starting point, and the horizontal and vertical spacing values, determine the uniform width and uniform height of each graphic to be drawn in the canvas.

[0016] S22. According to the preset formulas: X=kx+b, and Y=k'y+b', perform preliminary calculations and transformations on the X-axis datasets in each sublist of the X list and on the Y-axis datasets in each sublist of the Y list, respectively; wherein:

[0017] The preset formula includes X=kx+b, which is used to perform calculations and transformations on the X-axis datasets in each sublist of the X list; where X is the transformed X-axis data; x is the X-axis data in the original coordinate data; k is the first scaling ratio; b is the horizontal coordinate offset; the first scaling ratio and the horizontal coordinate offset constitute a first transformation parameter combination, and the value of the first transformation parameter combination has a one-to-one correspondence with each sublist of the X list;

[0018] The calculation formula for the value of the first transformation parameter combination corresponding to the sublist in the X list includes:

[0019] The formula for calculating the value of the first scaling factor k of the nth sublist in the X list includes:

[0020] k= picture_width / (max_x[n]-min_x[n]);

[0021] Where, picture_width is the uniform width; max_x[n] is the maximum value of the X-axis data in the nth sublist of the X list; min_x[n] is the minimum value of the X-axis data in the nth sublist of the X list; n is a positive integer starting from 0;

[0022] The formula for calculating the x-coordinate offset b of the nth sublist in the X list includes:

[0023] b= (start_point_X+(n+1) * picture_width +(n-1) *pic_Distance_x)- max_x[n] * k;

[0024] Where start_point_X is the x-coordinate of the first starting point; pic_Distance_x is the horizontal spacing value;

[0025] The preset formula also includes Y=k'y+b', which is used to perform calculations and transformations on the Y-axis datasets in each sublist of the Y list; where Y is the transformed Y-axis data; y is the Y-axis data in the original coordinate data; k' is the second scaling ratio; b' is the ordinate offset; the second scaling ratio and the ordinate offset constitute the second transformation parameter combination, and the value of the second transformation parameter combination has a one-to-one correspondence with each sublist of the Y list;

[0026] The calculation formula for the value of the second transformation parameter combination corresponding to the sublist in the Y list includes:

[0027] The formula for calculating the value of the second scaling factor k' of the nth sublist in the Y list includes:

[0028] k '= picture_high / (max_y[n]-min_y[n])

[0029] Where picture_high is the uniform height; max_y[n] is the maximum value of the Y-axis data in the nth sublist of the Y list; min_y[n] is the minimum value of the Y-axis data in the nth sublist of the Y list; n is a positive integer starting from 0;

[0030] The formula for calculating the x-coordinate offset b' of the nth sublist in the Y list includes:

[0031] b = (start_point_Y+ picture_high )- max_y[n] * k

[0032] Where start_point_Y is the ordinate value of the first starting point; pic_Distance_y is the vertical spacing value;

[0033] S23. Based on the results of the preliminary calculation and transformation, generate the corresponding X' list and Y' list; each sublist of the X' list is the X-axis dataset after the preliminary calculation and transformation; each sublist of the Y' list is the Y-axis dataset after the preliminary calculation and transformation.

[0034] S24. Perform secondary operations and transformations on the data of each sublist in the X' list and the Y' list respectively to generate the final plotting data, wherein:

[0035] The formulas for performing secondary operations on the data in each sublist of the X' list include:

[0036] X'= X - (picture_width + pic_Distance_x)*(m-1)*col_mun;

[0037] Where X' is the X-axis data used as the final drawing data; X is the X-axis data after preliminary calculation and transformation; col_mun is the number of graphics to be drawn in each row of the canvas; m is the row number of the graphics to be drawn corresponding to the sublist in the canvas;

[0038] The formulas for performing secondary operations on the data in each sublist of the Y' list include:

[0039] Y'=Y - (picture_high+pic_Distance_y)*(m-1)

[0040] Where Y' is the Y-axis data used as the final plotting data; Y' is the Y-axis data after preliminary calculation and transformation.

[0041] Preferably, in this invention, the step of performing calculations and transformations on the X-axis datasets in each sublist of the X list and the Y-axis datasets in each sublist of the Y list according to the preset formulas: X=kx+b and Y=k'y+b', includes:

[0042] Simultaneously, operations and transformations are performed on the data in each sublist of the X list and the Y list, including:

[0043] The X-axis data of each sublist in the X list are read sequentially, and the updated X-axis data of each sublist are calculated according to the first transformation parameter combination corresponding to the sublist using the preset formula: X=kx+b.

[0044] The Y-axis data of each sublist in the Y list are read sequentially, and the updated Y-axis data of each sublist are calculated according to the second transformation parameter combination corresponding to the sublist using the preset formula: Y=k'y+b'.

[0045] Preferably, in this invention, it includes:

[0046] Each of the first conversion parameter combinations is stored in a preset first conversion parameter list, with each list element in the first conversion parameter list being a list element; each list element in the first conversion parameter list corresponds one-to-one with each sublist in the X list;

[0047] Each of the second conversion parameter combinations is stored in a preset second conversion parameter list, with the second conversion parameter combination as a list element; each list element in the first conversion parameter list corresponds one-to-one with each sublist in the Y list.

[0048] Preferably, in this invention, the step of converting drawing command calls from the turtle library into drawing coordinate data in the canvas coordinate system and drawing on the canvas includes:

[0049] After calculating the updated X-axis data of a sublist in the X list and the updated Y-axis data of the sublist in the Y list corresponding to the sublist in the X list, the updated X-axis data and updated Y-axis data are called using the drawing commands in the turtle library, and the corresponding graphic to be drawn is drawn on the canvas.

[0050] When the number of the graphics to be drawn reaches an integer multiple of the number of graphics in a single row, the drawing of the current row is stopped by the break interrupt command and the drawing continues to the next row.

[0051] In another aspect of the invention, a drawing device based on the Turtle library is also provided, comprising:

[0052] The setting value acquisition unit is used to acquire drawing setting values; the drawing setting values ​​include the number of graphics to be drawn in each row of the canvas, the coordinates of the first starting point of the first graphic to be drawn on the canvas, the horizontal spacing value and the vertical spacing value between adjacent graphics to be drawn.

[0053] The raw data acquisition unit is used to acquire the raw coordinate data of each of the graphics to be drawn, wherein the raw coordinate data includes X-axis data and Y-axis data;

[0054] The original list generation unit is used to generate an X list and a Y list respectively based on the original coordinate data of each of the graphics to be drawn; each sublist of the X list is the X-axis dataset in the original coordinate data of each of the graphics to be drawn; each sublist of the Y list is the Y-axis dataset in the original coordinate data of each of the graphics to be drawn; the sublists in the X list and the Y list correspond one-to-one, and two corresponding sublists in the X list and the Y list are the original coordinate data of the same graphics to be drawn;

[0055] The data conversion unit is used to perform calculations and conversions on the data of each sublist in the X list and the Y list according to a preset formula, using the drawing setting value as a parameter, to convert the original coordinate data in the sublist into drawing coordinate data in the canvas coordinate system.

[0056] Preferably, in this invention, it further includes:

[0057] The drawing unit is used to draw on the canvas by converting drawing coordinate data into the canvas coordinate system using drawing command calls from the turtle library.

[0058] In another aspect of this invention, a drawing device based on the Turtle library is also provided, comprising:

[0059] Memory, used to store computer programs;

[0060] A processor for invoking and executing the computer program to implement the various steps of the Turtle library-based drawing method as described in any of the preceding claims.

[0061] In another aspect of the present invention, a storage medium is also provided, on which a computer program is stored, which, when executed by a processor, implements the various steps of the drawing method based on the Turtle library as described in any of the preceding claims.

[0062] The Turtle-based drawing device includes a computer program stored on a medium. The computer program includes program instructions that, when executed by a computer, cause the computer to perform the methods described in the above aspects and achieve the same technical effects.

[0063] Compared with the prior art, the present invention has the following beneficial effects:

[0064] In this invention, after obtaining the original coordinate data of each graphic to be drawn, as long as the row and column arrangement of the multiple graphics to be drawn in the computer drawing software is set, the original coordinate data of the multiple graphics to be drawn can be automatically converted into drawing coordinate data in the canvas coordinate system, and each graphic to be drawn can be adjusted to be presented in the canvas with an appropriate image size.

[0065] Because of this invention, when drawing multiple images on the same canvas, it is no longer necessary to invest a lot of effort in programming multiple times to match the function programs of the graphics with the various parameters of the canvas in the Turtle library, thus effectively improving drawing efficiency.

[0066] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention and to implement it according to the contents of the specification, and to make the above and other objects, technical features and advantages of the present invention easier to understand, one or more preferred embodiments are listed below and described in detail with reference to the accompanying drawings. Attached Figure Description

[0067] To more clearly illustrate the technical solution of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0068] Figure 1 This is a flowchart illustrating the steps of the drawing method based on the Turtle library described in this invention;

[0069] Figure 2 This is a schematic diagram of the drawing device structure based on the Turtle library described in this invention;

[0070] Figure 3 This is a schematic diagram of the drawing device structure based on the Turtle library described in this invention. Detailed Implementation

[0071] The specific embodiments of the present invention will now be described in detail with reference to the accompanying drawings, but it should be understood that the scope of protection of the present invention is not limited to the specific embodiments.

[0072] Unless otherwise expressly stated, throughout the specification and claims, the term "comprising" or its variations such as "including" or "comprises" shall be understood to include the stated elements or components without excluding other elements or other components.

[0073] In this document, the terms "first," "second," etc., are used to distinguish two different elements or parts, and are not used to define specific positions or relative relationships. In other words, in some embodiments, the terms "first," "second," etc., can also be used interchangeably.

[0074] Example 1

[0075] In order to effectively improve drawing efficiency, such as Figure 1 As shown, this embodiment of the invention provides a drawing method based on the Turtle library, including the following steps:

[0076] S11. Obtain drawing settings; the drawing settings include the number of graphics to be drawn in each row of the canvas, the coordinates of the first starting point of the first graphic to be drawn on the canvas, and the horizontal and vertical spacing between adjacent graphics to be drawn.

[0077] In order to arrange multiple graphics to be drawn in a reasonable manner on the drawing canvas, it is necessary to pre-set the number of graphics to be drawn in each row of the canvas (i.e., the number of graphics per row); as well as the coordinates of the first starting point of the first graphic to be drawn on the canvas, the horizontal spacing value between adjacent graphics to be drawn, and the vertical spacing value.

[0078] S12. Obtain the original coordinate data of each of the graphics to be drawn, wherein the original coordinate data includes X-axis data and Y-axis data;

[0079] In addition, it is necessary to obtain the original coordinate data of each graphic to be drawn; in practical applications, if the graphic is drawn based on the original coordinate data of each graphic, the graphic to be drawn may be of different sizes.

[0080] S13. Generate an X list and a Y list based on the original coordinate data of each of the graphics to be drawn; each sublist of the X list is the X-axis dataset in the original coordinate data of each of the graphics to be drawn; each sublist of the Y list is the Y-axis dataset in the original coordinate data of each of the graphics to be drawn; the sublists in the X list and the Y list correspond one-to-one, and two corresponding sublists in the X list and the Y list are the original coordinate data of the same graphics to be drawn;

[0081] To facilitate subsequent coordinate system transformation of the data, the original coordinate data needs to be preprocessed according to the corresponding storage format. In this embodiment of the invention, the original data is stored in a list format.

[0082] S14. Using the drawing settings as parameters, perform calculations and transformations on the data of each sublist in the X list and the Y list according to the preset formula, and convert the original coordinate data in the sublist into drawing coordinate data in the canvas coordinate system.

[0083] After setting the number of graphics in a single row, the coordinates of the first starting point of the first graphic to be drawn on the canvas, and the horizontal and vertical spacing between adjacent graphics to be drawn, the appropriate size and position of each graphic to be drawn after reasonable layout can be obtained (i.e., the number of rows and columns of the graphic to be drawn). In this way, according to the corresponding data conversion formula, the coordinate system can be transformed based on the original data of each graphic to be drawn, and the data values ​​of each graphic to be drawn in the canvas after reasonable layout can be generated.

[0084] In this embodiment of the invention, the method employed is to transform the X-axis data in the X list and the Y-axis data in the Y list respectively. Specific sub-steps may include:

[0085] S21. Based on the number of single-row graphics, the coordinates of the first starting point, and the horizontal and vertical spacing values, determine the uniform width and uniform height of each graphic to be drawn in the canvas.

[0086] After setting the number of single-row graphics, the coordinates of the first starting point of the first graphic to be drawn on the canvas, and the horizontal and vertical spacing between adjacent graphics to be drawn, the first thing that can be determined based on the overall size of the canvas is the uniform width (picture_width) and uniform height (picture_high) of the graphics to be drawn.

[0087] S22. According to the preset formulas: X=kx+b, and Y=k'y+b', perform preliminary calculations and transformations on the X-axis datasets in each sublist of the X list and on the Y-axis datasets in each sublist of the Y list, respectively; wherein:

[0088] The preset formula includes X=kx+b, which is used to perform calculations and transformations on the X-axis datasets in each sublist of the X list; where X is the transformed X-axis data; x is the X-axis data in the original coordinate data; k is the first scaling ratio; b is the horizontal coordinate offset; the first scaling ratio and the horizontal coordinate offset constitute a first transformation parameter combination, and the value of the first transformation parameter combination has a one-to-one correspondence with each sublist of the X list;

[0089] The calculation formula for the value of the first transformation parameter combination corresponding to the sublist in the X list includes:

[0090] The formula for calculating the value of the first scaling factor k of the nth sublist in the X list includes:

[0091] k= picture_width / (max_x[n]-min_x[n]);

[0092] Where, picture_width is the uniform width; max_x[n] is the maximum value of the X-axis data in the nth sublist of the X list; min_x[n] is the minimum value of the X-axis data in the nth sublist of the X list; n is a positive integer starting from 0;

[0093] The formula for calculating the x-coordinate offset b of the nth sublist in the X list includes:

[0094] b= (start_point_X+(n+1) * picture_width +(n-1) *pic_Distance_x)- max_x[n] * k;

[0095] Where start_point_X is the x-coordinate of the first starting point; pic_Distance_x is the horizontal spacing value;

[0096] The preset formula also includes Y=k'y+b', which is used to perform calculations and transformations on the Y-axis datasets in each sublist of the Y list; where Y is the transformed Y-axis data; y is the Y-axis data in the original coordinate data; k' is the second scaling ratio; b' is the ordinate offset; the second scaling ratio and the ordinate offset constitute the second transformation parameter combination, and the value of the second transformation parameter combination has a one-to-one correspondence with each sublist of the Y list;

[0097] The calculation formula for the value of the second transformation parameter combination corresponding to the sublist in the Y list includes:

[0098] The formula for calculating the value of the second scaling factor k' of the nth sublist in the Y list includes:

[0099] k '= picture_high / (max_y[n]-min_y[n])

[0100] Where picture_high is the uniform height; max_y[n] is the maximum value of the Y-axis data in the nth sublist of the Y list; min_y[n] is the minimum value of the Y-axis data in the nth sublist of the Y list; n is a positive integer starting from 0;

[0101] The formula for calculating the x-coordinate offset b' of the nth sublist in the Y list includes:

[0102] b = (start_point_Y+ picture_high )- max_y[n] * k

[0103] Where start_point_Y is the ordinate value of the first starting point; pic_Distance_y is the vertical spacing value;

[0104] S23. Based on the results of the preliminary calculation and transformation, generate the corresponding X' list and Y' list; each sublist of the X' list is the X-axis dataset after the preliminary calculation and transformation; each sublist of the Y' list is the Y-axis dataset after the preliminary calculation and transformation.

[0105] In this embodiment of the invention, a two-stage data conversion method is adopted. After the initial calculation conversion, the scaling conversion is performed to unify the size of each graphic to be drawn. That is, according to the layout setting, each graphic to be drawn is scaled to a suitable size. The data of all graphics to be drawn are preprocessed into a layout arranged in a single line.

[0106] S24. Perform secondary operations and transformations on the data of each sublist in the X' list and the Y' list respectively to generate the final plotting data, wherein:

[0107] The formulas for performing secondary operations on the data in each sublist of the X' list include:

[0108] X'= X - (picture_width + pic_Distance_x)*(m-1)*col_mun;

[0109] Where X' is the X-axis data used as the final drawing data; X is the X-axis data after preliminary calculation and transformation; col_mun is the number of graphics to be drawn in each row of the canvas; m is the row number of the graphics to be drawn corresponding to the sublist in the canvas;

[0110] The formulas for performing secondary operations on the data in each sublist of the Y' list include:

[0111] Y'=Y - (picture_high+pic_Distance_y)*(m-1)

[0112] Where Y' is the Y-axis data used as the final plotting data; Y' is the Y-axis data after preliminary calculation and transformation.

[0113] In this step, position offset is performed through secondary calculations, which can convert each graphic to be drawn into the final drawing data when it is in the correct row and column position, as determined by the drawing settings.

[0114] In practical applications, the specific implementation method for performing preliminary calculation conversion in this embodiment of the invention can be as follows:

[0115] The step involves performing calculations and transformations on the X-axis datasets in each sublist of the X list and the Y-axis datasets in each sublist of the Y list, according to the preset formulas: X=kx+b and Y=k'y+b', including:

[0116] Simultaneously, operations and transformations are performed on the data in each sublist of the X list and the Y list, including:

[0117] The X-axis data of each sublist in the X list are read sequentially, and the updated X-axis data of each sublist are calculated according to the first transformation parameter combination corresponding to the sublist using the preset formula: X=kx+b.

[0118] The Y-axis data of each sublist in the Y list are read sequentially, and the updated Y-axis data of each sublist are calculated according to the second transformation parameter combination corresponding to the sublist using the preset formula: Y=k'y+b'.

[0119] To facilitate establishing a one-to-one correspondence between the first conversion parameter combination and each sublist in the X list, and between the second conversion parameter combination and each sublist in the Y list, in this embodiment of the invention, both the first and second conversion parameter combinations can be stored in list form. Specifically:

[0120] Each of the first conversion parameter combinations is stored in a preset first conversion parameter list, with each list element in the first conversion parameter list being a list element; each list element in the first conversion parameter list corresponds one-to-one with each sublist in the X list;

[0121] Each of the second conversion parameter combinations is stored in a preset second conversion parameter list, with the second conversion parameter combination as a list element; each list element in the first conversion parameter list corresponds one-to-one with each sublist in the Y list.

[0122] Furthermore, in embodiments of the present invention, it may also include:

[0123] S15. Use the drawing command call in the turtle library to convert the drawing coordinate data in the canvas coordinate system and draw on the canvas.

[0124] After the final drawing data is generated, it can be stored in the turtle library. By calling the drawing commands in the turtle library, the graphics to be drawn can be drawn sequentially onto the canvas according to the layout settings.

[0125] In practical software implementation, the graphics in each row of the canvas can be drawn from bottom to top. Each completed row of graphics can be considered a loop, and the drawing of all graphics can be completed through multiple loops. A `break` command can be added to each loop to interrupt the drawing process. When the number of drawings completed in a single loop reaches a set value (i.e., the number of graphics per row), the loop is interrupted; then, the next loop continues to the next row to continue drawing until the drawing is finished. Specifically, this includes:

[0126] After calculating the updated X-axis data of a sublist in the X list and the updated Y-axis data of the sublist in the Y list corresponding to the sublist in the X list, the updated X-axis data and updated Y-axis data are called using the drawing commands in the turtle library, and the corresponding graphic to be drawn is drawn on the canvas.

[0127] When the number of the graphics to be drawn reaches an integer multiple of the number of graphics in a single row, the drawing of the current row is stopped by the break interrupt command and the drawing continues to the next row.

[0128] In summary, in this embodiment of the invention, after obtaining the original coordinate data of each graphic to be drawn, as long as the row and column arrangement of the multiple graphics to be drawn in the computer drawing software is set, the original coordinate data of the multiple graphics to be drawn can be automatically converted into drawing coordinate data in the canvas coordinate system, and each graphic to be drawn can be adjusted to be presented in the canvas with an appropriate image size.

[0129] Because of the embodiments of the present invention, when drawing multiple images on the same canvas, it is no longer necessary to invest a lot of effort in programming multiple times to match the function program of the graphics with the various parameters of the canvas in the Turtle library, thus effectively improving the drawing efficiency. Example 2

[0130] Corresponding to the method embodiment, another aspect of the present invention provides a drawing device based on the Turtle library. Figure 2 This diagram illustrates the structure of a Turtle-based drawing device according to an embodiment of the present invention. The Turtle-based drawing device is a... Figure 1 The device corresponding to the drawing method based on the Turtle library in the corresponding embodiment is implemented through a virtual device. Figure 1The drawing method based on the Turtle library in the corresponding embodiment can be executed by an electronic device, such as a network device, terminal device, or server. Specifically, the drawing device based on the Turtle library in this embodiment includes:

[0131] The setting value acquisition unit 01 is used to acquire drawing setting values; the drawing setting values ​​include the number of graphics to be drawn in each row of the canvas, the coordinates of the first starting point of the first graphic to be drawn on the canvas, the horizontal spacing value and the vertical spacing value between adjacent graphics to be drawn.

[0132] The raw data acquisition unit 02 is used to acquire the raw coordinate data of each of the graphics to be drawn, wherein the raw coordinate data includes X-axis data and Y-axis data;

[0133] The original list generation unit 03 is used to generate an X list and a Y list respectively based on the original coordinate data of each of the graphics to be drawn; each sublist of the X list is the X-axis dataset in the original coordinate data of each of the graphics to be drawn; each sublist of the Y list is the Y-axis dataset in the original coordinate data of each of the graphics to be drawn; the sublists in the X list and the Y list correspond one-to-one, and two corresponding sublists in the X list and the Y list are the original coordinate data of the same graphics to be drawn;

[0134] The data conversion unit 04 is used to perform calculations and conversions on the data of each sublist in the X list and the Y list according to the preset formula, using the drawing setting value as a parameter, to convert the original coordinate data in the sublist into drawing coordinate data in the canvas coordinate system.

[0135] Preferably, in this invention, it further includes:

[0136] The drawing unit 05 is used to draw on the canvas by converting drawing coordinate data into the canvas coordinate system using drawing commands from the turtle library.

[0137] It should be noted that the specific implementation and technical effects of the Turtle-based drawing device in the embodiments of the present invention can be found by referring to... Figure 1 The corresponding drawing methods based on the Turtle library will not be elaborated here. Example 3

[0138] Corresponding to the method embodiments, this embodiment of the invention also provides a drawing device based on the Turtle library, such as a terminal or server. The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The terminal can be a smartphone, tablet, laptop, desktop computer, etc., but is not limited to these.

[0139] Example diagrams of the hardware structure block diagrams of the graphics device based on the Turtle library provided in this application embodiment are as follows: Figure 3 As shown, it may include:

[0140] Processor 1, communication interface 2, memory 3, and communication bus 4;

[0141] The processor 1, communication interface 2, and memory 3 communicate with each other via communication bus 4.

[0142] Optionally, communication interface 2 can be an interface of a communication module, such as the interface of a GSM module;

[0143] Processor 1 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application.

[0144] Memory 3 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device.

[0145] Specifically, processor 1 is used to execute the computer program stored in memory 3 to perform the following steps:

[0146] Obtain drawing settings; the drawing settings include the number of graphics to be drawn in each row of the canvas, the coordinates of the first starting point of the first graphic to be drawn on the canvas, and the horizontal and vertical spacing between adjacent graphics to be drawn.

[0147] Obtain the original coordinate data of each of the graphics to be drawn, the original coordinate data including X-axis data and Y-axis data;

[0148] An X list and a Y list are generated based on the original coordinate data of each of the graphics to be drawn. Each sublist of the X list is the X-axis dataset of the original coordinate data of each of the graphics to be drawn. Each sublist of the Y list is the Y-axis dataset of the original coordinate data of each of the graphics to be drawn. The sublists in the X list and the Y list correspond one-to-one, and two corresponding sublists in the X list and the Y list are the original coordinate data of the same graphics to be drawn.

[0149] Using the drawing settings as parameters, the data of each sublist in the X list and the Y list are calculated and transformed according to the preset formula, so as to convert the original coordinate data in the sublist into drawing coordinate data in the canvas coordinate system.

[0150] Preferably, in this embodiment of the invention, it further includes:

[0151] The drawing commands from the turtle library are used to convert the data into drawing coordinates in the canvas coordinate system, which are then used to draw the data on the canvas.

[0152] The above-described product can execute the method provided in the embodiments of the present invention, and has the corresponding functional modules and beneficial effects for executing the method. Technical details not described in detail in this embodiment can be found in the drawing method based on the Turtle library provided in the embodiments of the present invention. Example 4

[0153] In this embodiment of the invention, a storage medium is also provided, which can store a program suitable for execution by a processor, the program being used for:

[0154] Obtain drawing settings; the drawing settings include the number of graphics to be drawn in each row of the canvas, the coordinates of the first starting point of the first graphic to be drawn on the canvas, and the horizontal and vertical spacing between adjacent graphics to be drawn.

[0155] Obtain the original coordinate data of each of the graphics to be drawn, the original coordinate data including X-axis data and Y-axis data;

[0156] An X list and a Y list are generated based on the original coordinate data of each of the graphics to be drawn. Each sublist of the X list is the X-axis dataset of the original coordinate data of each of the graphics to be drawn. Each sublist of the Y list is the Y-axis dataset of the original coordinate data of each of the graphics to be drawn. The sublists in the X list and the Y list correspond one-to-one, and two corresponding sublists in the X list and the Y list are the original coordinate data of the same graphics to be drawn.

[0157] Using the drawing settings as parameters, the data of each sublist in the X list and the Y list are calculated and transformed according to the preset formula, so as to convert the original coordinate data in the sublist into drawing coordinate data in the canvas coordinate system.

[0158] Preferably, in this embodiment of the invention, it further includes:

[0159] The drawing commands from the turtle library are used to convert the data into drawing coordinates in the canvas coordinate system, which are then used to draw the data on the canvas.

[0160] Optionally, the refined and extended functions of the program can be found in the description above.

[0161] The above-described product can execute the methods provided in the embodiments of the present invention, and has the corresponding functional modules and beneficial effects for executing the methods. Technical details not described in detail in this embodiment can be found in the methods provided in other embodiments of the present invention.

[0162] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0163] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. Furthermore, the couplings or direct couplings or communication connections shown or discussed may be indirect couplings or communication connections through interfaces, devices, or units, and may be electrical, mechanical, or other forms.

[0164] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0165] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0166] It should be understood that in the embodiments of this application, the claims, various embodiments, and features can be combined with each other to solve the aforementioned technical problems.

[0167] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0168] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A drawing method based on the Turtle library, characterized in that, Including the following steps: S11. Obtain drawing settings; the drawing settings include the number of graphics to be drawn in each row of the canvas, the coordinates of the first starting point of the first graphic to be drawn on the canvas, and the horizontal and vertical spacing between adjacent graphics to be drawn. S12. Obtain the original coordinate data of each of the graphics to be drawn; the original coordinate data includes X-axis data and Y-axis data; S13. Generate an X list and a Y list based on the original coordinate data of each of the graphics to be drawn; each sublist of the X list is the X-axis dataset in the original coordinate data of each of the graphics to be drawn; each sublist of the Y list is the Y-axis dataset in the original coordinate data of each of the graphics to be drawn; the sublists in the X list and the Y list correspond one-to-one, and two corresponding sublists in the X list and the Y list are the original coordinate data of the same graphics to be drawn; S14. Using the drawing setting value as a parameter, perform calculations and transformations on the data of each sublist in the X list and the Y list according to the preset formula, and convert the original coordinate data in the sublist into drawing coordinate data in the canvas coordinate system. S15. Use the drawing commands in the turtle library to convert the data into drawing coordinates in the canvas coordinate system and draw on the canvas. The step of using the drawing settings as parameters and performing calculations and transformations on the data of each sublist in the X list and the Y list according to preset formulas to convert the original coordinate data in the sublists into drawing coordinate data in the canvas coordinate system includes: S21. Based on the number of single-row graphics, the coordinates of the first starting point, and the horizontal and vertical spacing values, determine the uniform width and uniform height of each graphic to be drawn in the canvas. S22. According to the preset formulas: X=kx+b, and Y=k'y+b', perform preliminary calculations and transformations on the X-axis datasets in each sublist of the X list and on the Y-axis datasets in each sublist of the Y list, respectively; wherein: The preset formula includes X=kx+b, which is used to perform calculations and transformations on the X-axis datasets in each sublist of the X list; where X is the transformed X-axis data; x is the X-axis data in the original coordinate data; k is the first scaling ratio; b is the horizontal coordinate offset; the first scaling ratio and the horizontal coordinate offset constitute a first transformation parameter combination, and the value of the first transformation parameter combination has a one-to-one correspondence with each sublist of the X list; The calculation formula for the value of the first transformation parameter combination corresponding to the sublist in the X list includes: The formula for calculating the value of the first scaling factor k of the nth sublist in the X list includes: k= picture_width / (max_x[n]-min_x[n]); Where, picture_width is the uniform width; max_x[n] is the maximum value of the X-axis data in the nth sublist of the X list; min_x[n] is the minimum value of the X-axis data in the nth sublist of the X list; n is a positive integer starting from 0; The formula for calculating the x-coordinate offset b of the nth sublist in the X list includes: b= (start_point_X+(n+1) * picture_width +(n-1) *pic_Distance_x)- max_x[n]* k; Where start_point_X is the x-coordinate of the first starting point; pic_Distance_x is the horizontal spacing value; The preset formula also includes Y=k'y+b', which is used to perform calculations and transformations on the Y-axis datasets in each sublist of the Y list; where Y is the transformed Y-axis data; y is the Y-axis data in the original coordinate data; k' is the second scaling ratio; b' is the ordinate offset; the second scaling ratio and the ordinate offset constitute the second transformation parameter combination, and the value of the second transformation parameter combination has a one-to-one correspondence with each sublist of the Y list; The calculation formula for the value of the second transformation parameter combination corresponding to the sublist in the Y list includes: The formula for calculating the value of the second scaling factor k' of the nth sublist in the Y list includes: k '= picture_high / (max_y[n]-min_y[n]) Where picture_high is the uniform height; max_y[n] is the maximum value of the Y-axis data in the nth sublist of the Y list; min_y[n] is the minimum value of the Y-axis data in the nth sublist of the Y list; n is a positive integer starting from 0; The formula for calculating the x-coordinate offset b' of the nth sublist in the Y list includes: b = (start_point_Y+ picture_high )- max_y[n] * k Where start_point_Y is the ordinate value of the first starting point; pic_Distance_y is the vertical spacing value; S23. Based on the results of the preliminary calculation and transformation, generate the corresponding X' list and Y' list; each sublist of the X' list is the X-axis dataset after the preliminary calculation and transformation; each sublist of the Y' list is the Y-axis dataset after the preliminary calculation and transformation. S24. Perform secondary operations and transformations on the data of each sublist in the X' list and the Y' list respectively to generate the final plotting data, wherein: The formulas for performing secondary operations on the data in each sublist of the X' list include: X'= X - (picture_width + pic_Distance_x)*(m-1)*col_mun; Where X' is the X-axis data used as the final drawing data; X is the X-axis data after preliminary calculation and transformation; col_mun is the number of graphics to be drawn in each row of the canvas; m is the row number of the graphics to be drawn corresponding to the sublist in the canvas; The formulas for performing secondary operations on the data in each sublist of the Y' list include: Y'=Y - (picture_high+pic_Distance_y)*(m-1) Where Y' is the Y-axis data used as the final plotting data; Y' is the Y-axis data after preliminary calculation and transformation.

2. The drawing method based on the Turtle library according to claim 1, characterized in that, The step involves performing preliminary calculations and transformations on the X-axis datasets in each sublist of the X list and the Y-axis datasets in each sublist of the Y list, based on the preset formulas: X=kx+b and Y=k'y+b'. This includes: Simultaneously, operations and transformations are performed on the data in each sublist of the X list and the Y list, including: The X-axis data of each sublist in the X list are read sequentially, and the updated X-axis data of each sublist are calculated according to the first transformation parameter combination corresponding to the sublist using the preset formula: X=kx+b. The Y-axis data of each sublist in the Y list are read sequentially, and the updated Y-axis data of each sublist are calculated according to the second transformation parameter combination corresponding to the sublist using the preset formula: Y=k'y+b'.

3. The drawing method based on the Turtle library according to claim 1, characterized in that, include: Each of the first conversion parameter combinations is stored in a preset first conversion parameter list, with the first conversion parameter combination as a list element. Each list element in the first conversion parameter list corresponds one-to-one with each sublist in the X list; Each of the second conversion parameter combinations is stored in a preset second conversion parameter list, using the second conversion parameter combination as a list element. Each list element in the first conversion parameter list corresponds one-to-one with each sublist in the Y list.

4. The drawing method based on the Turtle library according to claim 3, characterized in that, The step of using drawing commands from the turtle library to convert data into drawing coordinates in the canvas coordinate system and then drawing on the canvas includes: After calculating the updated X-axis data of a sublist in the X list and the updated Y-axis data of the sublist in the Y list corresponding to the sublist in the X list, the updated X-axis data and updated Y-axis data are called using the drawing commands in the turtle library, and the corresponding graphic to be drawn is drawn on the canvas. When the number of the graphics to be drawn reaches an integer multiple of the number of graphics in a single row, the drawing of the current row is stopped by the break interrupt command and the drawing continues to the next row.

5. A drawing apparatus based on the Turtle library, used to implement the drawing method based on the Turtle library as described in any one of claims 1-4, characterized in that, include: The setting value acquisition unit is used to acquire drawing setting values; the drawing setting values ​​include the number of graphics to be drawn in each row of the canvas, the coordinates of the first starting point of the first graphic to be drawn on the canvas, the horizontal spacing value and the vertical spacing value between adjacent graphics to be drawn. The raw data acquisition unit is used to acquire the raw coordinate data of each of the graphics to be drawn; the raw coordinate data includes X-axis data and Y-axis data; The original list generation unit is used to generate an X list and a Y list respectively based on the original coordinate data of each of the graphics to be drawn; each sublist of the X list is the X-axis dataset in the original coordinate data of each of the graphics to be drawn; each sublist of the Y list is the Y-axis dataset in the original coordinate data of each of the graphics to be drawn; the sublists in the X list and the Y list correspond one-to-one, and two corresponding sublists in the X list and the Y list are the original coordinate data of the same graphics to be drawn; The data conversion unit is used to perform calculations and conversions on the data of each sublist in the X list and the Y list according to a preset formula, using the drawing setting value as a parameter, to convert the original coordinate data in the sublist into drawing coordinate data in the canvas coordinate system.

6. The drawing device based on the Turtle library according to claim 5, characterized in that, Also includes: The drawing unit is used to draw on the canvas by converting drawing coordinate data into the canvas coordinate system using drawing command calls from the turtle library.

7. A drawing device based on the Turtle library, characterized in that, include: Memory, used to store computer programs; A processor for invoking and executing the computer program to implement the steps of the drawing method based on the Turtle library as described in any one of claims 1-4.

8. A storage medium, characterized in that, Includes a software program adapted for a processor to perform the steps of the drawing method based on the Turtle library as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Method and devicefor converting a path coordinate graph, storage medium and apparatus

    CN109242929A

  • Graphics drawing method, device, electronic device and storage medium

    CN109254976A