แก้ไข 0.01
กราฟ Glyth เป็นแพ็คเกจ Python โอเพนซอร์ซสำหรับการทำกราฟสมการลงบนอาร์เรย์ 2 มิติ (ชื่อว่า The Canvas ) พร้อมอาร์กิวเมนต์ที่หลากหลายเพื่อวาดภายในช่วงที่เฉพาะเจาะจงและถูกผูกไว้ ปรับสัดส่วนความกว้างและความสูงของ ผืนผ้าใบ ตามสัดส่วน
-เมื่อแนบตัวสร้างกับวัตถุอาร์เรย์ 2D ที่มีขนาด ความละเอียด ที่ประกาศจะเต็มไปด้วย blank_glyth ที่เลือกไว้ชื่อ ผืนผ้าใบ
แพ็คเกจทำงานบนค่าการแมประหว่าง X และ F (x) จากสมการกราฟไปยังความละเอียดที่กำหนดของผืนผ้าใบแปลพิกัดด้วยปัจจัยการปรับขนาดที่ไม่สม่ำเสมอเพื่อวาด Glyth โดยดัชนี 2D

ในช่วง ตั้งแต่ และช่วง ถึง ตามลำดับภูมิภาค X-Axis ที่กำหนดของสมการที่จะวาด

ในกรณีที่ค่าสูงสุดและขั้นต่ำเป็นตามลำดับค่าสูงสุดที่คำนวณได้ (หรือให้) ค่าสูงสุดและขั้นต่ำแกน y สำหรับสมการภายในภูมิภาคแกน x
The constructor of the class to create an attached object, setup the canvas array with the arguements given, both the size and blank (background) glyth
- resolution: the width by the height of the canvas measured in character glyths | 'x'.join([width, height])
- blank_glyth: the background glyth used for spacing the graph
Format the graph equation such that all unecessary characters are removed to be processed, this includes removal of 'y' and '=' if given an equation to form an expression and all ' ' (spaces) present
- equation: the mathematical equation of the graph going to be drawn
Calculate the upper and lower bounds in the y-axis of a graph equation between the given x-axis range, to be used later for mapping positions
- equation: the mathematical equation of the graph going to be drawn
- x_range: a tuple of the x-axis range between which the graph will be used, all outside this is unnecessary
Draw a glyth onto the canvas array dependent on given arguments in relation to the graph equation, including the x-axis range and y-axis bounds of the 2-dimensional section of the graph and character position along the canvas
- char_x: the x_axis glyth position of the canvas, such that it starts to the leftmost position (0) to the rightmost (canvas width - 1) | 0 <= char_x < canvas width
- equation: the mathematical equation of the graph going to be drawn
- glyth: the character/s to be drawn onto the canvas at the calculated coordinate relative to the graph equation
- x_range: a tuple of the x-axis range between which the graph will be used, all outside this is unnecessary | (range_from, range_to)
- y_bounds: a tuple of the y-axis bounds for the x-axis region of the graph, including both the minimum and maximum values | (min, max)
Clear the canvas by replacing all indicies in the array with the blank glyth assigned in the constructor, removing any graphs drawn
Pretty print the canvas array into equal rows of the set width with newline character moving to the next row, as each index is printed incrementally
- clear: a boolean value (either True or False) whether to clear the each canvas array index after printing the index | True or False
from glyth_graph import graph_basic
from random import choice
character_set = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/'
print ( '---Glyth Graph---' )
print ( ' n ---Resolution---' )
width = int ( input ( 'Width (chars): ' ))
height = int ( input ( 'Height (chars): ' ))
glyth_graph = graph_basic (
resolution = 'x' . join ([ str ( width ), str ( height )]),
blank_glyth = ' '
)
while True :
print ( ' n ---Graph Properties---' )
equation = glyth_graph . format_equation ( input ( 'Equation: ' ))
range_from , range_to = int ( input ( 'x-axis From: ' )), int ( input ( 'x-axis To: ' ))
print ()
bounds = glyth_graph . y_bounds (
equation = equation ,
x_range = ( range_from , range_to )
)
for char_x in range ( 0 , width ):
glyth_graph . draw_graph (
char_x = char_x ,
equation = equation ,
glyth = choice ( character_set ),
x_range = ( range_from , range_to ),
y_bounds = bounds
)
glyth_graph . print_canvas ()
ตัวอย่างของเอาต์พุตไปยังโปรแกรมซึ่งอาจแตกต่างกันไปตามค่าที่กำหนดเองสำหรับอินพุตที่กำหนดทั้งหมดพิมพ์อาร์เรย์ Canvas:
---Glyth Graph---
---Resolution---
Width (chars): 100
Height (chars): 30
Width: 100 | Height: 30
---Graph Properties---
Equation: y = math.sin(x)
x-axis From: 0
x-axis To: 6.283185
LbvwLB+K
Rp8 49D
MB FgW
Kt O
i6 +w
t f
z LZ
k7 q
9 q
Y G
3 yP
r c
9 h
C 4
f K
l M oe
o 7
y n
O e
tf 0
M u
r O
I lv
o8 w
L A
Q2 uO
w LD
zvu 8x
nGl xMw
XsohPTDx
| การอนุญาต | เงื่อนไข | ข้อ จำกัด |
|---|---|---|
| การใช้งานเชิงพาณิชย์ | ใบอนุญาตและประกาศลิขสิทธิ์ | ความรับผิดชอบ |
| การกระจาย | การรับประกัน | |
| การปรับเปลี่ยน | ||
| การใช้งานส่วนตัว |
MIT License
Copyright (c) 2021 Ivan (GitHub: ivanl-exe, E-Mail: [email protected])
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.