phg-vis 1.3.0__tar.gz → 1.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {phg_vis-1.3.0/phg_vis.egg-info → phg_vis-1.3.2}/PKG-INFO +124 -8
  2. {phg_vis-1.3.0 → phg_vis-1.3.2}/README.md +123 -7
  3. phg_vis-1.3.2/phg/__init__.py +329 -0
  4. phg_vis-1.3.2/phg/pipe_string_phg.py +411 -0
  5. phg_vis-1.3.2/phg/vis/vis.ini +4 -0
  6. {phg_vis-1.3.0 → phg_vis-1.3.2/phg_vis.egg-info}/PKG-INFO +124 -8
  7. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg_vis.egg-info/SOURCES.txt +1 -0
  8. {phg_vis-1.3.0 → phg_vis-1.3.2}/setup.py +1 -1
  9. phg_vis-1.3.0/phg/__init__.py +0 -82
  10. phg_vis-1.3.0/phg/vis/vis.ini +0 -4
  11. {phg_vis-1.3.0 → phg_vis-1.3.2}/LICENSE +0 -0
  12. {phg_vis-1.3.0 → phg_vis-1.3.2}/MANIFEST.in +0 -0
  13. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg/phg_to_shader.py +0 -0
  14. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg/shader_render.py +0 -0
  15. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg/vis/GCU.dll +0 -0
  16. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg/vis/dragpad.exe +0 -0
  17. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg/vis/dragpad_config.ini +0 -0
  18. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg/vis/freeglut.dll +0 -0
  19. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg/vis/imgui/main.lua +0 -0
  20. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg/vis/lua.dll +0 -0
  21. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg/vis/script.phg +0 -0
  22. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg/vis/sqlite3.dll +0 -0
  23. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg/vis/vis.exe +0 -0
  24. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg/vis/zlib1.dll +0 -0
  25. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg/visphg.py +0 -0
  26. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg_vis.egg-info/dependency_links.txt +0 -0
  27. {phg_vis-1.3.0 → phg_vis-1.3.2}/phg_vis.egg-info/top_level.txt +0 -0
  28. {phg_vis-1.3.0 → phg_vis-1.3.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: phg_vis
3
- Version: 1.3.0
3
+ Version: 1.3.2
4
4
  Summary: A package for the PHG modeling language and 3D visualization tool.
5
5
  Home-page: https://github.com/panguojun/Coordinate-System
6
6
  Author: romeosoft
@@ -13,20 +13,21 @@ Requires-Python: >=3.8
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
15
 
16
- # PHG - Minimalist 3D Modeling Language
16
+ # PHG - Python Hypergraphics Library
17
17
 
18
- PHG (Bacteriophage) is a specialized modeling language for describing 3D scene node trees. Combining concepts from group theory, it provides custom overloading capabilities for variables and operations, making it particularly suitable for describing complex 3D scenes and 2D sprite structures.
18
+ PHG (Python Hypergraphics) is a powerful 3D modeling and visualization library that combines a minimalist modeling language with Python integration. It provides procedural 3D scene generation, shader-based rendering, and specialized pipe system visualization.
19
19
 
20
20
  ---
21
21
 
22
22
  ## 🌟 Features
23
23
 
24
- - **Minimalist Syntax** - Declarative node tree description
24
+ - **Minimalist Syntax** - Declarative node tree description for 3D scenes
25
25
  - **Hierarchical Modeling** - Support for nested nodes and transform inheritance
26
26
  - **Parametric Design** - Flexible property system and function definitions
27
- - **Topological Structures** - Two organization methods: sequence and array composition
28
- - **Visualization Rendering** - Powerful offscreen rendering and screenshot capabilities
29
- - **Python Integration** - Convenient Python API
27
+ - **Pipe Visualization** - Specialized system for visualizing pipe structures with world/local coordinate support
28
+ - **Shader Conversion** - Convert PHG scripts to GLSL shaders for GPU rendering
29
+ - **Dual Rendering Modes** - Both real-time visualization (vis.exe) and offscreen rendering
30
+ - **Python Integration** - Comprehensive Python API for all features
30
31
 
31
32
  ---
32
33
 
@@ -402,6 +403,122 @@ for size in [5, 10, 15, 20]:
402
403
 
403
404
  ---
404
405
 
406
+ ## 🔧 Pipe Visualization System
407
+
408
+ PHG includes a specialized pipe visualization system for creating 3D pipe structures from simple string commands.
409
+
410
+ ### Pipe String Commands
411
+
412
+ - **F** - Forward (move forward in current direction)
413
+ - **B** - Back (move backward in current direction)
414
+ - **R** - Right (turn right and move)
415
+ - **L** - Left (turn left and move)
416
+ - **U** - Up (turn up and move)
417
+ - **D** - Down (turn down and move)
418
+
419
+ ### World Coordinate System
420
+
421
+ World coordinate pipes use absolute directions regardless of current orientation:
422
+
423
+ ```python
424
+ import phg
425
+ from coordinate_system import vec3, quat, coord3
426
+
427
+ # Create a pipe in world coordinates
428
+ # F moves along world Z+, R moves along world X+, etc.
429
+ start_pos = coord3(vec3(0, 0, 0), quat(1, 0, 0, 0))
430
+ phg_script = phg.world_pipestr_vis("FFRRUD", start_pos)
431
+
432
+ # Custom pipe appearance
433
+ phg.world_pipestr_vis(
434
+ "FFLLUU",
435
+ start_pos,
436
+ pipe_color=(255, 100, 50), # Orange pipe
437
+ pipe_radius=0.5 # Thicker pipe
438
+ )
439
+ ```
440
+
441
+ ### Local Coordinate System
442
+
443
+ Local coordinate pipes use directions relative to current orientation:
444
+
445
+ ```python
446
+ import phg
447
+ from coordinate_system import vec3, quat, coord3
448
+
449
+ # Create a pipe in local coordinates
450
+ # F moves forward relative to current orientation
451
+ start_pos = coord3(vec3(0, 0, 0), quat(1, 0, 0, 0))
452
+ phg_script = phg.local_pipestr_vis("FFRRUD", start_pos)
453
+
454
+ # The same string produces different results in local vs world coordinates
455
+ phg.local_pipestr_vis(
456
+ "FFRRFF", # Forward, Forward, Right turn, Right turn, Forward, Forward
457
+ start_pos,
458
+ pipe_color=(0, 255, 100) # Green pipe
459
+ )
460
+ ```
461
+
462
+ ### Direct PHG Script Generation
463
+
464
+ For advanced use cases, you can generate PHG scripts without immediate visualization:
465
+
466
+ ```python
467
+ import phg
468
+ from coordinate_system import vec3, quat, coord3
469
+
470
+ start = coord3(vec3(5, 0, 0), quat(1, 0, 0, 0))
471
+
472
+ # Generate PHG script for world coordinates
473
+ world_phg = phg.world_pipe_to_phg("FFRUD", start)
474
+
475
+ # Generate PHG script for local coordinates
476
+ local_phg = phg.local_pipe_to_phg("FFRUD", start)
477
+
478
+ # Visualize later
479
+ phg.vis(world_phg)
480
+ ```
481
+
482
+ ### Example: Complex Pipe System
483
+
484
+ ```python
485
+ import phg
486
+ from coordinate_system import vec3, quat, coord3
487
+
488
+ # Create a complex pipe network
489
+ def create_pipe_network():
490
+ # Main pipeline
491
+ main_pipe = phg.world_pipestr_vis(
492
+ "FFFFRRFFRRUUFFLLFF",
493
+ coord3(vec3(0, 0, 0), quat(1, 0, 0, 0)),
494
+ pipe_color=(100, 100, 255),
495
+ pipe_radius=0.5
496
+ )
497
+
498
+ # Branch 1
499
+ branch1 = phg.world_pipestr_vis(
500
+ "RRUUFFFF",
501
+ coord3(vec3(4, 0, 0), quat(1, 0, 0, 0)),
502
+ pipe_color=(255, 100, 100),
503
+ pipe_radius=0.3
504
+ )
505
+
506
+ # Branch 2
507
+ branch2 = phg.local_pipestr_vis(
508
+ "FFLLDDFF",
509
+ coord3(vec3(8, 2, 2), quat(1, 0, 0, 0)),
510
+ pipe_color=(100, 255, 100),
511
+ pipe_radius=0.3
512
+ )
513
+
514
+ return main_pipe, branch1, branch2
515
+
516
+ # Create and visualize the network
517
+ pipes = create_pipe_network()
518
+ ```
519
+
520
+ ---
521
+
405
522
  ## 💡 Complete Examples
406
523
 
407
524
  ### Example 1: Simple Geometry
@@ -581,7 +698,6 @@ Recommended maximum resolution is **4096 x 4096**. Excessively large resolutions
581
698
  ## 🔗 Links
582
699
 
583
700
  - [PyPI Package](https://pypi.org/project/phg/)
584
- - [Official Documentation](https://your.documentation.link)
585
701
  - [Mathematical Foundation](https://github.com/panguojun/Coordinate-System)
586
702
 
587
703
  ---
@@ -1,17 +1,18 @@
1
- # PHG - Minimalist 3D Modeling Language
1
+ # PHG - Python Hypergraphics Library
2
2
 
3
- PHG (Bacteriophage) is a specialized modeling language for describing 3D scene node trees. Combining concepts from group theory, it provides custom overloading capabilities for variables and operations, making it particularly suitable for describing complex 3D scenes and 2D sprite structures.
3
+ PHG (Python Hypergraphics) is a powerful 3D modeling and visualization library that combines a minimalist modeling language with Python integration. It provides procedural 3D scene generation, shader-based rendering, and specialized pipe system visualization.
4
4
 
5
5
  ---
6
6
 
7
7
  ## 🌟 Features
8
8
 
9
- - **Minimalist Syntax** - Declarative node tree description
9
+ - **Minimalist Syntax** - Declarative node tree description for 3D scenes
10
10
  - **Hierarchical Modeling** - Support for nested nodes and transform inheritance
11
11
  - **Parametric Design** - Flexible property system and function definitions
12
- - **Topological Structures** - Two organization methods: sequence and array composition
13
- - **Visualization Rendering** - Powerful offscreen rendering and screenshot capabilities
14
- - **Python Integration** - Convenient Python API
12
+ - **Pipe Visualization** - Specialized system for visualizing pipe structures with world/local coordinate support
13
+ - **Shader Conversion** - Convert PHG scripts to GLSL shaders for GPU rendering
14
+ - **Dual Rendering Modes** - Both real-time visualization (vis.exe) and offscreen rendering
15
+ - **Python Integration** - Comprehensive Python API for all features
15
16
 
16
17
  ---
17
18
 
@@ -387,6 +388,122 @@ for size in [5, 10, 15, 20]:
387
388
 
388
389
  ---
389
390
 
391
+ ## 🔧 Pipe Visualization System
392
+
393
+ PHG includes a specialized pipe visualization system for creating 3D pipe structures from simple string commands.
394
+
395
+ ### Pipe String Commands
396
+
397
+ - **F** - Forward (move forward in current direction)
398
+ - **B** - Back (move backward in current direction)
399
+ - **R** - Right (turn right and move)
400
+ - **L** - Left (turn left and move)
401
+ - **U** - Up (turn up and move)
402
+ - **D** - Down (turn down and move)
403
+
404
+ ### World Coordinate System
405
+
406
+ World coordinate pipes use absolute directions regardless of current orientation:
407
+
408
+ ```python
409
+ import phg
410
+ from coordinate_system import vec3, quat, coord3
411
+
412
+ # Create a pipe in world coordinates
413
+ # F moves along world Z+, R moves along world X+, etc.
414
+ start_pos = coord3(vec3(0, 0, 0), quat(1, 0, 0, 0))
415
+ phg_script = phg.world_pipestr_vis("FFRRUD", start_pos)
416
+
417
+ # Custom pipe appearance
418
+ phg.world_pipestr_vis(
419
+ "FFLLUU",
420
+ start_pos,
421
+ pipe_color=(255, 100, 50), # Orange pipe
422
+ pipe_radius=0.5 # Thicker pipe
423
+ )
424
+ ```
425
+
426
+ ### Local Coordinate System
427
+
428
+ Local coordinate pipes use directions relative to current orientation:
429
+
430
+ ```python
431
+ import phg
432
+ from coordinate_system import vec3, quat, coord3
433
+
434
+ # Create a pipe in local coordinates
435
+ # F moves forward relative to current orientation
436
+ start_pos = coord3(vec3(0, 0, 0), quat(1, 0, 0, 0))
437
+ phg_script = phg.local_pipestr_vis("FFRRUD", start_pos)
438
+
439
+ # The same string produces different results in local vs world coordinates
440
+ phg.local_pipestr_vis(
441
+ "FFRRFF", # Forward, Forward, Right turn, Right turn, Forward, Forward
442
+ start_pos,
443
+ pipe_color=(0, 255, 100) # Green pipe
444
+ )
445
+ ```
446
+
447
+ ### Direct PHG Script Generation
448
+
449
+ For advanced use cases, you can generate PHG scripts without immediate visualization:
450
+
451
+ ```python
452
+ import phg
453
+ from coordinate_system import vec3, quat, coord3
454
+
455
+ start = coord3(vec3(5, 0, 0), quat(1, 0, 0, 0))
456
+
457
+ # Generate PHG script for world coordinates
458
+ world_phg = phg.world_pipe_to_phg("FFRUD", start)
459
+
460
+ # Generate PHG script for local coordinates
461
+ local_phg = phg.local_pipe_to_phg("FFRUD", start)
462
+
463
+ # Visualize later
464
+ phg.vis(world_phg)
465
+ ```
466
+
467
+ ### Example: Complex Pipe System
468
+
469
+ ```python
470
+ import phg
471
+ from coordinate_system import vec3, quat, coord3
472
+
473
+ # Create a complex pipe network
474
+ def create_pipe_network():
475
+ # Main pipeline
476
+ main_pipe = phg.world_pipestr_vis(
477
+ "FFFFRRFFRRUUFFLLFF",
478
+ coord3(vec3(0, 0, 0), quat(1, 0, 0, 0)),
479
+ pipe_color=(100, 100, 255),
480
+ pipe_radius=0.5
481
+ )
482
+
483
+ # Branch 1
484
+ branch1 = phg.world_pipestr_vis(
485
+ "RRUUFFFF",
486
+ coord3(vec3(4, 0, 0), quat(1, 0, 0, 0)),
487
+ pipe_color=(255, 100, 100),
488
+ pipe_radius=0.3
489
+ )
490
+
491
+ # Branch 2
492
+ branch2 = phg.local_pipestr_vis(
493
+ "FFLLDDFF",
494
+ coord3(vec3(8, 2, 2), quat(1, 0, 0, 0)),
495
+ pipe_color=(100, 255, 100),
496
+ pipe_radius=0.3
497
+ )
498
+
499
+ return main_pipe, branch1, branch2
500
+
501
+ # Create and visualize the network
502
+ pipes = create_pipe_network()
503
+ ```
504
+
505
+ ---
506
+
390
507
  ## 💡 Complete Examples
391
508
 
392
509
  ### Example 1: Simple Geometry
@@ -566,7 +683,6 @@ Recommended maximum resolution is **4096 x 4096**. Excessively large resolutions
566
683
  ## 🔗 Links
567
684
 
568
685
  - [PyPI Package](https://pypi.org/project/phg/)
569
- - [Official Documentation](https://your.documentation.link)
570
686
  - [Mathematical Foundation](https://github.com/panguojun/Coordinate-System)
571
687
 
572
688
  ---
@@ -0,0 +1,329 @@
1
+ """
2
+ PHG - Python Hypergraphics Library
3
+ ===================================
4
+
5
+ A powerful graphics library for procedural 3D visualization using PHG scripts.
6
+
7
+ Main Features:
8
+ - PHG script visualization via vis.exe
9
+ - Shader-based rendering with GLSL conversion
10
+ - Pipe system visualization with world/local coordinate systems
11
+ - Multiple pipe visualization support
12
+ - Real-time and image rendering capabilities
13
+
14
+ Version: 1.3.1
15
+ Author: PanGuoJun
16
+ License: MIT
17
+ """
18
+
19
+ from .visphg import vis, image
20
+ from .shader_render import ShaderRenderer, render_shader
21
+ from .phg_to_shader import PHGToShaderConverter, phg_to_shader
22
+ from .pipe_string_phg import (
23
+ world_pipe_to_phg,
24
+ local_pipe_to_phg,
25
+ world_pipestr_vis,
26
+ local_pipestr_vis,
27
+ multiple_pipes_vis
28
+ )
29
+
30
+ # Extend ShaderRenderer class to support direct PHG rendering
31
+ class PHGShaderRenderer(ShaderRenderer):
32
+ """Shader renderer that supports direct PHG rendering"""
33
+
34
+ def render_phg(self, phg_script: str, duration=0, interactive=True):
35
+ """
36
+ Render PHG script
37
+
38
+ Parameters:
39
+ phg_script: PHG script code
40
+ duration: Render duration
41
+ interactive: Whether to allow interaction
42
+
43
+ Returns:
44
+ success: Whether rendering was successful
45
+ """
46
+ converter = PHGToShaderConverter()
47
+ shader_code = converter.generate_shader_code(phg_script)
48
+
49
+ if not shader_code:
50
+ print("Error: PHG conversion failed")
51
+ return False
52
+
53
+ return self.render_shader(shader_code, duration, interactive)
54
+
55
+ # Convenience functions
56
+ def render_phg(phg_script: str, width=800, height=600, duration=0, title="PHG Renderer"):
57
+ """
58
+ Directly render PHG script
59
+
60
+ Parameters:
61
+ phg_script: PHG script code
62
+ width: Window width
63
+ height: Window height
64
+ duration: Render duration
65
+ title: Window title
66
+ """
67
+ renderer = PHGShaderRenderer(width, height, title)
68
+ success = renderer.render_phg(phg_script, duration)
69
+ renderer.close()
70
+ return success
71
+
72
+ def convert_phg_to_shader(phg_script: str) -> str:
73
+ """
74
+ Convert PHG script to GLSL shader code
75
+
76
+ Parameters:
77
+ phg_script: PHG script
78
+
79
+ Returns:
80
+ shader_code: GLSL shader code
81
+ """
82
+ return phg_to_shader(phg_script)
83
+
84
+ def visualize_pipe_variants(pipe_variants, start_position=None, colors=None, coordinate_system='world'):
85
+ """
86
+ Visualize multiple pipe variants for comparison
87
+
88
+ Parameters:
89
+ pipe_variants: List of pipe strings or configuration dictionaries
90
+ start_position: Starting coordinate (optional)
91
+ colors: List of colors for each pipe variant
92
+ coordinate_system: 'world' or 'local' coordinate system
93
+
94
+ Returns:
95
+ PHG script string
96
+ """
97
+ from coordinate_system import vec3, quat, coord3
98
+
99
+ # Handle start position
100
+ if start_position is None:
101
+ start_c = coord3(vec3(0, 0, 0), quat(1, 0, 0, 0))
102
+ else:
103
+ start_c = start_position
104
+
105
+ # Handle different input formats
106
+ if isinstance(pipe_variants[0], str):
107
+ # Simple list of pipe strings
108
+ if colors is None:
109
+ # Generate distinct colors for each variant
110
+ import colorsys
111
+ colors = []
112
+ for i in range(len(pipe_variants)):
113
+ hue = i / len(pipe_variants)
114
+ rgb = colorsys.hsv_to_rgb(hue, 0.8, 0.9)
115
+ colors.append(tuple(int(c * 255) for c in rgb))
116
+
117
+ if coordinate_system == 'world':
118
+ return world_pipestr_vis(pipe_variants, start_c, colors)
119
+ else:
120
+ return local_pipestr_vis(pipe_variants, start_c, colors)
121
+
122
+ else:
123
+ # List of configuration dictionaries
124
+ pipe_configs = []
125
+ for i, variant in enumerate(pipe_variants):
126
+ if isinstance(variant, str):
127
+ config = {
128
+ 'pipe_str': variant,
129
+ 'start_c': start_c,
130
+ 'color': colors[i] if colors else None,
131
+ 'radius': 0.3
132
+ }
133
+ else:
134
+ config = variant
135
+ if 'start_c' not in config:
136
+ config['start_c'] = start_c
137
+
138
+ pipe_configs.append(config)
139
+
140
+ return multiple_pipes_vis(pipe_configs, coordinate_system)
141
+
142
+ def create_pipe_comparison_grid(pipe_strings, grid_size=(2, 2), start_position=None,
143
+ base_color=(0, 55, 255), coordinate_system='world'):
144
+ """
145
+ Create a grid layout for comparing multiple pipe paths
146
+
147
+ Parameters:
148
+ pipe_strings: List of pipe strings to compare
149
+ grid_size: (rows, cols) for grid layout
150
+ start_position: Base starting position
151
+ base_color: Base color for pipes
152
+ coordinate_system: 'world' or 'local'
153
+
154
+ Returns:
155
+ PHG script string
156
+ """
157
+ from coordinate_system import vec3, quat, coord3
158
+
159
+ if start_position is None:
160
+ start_position = coord3(vec3(0, 0, 0), quat(1, 0, 0, 0))
161
+
162
+ rows, cols = grid_size
163
+ spacing = 5.0 # Space between pipes in grid
164
+
165
+ pipe_configs = []
166
+
167
+ for i, pipe_str in enumerate(pipe_strings):
168
+ if i >= rows * cols:
169
+ break
170
+
171
+ row = i // cols
172
+ col = i % cols
173
+
174
+ # Calculate position in grid
175
+ x_offset = col * spacing
176
+ z_offset = row * spacing
177
+
178
+ # Create individual start position for this pipe
179
+ individual_start = coord3(
180
+ vec3(
181
+ start_position.o.x + x_offset,
182
+ start_position.o.y,
183
+ start_position.o.z + z_offset
184
+ ),
185
+ start_position.Q()
186
+ )
187
+
188
+ # Generate color variation
189
+ color_variation = (
190
+ min(255, base_color[0] + (i * 30) % 100),
191
+ min(255, base_color[1] + (i * 50) % 100),
192
+ min(255, base_color[2] + (i * 70) % 100)
193
+ )
194
+
195
+ pipe_configs.append({
196
+ 'pipe_str': pipe_str,
197
+ 'start_c': individual_start,
198
+ 'color': color_variation,
199
+ 'radius': 0.25 + (i * 0.05) # Vary radius slightly
200
+ })
201
+
202
+ return multiple_pipes_vis(pipe_configs, coordinate_system)
203
+
204
+ def generate_pipe_variants_from_rules(base_pipe, num_variants=5, apply_rules=None):
205
+ """
206
+ Generate pipe variants using transformation rules
207
+
208
+ Parameters:
209
+ base_pipe: Base pipe string
210
+ num_variants: Number of variants to generate
211
+ apply_rules: List of rules to apply ('swap', 'insert', 'cancel')
212
+
213
+ Returns:
214
+ List of pipe variant strings
215
+ """
216
+ if apply_rules is None:
217
+ apply_rules = ['swap', 'insert', 'cancel']
218
+
219
+ variants = [base_pipe]
220
+
221
+ # Import the pipe transformer if available
222
+ try:
223
+ from .pipe_string_phg import PipeStringTransformer
224
+ transformer = PipeStringTransformer()
225
+
226
+ for _ in range(num_variants - 1):
227
+ current_pipe = base_pipe
228
+
229
+ # Apply random transformations
230
+ import random
231
+ for _ in range(random.randint(1, 3)):
232
+ rule = random.choice(apply_rules)
233
+
234
+ if rule == 'swap' and len(current_pipe) >= 2:
235
+ i, j = random.sample(range(len(current_pipe)), 2)
236
+ current_pipe = transformer.swap_positions(current_pipe, i, j)
237
+
238
+ elif rule == 'insert':
239
+ position = random.randint(0, len(current_pipe))
240
+ direction = random.choice(list(transformer.CANCEL_PAIRS.keys()))
241
+ current_pipe = transformer.insert_cancel_pair(current_pipe, position, direction)
242
+
243
+ elif rule == 'cancel':
244
+ current_pipe = transformer.cancel_adjacent_pairs(current_pipe)
245
+
246
+ # Simplify and add if valid
247
+ simplified = transformer.simplify_path(current_pipe)
248
+ if simplified not in variants:
249
+ variants.append(simplified)
250
+
251
+ except ImportError:
252
+ # Fallback: simple variant generation
253
+ import random
254
+ for i in range(num_variants - 1):
255
+ # Simple character shuffling
256
+ pipe_list = list(base_pipe)
257
+ random.shuffle(pipe_list)
258
+ variant = ''.join(pipe_list)
259
+ if variant not in variants:
260
+ variants.append(variant)
261
+
262
+ return variants[:num_variants]
263
+
264
+ # Enhanced pipe visualization with transformation support
265
+ def visualize_pipe_with_transformations(pipe_string, start_position=None,
266
+ transformations=None, show_variants=3):
267
+ """
268
+ Visualize a pipe string along with its transformed variants
269
+
270
+ Parameters:
271
+ pipe_string: Base pipe string
272
+ start_position: Starting coordinate
273
+ transformations: List of transformation rules to apply
274
+ show_variants: Number of variants to show
275
+
276
+ Returns:
277
+ PHG script string
278
+ """
279
+ # Generate variants
280
+ variants = generate_pipe_variants_from_rules(
281
+ pipe_string,
282
+ num_variants=show_variants + 1, # +1 for original
283
+ apply_rules=transformations
284
+ )
285
+
286
+ # Create comparison visualization
287
+ return visualize_pipe_variants(variants, start_position)
288
+
289
+ __all__ = [
290
+ # Core visualization functions
291
+ 'vis',
292
+ 'image',
293
+
294
+ # Shader rendering
295
+ 'ShaderRenderer',
296
+ 'render_shader',
297
+ 'render_phg',
298
+ 'PHGShaderRenderer',
299
+
300
+ # PHG conversion
301
+ 'PHGToShaderConverter',
302
+ 'phg_to_shader',
303
+ 'convert_phg_to_shader',
304
+
305
+ # Pipe visualization
306
+ 'world_pipe_to_phg',
307
+ 'local_pipe_to_phg',
308
+ 'world_pipestr_vis',
309
+ 'local_pipestr_vis',
310
+ 'multiple_pipes_vis',
311
+
312
+ # Enhanced pipe visualization
313
+ 'visualize_pipe_variants',
314
+ 'create_pipe_comparison_grid',
315
+ 'generate_pipe_variants_from_rules',
316
+ 'visualize_pipe_with_transformations',
317
+ ]
318
+
319
+ __version__ = "1.3.1"
320
+ __author__ = "PanGuoJun"
321
+ __description__ = "Python Hypergraphics Library"
322
+
323
+ # Package initialization information
324
+ print(f"PHG {__version__} - {__description__}")
325
+ print("[OK] Visualization module loaded")
326
+ print("[OK] Shader converter loaded")
327
+ print("[OK] Pipe visualization loaded")
328
+ print("[OK] Multiple pipe visualization support loaded")
329
+ print("[OK] Pipe transformation utilities loaded")