File size: 12,367 Bytes
f3b69f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
"""
LUXBIN - Photonic Binary Language Demo
A language where colors are letters and shades are grammar
"""

import gradio as gr
import numpy as np
from PIL import Image, ImageDraw, ImageFont
import time

# LUXBIN Alphabet (26 letters A-Z)
ALPHABET = {
    'A': 0.0, 'B': 5.625, 'C': 11.25, 'D': 16.875, 'E': 22.5,
    'F': 28.125, 'G': 33.75, 'H': 39.375, 'I': 45.0, 'J': 50.625,
    'K': 56.25, 'L': 61.875, 'M': 67.5, 'N': 73.125, 'O': 78.75,
    'P': 84.375, 'Q': 90.0, 'R': 95.625, 'S': 101.25, 'T': 106.875,
    'U': 112.5, 'V': 118.125, 'W': 123.75, 'X': 129.375, 'Y': 135.0,
    'Z': 140.625
}

# Reverse mapping
REVERSE_ALPHABET = {v: k for k, v in ALPHABET.items()}

# Grammar mappings
PARTS_OF_SPEECH = {
    'Noun': 100,
    'Verb': 75,
    'Adjective': 50,
    'Modifier': 30,
    'Control': 0
}

TENSES = {
    'Present': 70,
    'Past': 40,
    'Future': 85,
    'Conditional': 90
}


def hsl_to_rgb(h, s, l):
    """Convert HSL to RGB (0-255)"""
    s = s / 100.0
    l = l / 100.0

    c = (1 - abs(2 * l - 1)) * s
    x = c * (1 - abs((h / 60) % 2 - 1))
    m = l - c / 2

    if h < 60:
        r, g, b = c, x, 0
    elif h < 120:
        r, g, b = x, c, 0
    elif h < 180:
        r, g, b = 0, c, x
    elif h < 240:
        r, g, b = 0, x, c
    elif h < 300:
        r, g, b = x, 0, c
    else:
        r, g, b = c, 0, x

    return int((r + m) * 255), int((g + m) * 255), int((b + m) * 255)


def encode_text_to_luxbin(text, part_of_speech='Noun', tense='Present'):
    """Encode text to LUXBIN color sequence"""
    text = text.upper()
    saturation = PARTS_OF_SPEECH.get(part_of_speech, 100)
    lightness = TENSES.get(tense, 70)

    colors = []
    for char in text:
        if char == ' ':
            colors.append((0, 0, 0))  # Black for space
        elif char in ALPHABET:
            hue = ALPHABET[char]
            rgb = hsl_to_rgb(hue, saturation, lightness)
            colors.append(rgb)
        else:
            colors.append((128, 128, 128))  # Gray for unknown

    return colors


def create_color_strip(colors, width=800, height=100):
    """Create image showing color sequence"""
    if not colors:
        return Image.new('RGB', (width, height), 'black')

    img = Image.new('RGB', (width, height))
    draw = ImageDraw.Draw(img)

    block_width = width // len(colors)

    for i, color in enumerate(colors):
        x1 = i * block_width
        x2 = x1 + block_width
        draw.rectangle([x1, 0, x2, height], fill=color)

    return img


def create_hue_wheel(size=400):
    """Create visual hue wheel showing alphabet"""
    img = Image.new('RGB', (size, size), 'white')
    draw = ImageDraw.Draw(img)

    center = size // 2
    radius = size // 2 - 20

    # Draw color wheel
    for i in range(360):
        angle = i * np.pi / 180
        hue = i
        rgb = hsl_to_rgb(hue, 100, 70)

        x1 = center + int((radius - 30) * np.cos(angle))
        y1 = center + int((radius - 30) * np.sin(angle))
        x2 = center + int(radius * np.cos(angle))
        y2 = center + int(radius * np.sin(angle))

        draw.line([x1, y1, x2, y2], fill=rgb, width=2)

    # Add letter labels
    try:
        font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 16)
    except:
        font = ImageFont.load_default()

    for letter, hue in ALPHABET.items():
        angle = (hue - 90) * np.pi / 180  # Adjust for top = 0°
        label_radius = radius + 30
        x = center + int(label_radius * np.cos(angle))
        y = center + int(label_radius * np.sin(angle))

        # Draw letter
        bbox = draw.textbbox((x, y), letter, font=font)
        draw.text((x - (bbox[2] - bbox[0]) / 2, y - (bbox[3] - bbox[1]) / 2),
                  letter, fill='black', font=font)

    return img


def encode_demo(text, pos, tense):
    """Main encoding function"""
    colors = encode_text_to_luxbin(text, pos, tense)
    strip = create_color_strip(colors)

    # Create description
    desc = f"**LUXBIN Encoding**\n\n"
    desc += f"Text: `{text}`\n\n"
    desc += f"Grammar: {pos} (Saturation: {PARTS_OF_SPEECH[pos]}%), "
    desc += f"{tense} (Lightness: {TENSES[tense]}%)\n\n"
    desc += f"**Color Sequence:** {len(colors)} symbols\n\n"

    # List each letter with its color
    for i, char in enumerate(text.upper()):
        if char == ' ':
            desc += "` ` → Black (word boundary)\n\n"
        elif char in ALPHABET:
            desc += f"`{char}` → Hue {ALPHABET[char]:.1f}° (RGB: {colors[i]})\n\n"

    return strip, desc


def create_grammar_guide():
    """Create visual guide for grammar rules"""
    img = Image.new('RGB', (600, 400), 'white')
    draw = ImageDraw.Draw(img)

    try:
        font_title = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 20)
        font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 14)
    except:
        font_title = font = ImageFont.load_default()

    y = 20

    # Title
    draw.text((20, y), "LUXBIN Grammar Rules", fill='black', font=font_title)
    y += 40

    # Saturation (Parts of Speech)
    draw.text((20, y), "Saturation → Part of Speech", fill='black', font=font)
    y += 30

    for pos, sat in PARTS_OF_SPEECH.items():
        rgb = hsl_to_rgb(180, sat, 70)  # Use cyan hue for demo
        draw.rectangle([20, y, 70, y + 20], fill=rgb, outline='black')
        draw.text((80, y + 3), f"{pos}: {sat}%", fill='black', font=font)
        y += 30

    y += 20

    # Lightness (Tense)
    draw.text((20, y), "Lightness → Tense/Mode", fill='black', font=font)
    y += 30

    for tense, light in TENSES.items():
        rgb = hsl_to_rgb(180, 100, light)  # Use cyan hue for demo
        draw.rectangle([20, y, 70, y + 20], fill=rgb, outline='black')
        draw.text((80, y + 3), f"{tense}: {light}%", fill='black', font=font)
        y += 30

    return img


# Create Gradio interface
with gr.Blocks(title="LUXBIN - Photonic Binary Language", theme=gr.themes.Soft()) as demo:
    gr.Markdown("""
    # ⚛️ LUXBIN - Photonic Binary Language

    **A language where colors are letters and shades are grammar**

    - **Hue (0°-360°)** = Letter identity (A-Z)
    - **Saturation** = Part of speech (Noun, Verb, etc.)
    - **Lightness** = Tense/mode (Present, Past, etc.)
    - **Timing** = Word and sentence boundaries

    ---
    """)

    with gr.Tabs():
        # Tab 1: Encoder
        with gr.Tab("📤 Encode Text to LUXBIN"):
            gr.Markdown("### Convert text into photonic color sequences")

            with gr.Row():
                with gr.Column():
                    text_input = gr.Textbox(
                        label="Enter Text",
                        placeholder="HELLO WORLD",
                        value="HELLO"
                    )

                    pos_input = gr.Dropdown(
                        choices=list(PARTS_OF_SPEECH.keys()),
                        value="Noun",
                        label="Part of Speech (Saturation)"
                    )

                    tense_input = gr.Dropdown(
                        choices=list(TENSES.keys()),
                        value="Present",
                        label="Tense/Mode (Lightness)"
                    )

                    encode_btn = gr.Button("🎨 Encode to LUXBIN", variant="primary")

                with gr.Column():
                    color_output = gr.Image(label="LUXBIN Color Sequence")
                    desc_output = gr.Markdown()

            encode_btn.click(
                fn=encode_demo,
                inputs=[text_input, pos_input, tense_input],
                outputs=[color_output, desc_output]
            )

            gr.Markdown("""
            **How to read:**
            - Each color block = one letter
            - Black = space (word boundary)
            - Hue = which letter (A-Z)
            - Saturation = grammatical role
            - Lightness = tense
            """)

        # Tab 2: Alphabet Reference
        with gr.Tab("🎨 Alphabet & Hue Wheel"):
            gr.Markdown("### Visual reference for the LUXBIN alphabet")

            wheel_img = create_hue_wheel()
            gr.Image(value=wheel_img, label="LUXBIN Hue Wheel (26 Letters)")

            gr.Markdown("""
            **How it works:**
            - 360° hue spectrum divided into 64 symbols
            - A-Z occupy first 26 positions
            - Step size: 5.625° per symbol
            - A = 0° (red), Z = 140.625° (greenish-blue)
            """)

            # Show alphabet table
            gr.Markdown("### Complete Alphabet")

            alphabet_html = "<table style='width:100%'><tr>"
            for i, (letter, hue) in enumerate(ALPHABET.items()):
                if i % 6 == 0 and i > 0:
                    alphabet_html += "</tr><tr>"
                rgb = hsl_to_rgb(hue, 100, 70)
                alphabet_html += f"<td style='background-color:rgb{rgb}; padding:10px; text-align:center; border:1px solid black;'><b>{letter}</b><br>{hue:.1f}°</td>"
            alphabet_html += "</tr></table>"

            gr.HTML(alphabet_html)

        # Tab 3: Grammar Guide
        with gr.Tab("📚 Grammar Rules"):
            gr.Markdown("### LUXBIN grammar encoded in light properties")

            grammar_img = create_grammar_guide()
            gr.Image(value=grammar_img, label="Grammar Visual Guide")

            gr.Markdown("""
            ### Encoding Rules

            **Binary Layer:**
            - Each symbol = 6 bits (0-63)
            - Binary indexes photonic states
            - Not direct letter encoding

            **Photonic Layer:**
            - Hue = semantic identity (which letter/symbol)
            - Saturation = grammatical role
            - Lightness = temporal/modal information

            **Temporal Layer:**
            - 100ms = letter duration
            - 200ms dark = word boundary
            - 500ms dark = sentence end

            **Modifiers:**
            - +10% darker = plural
            - -10% lighter = negation
            - Rapid flicker = emphasis
            - Smooth fade = completion
            """)

        # Tab 4: About
        with gr.Tab("ℹ️ About LUXBIN"):
            gr.Markdown("""
            # About LUXBIN

            **LUXBIN** is a photonic binary language where semantic information is encoded directly in the physical properties of light.

            ## Key Concepts

            1. **Physics as Syntax**: Light parameters carry meaning
            2. **Parallel Channels**: Multiple layers of information in one photon
            3. **Non-Linear Encoding**: Not a cipher, but a genuine language

            ## Applications

            - **Assistive Technology**: Non-verbal communication
            - **Secure Communication**: Line-of-sight only, hard to intercept
            - **Extreme Environments**: Underwater, space, RF-denied zones
            - **Human-Machine Interfaces**: Direct photonic signaling

            ## Technical Details

            - **Alphabet Size**: 26 letters + 38 extended symbols
            - **Color Space**: HSL (Hue, Saturation, Lightness)
            - **Binary Base**: 6-bit indexing (64 total symbols)
            - **Grammar Layers**: Saturation, Lightness, Temporal

            ## Implementation

            - **Hardware**: ESP32 + WS2812 RGB LEDs
            - **Software**: Python encoder/decoder
            - **Perception**: Trainable by humans in ~30 minutes

            ## Status

            LUXBIN is a complete language specification ready for:
            - Hardware prototyping
            - Human perception testing
            - Standardization
            - Publication

            ---

            **Created by:** Nicholechristie
            **Version:** 1.0
            **License:** Open Specification
            """)

    # Examples
    gr.Markdown("---")
    gr.Markdown("### 🚀 Try These Examples")

    gr.Examples(
        examples=[
            ["HELLO WORLD", "Noun", "Present"],
            ["TEST", "Verb", "Past"],
            ["AI LANGUAGE", "Noun", "Future"],
            ["QUANTUM", "Adjective", "Present"],
        ],
        inputs=[text_input, pos_input, tense_input],
        outputs=[color_output, desc_output],
        fn=encode_demo,
        cache_examples=True
    )

# Launch
if __name__ == "__main__":
    demo.launch()