Compare commits

...

2 Commits

Author SHA1 Message Date
Thomas Naber f6cfe7235a Checkpoint 2
Writingthe code for this wasn't terribly difficult once I figured out
what i needed to do. I didn't quite understand the purpose of each
function in the context of the overall program, which made the scale
function difficult to write at first. When I did get stuck I used the
already existing code as well as the examples in the lab to help me
figure out what I needed to write.
2023-08-03 16:41:13 -04:00
Thomas Naber 8e57a173bb Checkpoint 1
I think I would be able to make the axes and the evenly spaced
tick marks. I don't know how to use the x and y values from the
list yet so I don't think I'd be able to make the labels or plot
the points on the scatter plot.
2023-07-31 11:24:41 -04:00
4 changed files with 74 additions and 26 deletions

View File

@ -4,9 +4,28 @@
- Draw the axes. - Draw the axes.
- Draw the x-axis. - Draw the x-axis.
- Draw the line. - Draw the line.
- ... - Find the range of the x-values
- Divide the range by 5
- Start at the origin. Label it with the lowest x-value
- repeat until at the end of the axis:
- add 1/5 of the range to the x-value
- move to the right 1/5 of the length of the axis
- draw a tick mark and label with the next x-value
- Draw the y-axis. - Draw the y-axis.
- Draw the line. - Draw the line.
- ... - Find the range of the y-values
- Divide the range by 5
- Start at the origin. Label it with the lowest y-value
- repeat until at the end of the axis:
- add 1/5 of the range to the y-value
- move up 1/5 of the length of the axis
- draw a tick mark and label with the next y-value
- Plot the points. - Plot the points.
- ... - Repeat for each point:
- Start with turtle at the "origin"
- move to the right the amount of the difference between the x-value and the lowest x- value
- move up the amount of the difference between the y-value and the lowest y-value
- plot the point
- return to the "origin"

6
poetry.lock generated
View File

@ -342,13 +342,13 @@ files = [
[[package]] [[package]]
name = "sphinx" name = "sphinx"
version = "7.1.1" version = "7.1.2"
description = "Python documentation generator" description = "Python documentation generator"
optional = false optional = false
python-versions = ">=3.8" python-versions = ">=3.8"
files = [ files = [
{file = "sphinx-7.1.1-py3-none-any.whl", hash = "sha256:4e6c5ea477afa0fb90815210fd1312012e1d7542589ab251ac9b53b7c0751bce"}, {file = "sphinx-7.1.2-py3-none-any.whl", hash = "sha256:d170a81825b2fcacb6dfd5a0d7f578a053e45d3f2b153fecc948c37344eb4cbe"},
{file = "sphinx-7.1.1.tar.gz", hash = "sha256:59b8e391f0768a96cd233e8300fe7f0a8dc2f64f83dc2a54336a9a84f428ff4e"}, {file = "sphinx-7.1.2.tar.gz", hash = "sha256:780f4d32f1d7d1126576e0e5ecc19dc32ab76cd24e950228dcf7b1f6d3d9e22f"},
] ]
[package.dependencies] [package.dependencies]

View File

@ -21,14 +21,14 @@ test(minimum, [[0, 1, 2, 3]], 0)
test(minimum, [[-10, -20, -30]], -30) test(minimum, [[-10, -20, -30]], -30)
test(bounds, [[0, 1, 2, 3]], [0, 3]) test(bounds, [[0, 1, 2, 3]], [0, 3])
test(bounds, [[-10, -20, -30]], [-30, -10]) test(bounds, [[-10, -20, -30]], [-30, -10])
test(clamp, [[10, 0, 100]], 10) test(clamp, [10, 0, 100], 10)
test(clamp, [[-10, 0, 100]], 0) test(clamp, [-10, 0, 100], 0)
test(clamp, [[104, 0, 100]], 100) test(clamp, [104, 0, 100], 100)
test(ratio, [[5, 0, 10]], 0.5) test(ratio, [5, 0, 10], 0.5)
test(ratio, [[167, 100, 200]], 0.67) test(ratio, [167, 100, 200], 0.67)
test(ratio, [[8, 10, 0]], 0.2) test(ratio, [8, 10, 0], 0.2)
test(ratio, [[4, 10, 20]], 0.0) test(ratio, [4, 10, 20], 0.0)
test(scale, [[4, 0, 10, 0, 100]], 40) test(scale, [4, 0, 10, 0, 100], 40)
test(scale, [[180, 120, 240, 0, 100]], 50) test(scale, [180, 120, 240, 0, 100], 50)
test(get_x_values, [[[0, 5], [1, 5], [2, 5]]], [0, 1, 2]) test(get_x_values, [[[0, 5], [1, 5], [2, 5]]], [0, 1, 2])
test(get_y_values, [[[0, 5], [1, 5], [2, 5]]], [5, 5, 5]) test(get_y_values, [[[0, 5], [1, 5], [2, 5]]], [5, 5, 5])

View File

@ -6,38 +6,67 @@
def maximum(data): def maximum(data):
"Returns the largest number in data" "Returns the largest number in data"
raise NotImplementedError highest = None
for number in data:
if highest is None:
highest = number
if number > highest:
highest = number
return highest
def minimum(data): def minimum(data):
"Returns the smallest number in data" "Returns the smallest number in data"
raise NotImplementedError lowest = None
for number in data:
if lowest is None:
lowest = number
if number < lowest:
lowest = number
return lowest
def bounds(data): def bounds(data):
"Returns a list of the smallest and largest numbers in data" "Returns a list of the smallest and largest numbers in data"
raise NotImplementedError min = minimum(data)
max = maximum(data)
bounds = [min, max]
return bounds
def clamp(value, low, high): def clamp(value, low, high):
"""Clamps a value to a range from low to high. """Clamps a value to a range from low to high.
Returns value if it is between low and high. Returns value if it is between low and high.
If value is lower than low, returns low. If value is higher than high, returns high. If value is lower than low, returns low. If value is higher than high, returns high.
""" """
raise NotImplementedError if value < low:
return low
elif value > high:
return high
else:
return value
def ratio(value, start, end): def ratio(value, start, end):
"""Returns a number from 0.0 to 1.0, representing how far along value is from start to end. """Returns a number from 0.0 to 1.0, representing how far along value is
The return value is clamped to [0, 1], so even if value is lower than start, the return from start to end.The return value is clamped to [0, 1], so even if value
value will not be lower than 0.0. is lower than start, the return value will not be lower than 0.0.
""" """
raise NotImplementedError number = ((value - start)/(end - start))
number = clamp(number, 0.0, 1.0)
return number
def scale(value, domain_min, domain_max, range_min, range_max): def scale(value, domain_min, domain_max, range_min, range_max):
"Given a value within a domain, returns the scaled equivalent within range." "Given a value within a domain, returns the scaled equivalent within range."
raise NotImplementedError r = ratio(value, domain_min, domain_max)
return range_min + r*(range_max - range_min)
def get_x_values(points): def get_x_values(points):
"Returns the first value for each point in points." "Returns the first value for each point in points."
raise NotImplementedError x_list = []
for data in points:
x_list.append(data[0])
return x_list
def get_y_values(points): def get_y_values(points):
"Returns the second value for each point in points." "Returns the second value for each point in points."
raise NotImplementedError y_list = []
for data in points:
y_list.append(data[1])
return y_list