Spaces:
Running on CPU Upgrade

ziem-io commited on
Commit
d39782f
·
1 Parent(s): be1d31d

Docs: Comments

Browse files
Files changed (2) hide show
  1. lib/wheel.py +12 -8
  2. whisky-wheel.code-workspace +8 -0
lib/wheel.py CHANGED
@@ -1,8 +1,10 @@
 
1
  from typing import List, Tuple
2
  import math
3
 
4
  ###################################################################################
5
 
 
6
  SVG_BASE = """
7
  <svg id="wheel"
8
  viewBox="0 0 500 500"
@@ -89,17 +91,17 @@ def compute_wheel_points(
89
  center: float = 250.0,
90
  input_ratio: float = 40.0,
91
  ) -> List[Tuple[float, float]]:
92
- """
93
- Repliziert die JS-Logik:
94
- angle = (360/segments*i + offsetAngle - 90) * (π*2/360)
95
- r = vals[i] * inputRatio + innerRadius
96
- x = cos(angle) * r + center
97
- y = sin(angle) * r + center
98
- """
99
  pts = []
100
  for i, v in enumerate(vals):
 
101
  angle_deg = (360.0 / segments) * i + offset_angle_deg - 90.0
102
  angle = angle_deg * (math.pi * 2.0 / 360.0)
 
103
  r = v * input_ratio + inner_radius
104
  x = math.cos(angle) * r + center
105
  y = math.sin(angle) * r + center
@@ -117,6 +119,7 @@ def build_svg_with_values(
117
  center: float = 250.0,
118
  input_ratio: float = 40.0,
119
  ) -> str:
 
120
  pts = compute_wheel_points(
121
  vals,
122
  segments=segments,
@@ -125,7 +128,8 @@ def build_svg_with_values(
125
  center=center,
126
  input_ratio=input_ratio,
127
  )
 
128
  points_attr = " ".join(f"{x:.2f},{y:.2f}" for x, y in pts)
129
 
130
  return SVG_BASE.format(POINTS=points_attr)
131
-
 
1
+ # Utilities for constructing the whisky flavor wheel SVG.
2
  from typing import List, Tuple
3
  import math
4
 
5
  ###################################################################################
6
 
7
+ # Base SVG template with placeholder for the dynamic graph coordinates.
8
  SVG_BASE = """
9
  <svg id="wheel"
10
  viewBox="0 0 500 500"
 
91
  center: float = 250.0,
92
  input_ratio: float = 40.0,
93
  ) -> List[Tuple[float, float]]:
94
+ # Repliziert die JS-Logik:
95
+ # angle = (360/segments*i + offsetAngle - 90) * (π*2/360)
96
+ # r = vals[i] * inputRatio + innerRadius
97
+ # x = cos(angle) * r + center
98
+ # y = sin(angle) * r + center
 
 
99
  pts = []
100
  for i, v in enumerate(vals):
101
+ # Align each segment by converting the polar angle to radians and shifting upwards.
102
  angle_deg = (360.0 / segments) * i + offset_angle_deg - 90.0
103
  angle = angle_deg * (math.pi * 2.0 / 360.0)
104
+ # Map the normalized input value onto the wheel radius and translate back to SVG center.
105
  r = v * input_ratio + inner_radius
106
  x = math.cos(angle) * r + center
107
  y = math.sin(angle) * r + center
 
119
  center: float = 250.0,
120
  input_ratio: float = 40.0,
121
  ) -> str:
122
+ # Populate the SVG template with cartesian points generated from the input values.
123
  pts = compute_wheel_points(
124
  vals,
125
  segments=segments,
 
128
  center=center,
129
  input_ratio=input_ratio,
130
  )
131
+ # Build the `points` attribute string in the format expected by the SVG polyline element.
132
  points_attr = " ".join(f"{x:.2f},{y:.2f}" for x, y in pts)
133
 
134
  return SVG_BASE.format(POINTS=points_attr)
135
+
whisky-wheel.code-workspace ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "folders": [
3
+ {
4
+ "path": "."
5
+ }
6
+ ],
7
+ "settings": {}
8
+ }