File size: 3,536 Bytes
48c1006
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4ede07e
48c1006
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4ede07e
48c1006
 
 
 
 
 
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
import streamlit as st
import streamlit.components.v1 as components

# HTML content
html_content = """
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2D Canvas Base 6 with Hidden State in Red</title>
    <style>
        body { font-family: Arial, sans-serif; }
        #coordinate-display { 
            position: absolute; 
            top: 10px; 
            left: 10px; 
            background-color: rgba(255, 255, 255, 0.7);
            padding: 5px;
            border-radius: 5px;
        }
    </style>
</head>
<body>
    
    <div style="position: relative;">
        <canvas id="graphCanvas" width="500" height="400" style="border: 1px solid #000;"></canvas>
        <div id="coordinate-display"></div>
    </div>

    <script>
        const canvas = document.getElementById('graphCanvas');
        const ctx = canvas.getContext('2d');
        const coordinateDisplay = document.getElementById('coordinate-display');

        function shouldHighlightCoordinate(num) {
            return ['6', '7', '8', '9'].some(digit => num.toString().includes(digit));
        }

        function drawGraph() {
            // Clear canvas
            ctx.fillStyle = '#f0f0f0';
            ctx.fillRect(0, 0, canvas.width, canvas.height);

            // Draw grid
            ctx.strokeStyle = '#999';
            ctx.lineWidth = 0.5;
            for (let i = 0; i <= 55; i += 5) {
                let x = i / 55 * canvas.width;
                let y = canvas.height - (i / 55 * canvas.height);
                
                ctx.beginPath();
                ctx.moveTo(x, 0);
                ctx.lineTo(x, canvas.height);
                ctx.stroke();

                ctx.beginPath();
                ctx.moveTo(0, y);
                ctx.lineTo(canvas.width, y);
                ctx.stroke();

                // Draw labels
                ctx.fillStyle = 'black';
                ctx.font = '12px Arial';
                ctx.fillText(i.toString(), x, canvas.height - 5);
                ctx.fillText(i.toString(), 5, y);
            }

            // Draw highlighted areas
            ctx.fillStyle = 'rgba(0, 0, 0, 0.2)';
            for (let i = 0; i <= 55; i++) {
                if (shouldHighlightCoordinate(i)) {
                    ctx.fillRect(i / 55 * canvas.width, 0, canvas.width / 55, canvas.height);
                    ctx.fillRect(0, canvas.height - ((i + 1) / 55 * canvas.height), canvas.width, canvas.height / 55);
                }
            }
        }

        function updateCoordinateDisplay(event) {
            const rect = canvas.getBoundingClientRect();
            const x = Math.min(55, Math.round((event.clientX - rect.left) / canvas.width * 55));
            const y = Math.round((1 - (event.clientY - rect.top) / canvas.height) * 55);
            const combined = x * 100 + y;
            
            coordinateDisplay.textContent = `Coordinate: ${combined}`;
            coordinateDisplay.style.color = shouldHighlightCoordinate(combined) ? 'red' : 'black';
        }

        canvas.addEventListener('mousemove', updateCoordinateDisplay);

        drawGraph();
    </script>
</body>
</html>
"""

# Streamlit app
def main():
    st.set_page_config(page_title="Interactive 2D Graph", layout="wide")
    
    st.title("2D Interactive Graph Base 6 With Hidden State in Red")
    
    # Embed the HTML content
    components.html(html_content, height=600)

if __name__ == "__main__":
    main()