-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prototype1.c
161 lines (159 loc) · 4.91 KB
/
Prototype1.c
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
#Setup before running code given below
/*
Code given below would run only in linux (Ubuntu)
Before running code we must install freeglut3-dev library of open GL in system
The code given can run in VS code but one needs to download glfw package and glad.
C code for constructing turing machine initial prototype
*/
#include <stdio.h>
#include <GL/freeglut.h>
void displayText(void *font, const char *text, float x, float y) {
glRasterPos2f(x, y);
for (int i = 0; text[i] != '\0'; i++) {
glutBitmapCharacter(font, text[i]);
}
}
void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Draw rectangles
glColor3f(1.0f, 1.0f, 1.0f); // Set color to white
// q0 rectangle
glBegin(GL_QUADS);
glVertex2f(-0.9f, 0.9f);
glVertex2f(-0.7f, 0.9f);
glVertex2f(-0.7f, 0.7f);
glVertex2f(-0.9f, 0.7f);
glEnd();
glColor3f(1.0f, 0.0f, 0.0f);
displayText(GLUT_BITMAP_HELVETICA_18, "q0", -0.89f, 0.85f);
glColor3f(0.0f, 0.0f, 1.0f);
displayText(GLUT_BITMAP_HELVETICA_10, "U --> U ,R", -0.89f, 0.94f);
glColor3f(1.0f, 1.0f, 1.0f);
// q1 rectangle
glBegin(GL_QUADS);
glVertex2f(-0.3f, 0.9f);
glVertex2f(-0.1f, 0.9f);
glVertex2f(-0.1f, 0.7f);
glVertex2f(-0.3f, 0.7f);
glEnd();
glColor3f(1.0f, 0.0f, 0.0f);
displayText(GLUT_BITMAP_HELVETICA_18, "q1", -0.29f, 0.85f);
glColor3f(0.0f, 0.0f, 1.0f);
displayText(GLUT_BITMAP_HELVETICA_10, "Res --> Res ,R\n\nPhos --> Phos ,R\n\nNitro --> Nitro ,R\n\nPest --> Pest ,R\n\nO2 --> O2 ,R", -0.59f, 0.94f);
glColor3f(1.0f, 1.0f, 1.0f);
// q2 rectangle
glBegin(GL_QUADS);
glVertex2f(0.3f, 0.9f);
glVertex2f(0.5f, 0.9f);
glVertex2f(0.5f, 0.7f);
glVertex2f(0.3f, 0.7f);
glEnd();
glColor3f(1.0f, 0.0f, 0.0f);
displayText(GLUT_BITMAP_HELVETICA_18, "q2", 0.31f, 0.85f);
glColor3f(0.0f, 0.0f, 1.0f);
displayText(GLUT_BITMAP_HELVETICA_10, "Res --> Res ,L\n\nPhos --> Phos ,L\n\nNitro --> Nitro ,L\n\nPest --> Pest ,L\n\nO2 --> x ,L", 0.29f, 0.94f);
glColor3f(1.0f, 1.0f, 1.0f);
// q3 rectangle
glBegin(GL_QUADS);
glVertex2f(0.9f, 0.9f);
glVertex2f(1.1f, 0.9f);
glVertex2f(1.1f, 0.7f);
glVertex2f(0.9f, 0.7f);
glEnd();
glColor3f(1.0f, 0.0f, 0.0f);
displayText(GLUT_BITMAP_HELVETICA_18, "q3", 0.85f, 0.85f);
glColor3f(1.0f, 1.0f, 1.0f);
// q4 rectangle
glBegin(GL_QUADS);
glVertex2f(-0.9f, 0.5f);
glVertex2f(-0.7f, 0.5f);
glVertex2f(-0.7f, 0.3f);
glVertex2f(-0.9f, 0.3f);
glEnd();
glColor3f(1.0f, 0.0f, 0.0f);
displayText(GLUT_BITMAP_HELVETICA_18, "q4", -0.89f, 0.45f);
glColor3f(1.0f, 1.0f, 1.0f);
// q5 rectangle
glBegin(GL_QUADS);
glVertex2f(-0.3f, 0.5f);
glVertex2f(-0.1f, 0.5f);
glVertex2f(-0.1f, 0.3f);
glVertex2f(-0.3f, 0.3f);
glEnd();
glColor3f(1.0f, 0.0f, 0.0f);
displayText(GLUT_BITMAP_HELVETICA_18, "q5", -0.29f, 0.45f);
glColor3f(1.0f, 1.0f, 1.0f);
// q6 rectangle
glBegin(GL_QUADS);
glVertex2f(0.3f, 0.5f);
glVertex2f(0.5f, 0.5f);
glVertex2f(0.5f, 0.3f);
glVertex2f(0.3f, 0.3f);
glEnd();
glColor3f(1.0f, 0.0f, 0.0f);
displayText(GLUT_BITMAP_HELVETICA_18, "q6", 0.31f, 0.45f);
glColor3f(1.0f, 1.0f, 1.0f);
// Draw lines for transitions
glColor3f(1.0f, 1.0f, 1.0f); // Set color to white
glLineWidth(2.0f);
// q0 to q1
glBegin(GL_LINES);
glVertex2f(-0.8f, 0.8f);
glVertex2f(-0.2f, 0.8f);
glEnd();
displayText(GLUT_BITMAP_HELVETICA_10, "S --> S, R", -0.5f, 0.81f);
// q1 to q2
glBegin(GL_LINES);
glVertex2f(-0.1f, 0.8f);
glVertex2f(0.5f, 0.8f);
glEnd();
displayText(GLUT_BITMAP_HELVETICA_10, "U --> U, L", 0.2f, 0.81f);
// Q1 to Q6
glBegin(GL_LINES);
glVertex2f(-0.2f, 0.7f);
glVertex2f(0.3f, 0.7f);
glEnd();
displayText(GLUT_BITMAP_HELVETICA_10, "C --> C, R", 0.05f, 0.71f);
// q2 to q3
glBegin(GL_LINES);
glVertex2f(0.4f, 0.8f);
glVertex2f(1.0f, 0.8f);
glEnd();
displayText(GLUT_BITMAP_HELVETICA_10, "U --> U, R", 0.6f, 0.81f);
// q3 to q4
glBegin(GL_LINES);
glVertex2f(1.0f, 0.8f);
glVertex2f(-0.8f, 0.5f);
glEnd();
displayText(GLUT_BITMAP_HELVETICA_10, "X --> X,R", 0.01f, 0.6f);
//0.89f, 0.54f
// q4 to q5
glBegin(GL_LINES);
glVertex2f(-0.7f, 0.4f);
glVertex2f(-0.3f, 0.4f);
glEnd();
displayText(GLUT_BITMAP_HELVETICA_10, "X --> X, R", -0.5f, 0.41f);
// q3 to q5
glBegin(GL_LINES);
glVertex2f(1.0f, 0.7f);
glVertex2f(-0.3f, 0.4f);
glEnd();
displayText(GLUT_BITMAP_HELVETICA_10, "Res --> Res ,R\n\nPhos --> Phos ,R\n\nNitro --> Nitro ,R\n\nPest --> Pest ,R", 0.4f, 0.58f);
// q4 to q6
glBegin(GL_LINES);
glVertex2f(-0.7f, 0.4f);
glVertex2f(0.3f, 0.4f);
glEnd();
displayText(GLUT_BITMAP_HELVETICA_10, "Res --> Res ,R\n\nPhos --> Phos ,R\n\nNitro --> Nitro ,R\n\nPest --> Pest ,R", -0.2f, 0.24f);
glutSwapBuffers();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(800, 400);
glutInitWindowPosition(100, 100);
glutCreateWindow("Turing Machine Diagram");
glutDisplayFunc(display);
glutMainLoop();
return 0; }