rss
logo

I provide consulting and custom development for Natural Language Processing, Information Extraction and Search solutions.Self Picture


 learn more   get in touch 

Logo - I Build Search
Jul 01
2003

Tilings Project digg

This code generated certain tile patterns. It was a lab assignment for the graphics course.

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
// tiling.cpp - Project titled Tilings
// Pravin Paratey (July 01, 2003)
 
#include <math.h>
#include <GL/gl.h>
#include <stdio.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <time.h>
 
#define CELL_WIDTH 20
#define CELL_HEIGHT 20
 
int choice=4;
const float PI=3.14;
 
void pattern1()
{
	float x,y,t;
 
	// __
	//  |
	glBegin(GL_LINE_STRIP);
	for(t=0;t<=3.15;t+=0.05)
	{
		x = 2.0*cos(t);
		y = 2.0*sin(t);
		glVertex2f(x-1.0,y-1.0);
	}
	glEnd();
	// |_
	glBegin(GL_LINE_STRIP);
	for(t=0;t<=3.15;t+=0.05)
	{
		x = 2.0*cos(t);
		y = 2.0*sin(t);
		glVertex2f(1.0-x,1.0-y);
	}
	glEnd();
 
	glBegin(GL_LINE_STRIP);
	for(t=PI/2;t<=PI;t+=0.01)
	{
		x = 2.0*cos(t);
		y = 2.0*sin(t);
		glVertex2f(x+1.0,y-1.0);
	}
	glEnd();
 
	glBegin(GL_LINE_STRIP);
	for(t=3*PI/2;t<=2*PI;t+=0.01)
	{
		x = 2.0*cos(t);
		y = 2.0*sin(t);
		glVertex2f(x-1.0,y+1.0);
	}
	glEnd();
}
 
void pattern2(int i, int j)
{
	// This calculates which tile to put
	if(i % 2 != 0)
		j++;
	if (j % 2 == 0)
	{
		glBegin(GL_LINES);
		glVertex2f(-1.0,1.0);
		glVertex2f(0.0,0.5);
		glVertex2f(0.0,0.5);
		glVertex2f(1.0,1.0);
		glVertex2f(0.0,0.5);
		glVertex2f(0.0,-0.5);
		glVertex2f(0.0,-0.5);
		glVertex2f(-1.0,-1.0);
		glVertex2f(0.0,-0.5);
		glVertex2f(1.0,-1.0);
		glEnd();
	}
	else
	{
		glBegin(GL_LINES);
		glVertex2f(-1.0,1.0);
		glVertex2f(-0.5,0.0);
		glVertex2f(-0.5,0.0);
		glVertex2f(-1.0,-1.0);
		glVertex2f(-0.5,0.0);
		glVertex2f(0.5,0.0);
		glVertex2f(0.5,0.0);
		glVertex2f(1.0,1.0);
		glVertex2f(0.5,0.0);
		glVertex2f(1.0,-1.0);
		glEnd();
	}
}
 
void custom()
{
	int r;
	float x,y,t;
 
	r = 1+(int)(6.0*rand()/(RAND_MAX+1.0));
 
	//r=4;
/*
	if (r == 1)
	{
		// T1
		glBegin(GL_LINES);
		glVertex2f(-1.0,1.0);
		glVertex2f(-0.5,-0.5);
		glVertex2f(-0.5,-0.5);
		glVertex2f(-1.0,-1.0);
		glVertex2f(-0.5,-0.5);
		glVertex2f(1.0,-1.0);
		glVertex2f(-1.0,1.0);
		glVertex2f(0.5,0.5);
		glVertex2f(0.5,0.5);
		glVertex2f(1.0,1.0);
		glVertex2f(0.5,0.5);
		glVertex2f(1.0,-1.0);
		glEnd();
	}
	else if (r == 2)
	{
		//T2
		glBegin(GL_LINES);
		glVertex2f(-1.0,1.0);
		glVertex2f(-0.5,0.5);
		glVertex2f(-0.5,0.5);
		glVertex2f(-0.5,-0.5);
		glVertex2f(-0.5,-0.5);
		glVertex2f(-1.0,-1.0);
		glVertex2f(-0.5,-0.5);
		glVertex2f(0.5,-0.5);
		glVertex2f(0.5,-0.5);
		glVertex2f(1.0,-1.0);
		glVertex2f(0.5,-0.5);
		glVertex2f(0.5,0.5);
		glVertex2f(0.5,0.5);
		glVertex2f(1.0,1.0);
		glVertex2f(0.5,0.5);
		glVertex2f(-0.5,0.5);
		glEnd();
	}
	else if (r == 3)
	{
		//T3
		glBegin(GL_LINES);
		glVertex2f(-1.0,1.0);
		glVertex2f(0.5,0.5);
		glVertex2f(0.5,0.5);
		glVertex2f(0.5,-0.5);
		glVertex2f(0.5,-0.5);
		glVertex2f(-1.0,-1.0);
		glVertex2f(1.0,1.0);
		glVertex2f(-0.5,0.5);
		glVertex2f(-0.5,0.5);
		glVertex2f(-0.5,-0.5);
		glVertex2f(-0.5,-0.5);
		glVertex2f(1.0,-1.0);
		glEnd();
	}
	else if (r == 4)
	{
		//T4
		glBegin(GL_LINES);
		glVertex2f(-1.0,1.0);
		glVertex2f(-0.5,-0.5);
		glVertex2f(0.5,0.5);
		glVertex2f(1.0,-1.0);
		glVertex2f(-1.0,-1.0);
		glVertex2f(1.0,1.0);
		glEnd();
	}
*/
	if(r == 1)
	{
		glBegin(GL_LINE_STRIP);
		glVertex2f(-1.0,0.0);
		glVertex2f(-0.5,0.0);
		glVertex2f(-0.5,0.5);
		glVertex2f(0.0,0.5);
		glVertex2f(0.0,1.0);
		glEnd();
		glBegin(GL_LINE_STRIP);
		glVertex2f(0.0,-1.0);
		glVertex2f(0.0,-0.5);
		glVertex2f(0.5,-0.5);
		glVertex2f(0.5,0.0);
		glVertex2f(1.0,0.0);
		glEnd();
	}
	else if(r == 2)
	{
		glBegin(GL_LINES);
		glVertex2f(-1.0,0.0);
		glVertex2f(0.0,1.0);
		glEnd();
		glBegin(GL_LINES);
		glVertex2f(0.0,-1.0);
		glVertex2f(1.0,0.0);
		glEnd();
	}
	else if(r == 3)
	{
		glBegin(GL_LINE_STRIP);
		for(t=PI/2;t<=PI;t+=0.01)
		{
			x = cos(t);
			y = sin(t);
			glVertex2f(x+1.0,y-1.0);
		}
		glEnd();
 
		glBegin(GL_LINE_STRIP);
		for(t=3*PI/2;t<=2*PI;t+=0.01)
		{
			x = cos(t);
			y = sin(t);
			glVertex2f(x-1.0,y+1.0);
		}
		glEnd();
	}
	else if(r == 4)
	{
		glBegin(GL_LINE_STRIP);
		glVertex2f(-1.0,0.0);
		glVertex2f(-0.5,0.0);
		glVertex2f(-0.5,-0.5);
		glVertex2f(0.0,-0.5);
		glVertex2f(0.0,-1.0);
		glEnd();
		glBegin(GL_LINE_STRIP);
		glVertex2f(0.0,1.0);
		glVertex2f(0.0,0.5);
		glVertex2f(0.5,0.5);
		glVertex2f(0.5,0.0);
		glVertex2f(1.0,0.0);
		glEnd();
	}
	else if(r == 5)
	{
		glBegin(GL_LINES);
		glVertex2f(-1.0,0.0);
		glVertex2f(0.0,-1.0);
		glEnd();
		glBegin(GL_LINES);
		glVertex2f(1.0,0.0);
		glVertex2f(0.0,1.0);
		glEnd();
	}
	else
	{
		glBegin(GL_LINE_STRIP);
		for(t=0;t<=3.15;t+=0.05)
		{
			x = cos(t);
			y = sin(t);
			glVertex2f(x-1.0,y-1.0);
		}
		glEnd();
 
		// |_
		glBegin(GL_LINE_STRIP);
		for(t=0;t<=3.15;t+=0.05)
		{
			x = cos(t);
			y = sin(t);
			glVertex2f(1.0-x,1.0-y);
		}
		glEnd();
	}
}
 
void truchet()
{
	int r;
	float x,y,t;
 
	// Randomly select one truchet to draw
	r = 1+(int)(2.0*rand()/(RAND_MAX+1.0));
 
	if(r == 1)
	{
		// __
		//  |
		glBegin(GL_LINE_STRIP);
		for(t=0;t<=3.15;t+=0.05)
		{
			x = cos(t);
			y = sin(t);
			glVertex2f(x-1.0,y-1.0);
		}
		glEnd();
 
		// |_
		glBegin(GL_LINE_STRIP);
		for(t=0;t<=3.15;t+=0.05)
		{
			x = cos(t);
			y = sin(t);
			glVertex2f(1.0-x,1.0-y);
		}
		glEnd();
	}
	else
	{
		glBegin(GL_LINE_STRIP);
		for(t=PI/2;t<=PI;t+=0.01)
		{
			x = cos(t);
			y = sin(t);
			glVertex2f(x+1.0,y-1.0);
		}
		glEnd();
 
		glBegin(GL_LINE_STRIP);
		for(t=3*PI/2;t<=2*PI;t+=0.01)
		{
			x = cos(t);
			y = sin(t);
			glVertex2f(x-1.0,y+1.0);
		}
		glEnd();
	}
}
 
void myDraw()
{
	float x, y;
	float t;
 
	glClear(GL_COLOR_BUFFER_BIT);
	//glViewport(0,0,100,100);
	glColor3f(0.0,0.0,1.0);
 
 
	for(int i=0;i<glutGet(GLUT_WINDOW_WIDTH)+CELL_WIDTH;i+=CELL_WIDTH)
		for(int j=0;j<glutGet(GLUT_WINDOW_HEIGHT)+CELL_HEIGHT;j+=CELL_HEIGHT)
		{
			glViewport(i,j,CELL_WIDTH,CELL_HEIGHT);
			if(choice == 1)
				pattern1();
			else if(choice == 2)
				pattern2(i/CELL_WIDTH,j/CELL_HEIGHT); //Passing co-ords
			else if (choice == 3)
				truchet();
			else if (choice == 4)
				custom();
		}
	glFlush();
}
 
void GetParams()
{
	printf("\nTilings\nBy Pravin Paratey[July 10, 2003]");
	printf("\n[1] Pattern 1 [Circles] (one motif repeated)");
	printf("\n[2] Pattern 2 [Cairo Tiles] (2 motifs placed alternately)");
	printf("\n[3] Truchet (2 motifs chosen randomly)");
	printf("\n[4] Custom Pattern (6 motifs chosen randomly)");
	printf("\nEnter Choice: ");
	scanf("%i",&choice);
}
 
 
int main(int argc, char *argv[])
{
 
	GetParams();
 
	// Initialise random seed
	srand(time(NULL));
	// Glut initializations
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(400,400);
	glutInitWindowPosition(100,100);
	glutCreateWindow("Tilings - Pravin Paratey");
 
	glClearColor(1.0,1.0,1.0,0.5);
	glutDisplayFunc(myDraw);
	glutMainLoop();
	return 0;
}

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Latest Articles

Apr
07

Palindromic sub-sequences in python

This bit of python code returns all palindromic subsequences in the input string.

[Read More]
Feb
19

Join a list of integers in Python

How do you run a string join on a list of integers in Python? After googling for about 10 mins, I gave up and did this. I am sure there is a better way of doing it!

[Read More]

Featured Projects

Document Tagger

Document Tagger

DocTagger lets you automatically classify text documents. Use this as a starting point to write apps that can sort through volumes of unorganized data.

[Read More]

Indic to English Transliterator

Indic to English Transliterator

Transliteration is the process of converting a word from one language to another while retaining its phonetic characteristics. This application lets you convert a word from any major Indian language (currently supports Hindi, Marathi, Sanskrit and Bengali) to English.

[Read More]

This page and its contents are copyright © 2010, Pravin Paratey.