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
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pattern Generator</title>
<style>
body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #f0f0f0;
padding: 40px; /* Add padding to body */
}
.canvas-container {
width: 100%;
max-width: 800px; /* Visible width in viewport */
margin: 20px;
padding: 40px; /* Add padding around canvas */
background: white;
box-shadow: 0 0 20px rgba(0,0,0,0.1);
}
canvas {
width: 100%;
height: auto;
background: white;
}
/* Print styles */
@media print {
body {
background: none;
padding: 0;
}
.canvas-container {
max-width: none;
width: 8.5in;
margin: 0;
padding: 0;
box-shadow: none;
}
canvas {
width: 8.5in;
height: 11in;
border: none;
}
}
</style>
</head>
<body>
<div class="canvas-container">
<canvas id="canvas"></canvas>
</div>
<script>
// Set up canvas with print-friendly dimensions (assuming 300 DPI)
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
// 8.5 inches * 300 pixels per inch = 2550 pixels
// 11 inches * 300 pixels per inch = 3300 pixels
canvas.width = 2550;
canvas.height = 3300;
// Utility functions for pattern generation
const random = (min, max) => Math.random() * (max - min) + min;
const randomInt = (min, max) => Math.floor(random(min, max));
const randomChoice = arr => arr[Math.floor(Math.random() * arr.length)];
// Basic shape generators
const shapes = {
circle: (x, y, size, params = {}) => {
const radius = params.radius || size/3;
ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI * 2);
params.fill ? ctx.fill() : ctx.stroke();
},
line: (x1, y1, x2, y2) => {
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.stroke();
},
triangle: (x, y, size) => {
ctx.beginPath();
ctx.moveTo(x, y + size);
ctx.lineTo(x + size/2, y);
ctx.lineTo(x + size, y + size);
ctx.closePath();
ctx.stroke();
},
square: (x, y, size) => {
ctx.strokeRect(x, y, size, size);
}
};
// Pattern generators that are simple to draw
const generatePattern = () => {
const types = [
// Simple repeating circles
(x, y, size) => {
const spacing = size/3;
for(let i = 0; i < 3; i++) {
for(let j = 0; j < 3; j++) {
if((i + j) % 2 === 0) { // Checkerboard pattern
shapes.circle(
x + spacing/2 + i * spacing,
y + spacing/2 + j * spacing,
spacing/2
);
}
}
}
},
// Nested squares
(x, y, size) => {
for(let i = 3; i > 0; i--) {
const offset = (3 - i) * size/6;
const squareSize = size - offset * 2;
shapes.square(x + offset, y + offset, squareSize);
}
},
// Simple flower pattern
(x, y, size) => {
const center = size/2;
const radius = size/4;
// Center circle
shapes.circle(x + center, y + center, size/6);
// Petals
for(let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const petalX = x + center + Math.cos(angle) * radius;
const petalY = y + center + Math.sin(angle) * radius;
shapes.circle(petalX, petalY, size/6);
}
},
// Triangles in a row
(x, y, size) => {
const triSize = size/3;
for(let i = 0; i < 3; i++) {
shapes.triangle(
x + i * triSize,
y + (i % 2) * triSize/2,
triSize
);
}
},
// Simple grid of squares
(x, y, size) => {
const gridSize = size/2;
for(let i = 0; i < 2; i++) {
for(let j = 0; j < 2; j++) {
shapes.square(
x + i * gridSize + size/8,
y + j * gridSize + size/8,
gridSize * 0.75
);
}
}
},
// Alternating circles and squares
(x, y, size) => {
const spacing = size/2;
for(let i = 0; i < 2; i++) {
for(let j = 0; j < 2; j++) {
if((i + j) % 2 === 0) {
shapes.circle(
x + spacing/2 + i * spacing,
y + spacing/2 + j * spacing,
spacing/3
);
} else {
shapes.square(
x + i * spacing + spacing/6,
y + j * spacing + spacing/6,
spacing * 2/3
);
}
}
}
},
// Simple star pattern
(x, y, size) => {
const center = size/2;
// Horizontal and vertical lines
shapes.line(x, y + center, x + size, y + center);
shapes.line(x + center, y, x + center, y + size);
// Diagonal lines
shapes.line(x, y, x + size, y + size);
shapes.line(x + size, y, x, y + size);
},
// Nested arcs
(x, y, size) => {
const center = size/2;
for(let i = 1; i <= 4; i++) {
const radius = (size/2) * (i/4);
ctx.beginPath();
ctx.arc(x + center, y + center, radius, 0, Math.PI);
ctx.stroke();
}
},
// Quarter circles in corners
(x, y, size) => {
const radius = size/2;
// Top left
ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI/2);
ctx.stroke();
// Top right
ctx.beginPath();
ctx.arc(x + size, y, radius, Math.PI/2, Math.PI);
ctx.stroke();
// Bottom right
ctx.beginPath();
ctx.arc(x + size, y + size, radius, Math.PI, Math.PI * 3/2);
ctx.stroke();
// Bottom left
ctx.beginPath();
ctx.arc(x, y + size, radius, Math.PI * 3/2, Math.PI * 2);
ctx.stroke();
},
// Concentric circles
(x, y, size) => {
const center = size/2;
for(let i = 1; i <= 3; i++) {
shapes.circle(
x + center,
y + center,
size,
{radius: (size/2) * (i/3)}
);
}
},
// Nested diamonds
(x, y, size) => {
const center = size/2;
for(let i = 1; i <= 3; i++) {
const offset = (size/2) * (i/3);
ctx.beginPath();
ctx.moveTo(x + center, y + center - offset);
ctx.lineTo(x + center + offset, y + center);
ctx.lineTo(x + center, y + center + offset);
ctx.lineTo(x + center - offset, y + center);
ctx.closePath();
ctx.stroke();
}
},
// Radiating arcs
(x, y, size) => {
const center = size/2;
const radius = size/3;
for(let i = 0; i < 4; i++) {
const startAngle = (Math.PI/2) * i;
ctx.beginPath();
ctx.arc(x + center, y + center, radius, startAngle, startAngle + Math.PI/2);
ctx.stroke();
}
},
// Stacked semicircles
(x, y, size) => {
const width = size * 0.8;
for(let i = 0; i < 3; i++) {
ctx.beginPath();
ctx.arc(
x + size/2,
y + (size/3) * (i + 1),
width/2,
0,
Math.PI,
i % 2 === 0
);
ctx.stroke();
}
}
];
// Return a single pattern type (no combinations)
return (x, y, size) => {
ctx.save();
ctx.translate(x, y);
// Only rotate in 90-degree increments for predictability
const rotation = Math.PI/2 * randomInt(0, 4);
if(rotation > 0) {
ctx.translate(size/2, size/2);
ctx.rotate(rotation);
ctx.translate(-size/2, -size/2);
}
randomChoice(types)(0, 0, size);
ctx.restore();
};
};
// Generate fewer patterns to ensure more repetition
const patterns = Array(10).fill(null).map(generatePattern);
// Function to shuffle array
const shuffle = arr => [...arr].sort(() => Math.random() - 0.5);
// Function to draw a row of patterns
const drawPatternRow = (xOffset, y, size) => {
const gutter = size * 0.1; // 10% of pattern size for gutter
const patternWithGutter = size * 0.8; // 80% of space for actual pattern
const shuffledPatterns = shuffle(patterns);
for(let i = 0; i < 5; i++) {
const xPos = xOffset + i * size + gutter;
const yPos = y + gutter;
shuffledPatterns[i](xPos, yPos, patternWithGutter);
}
};
// Modified drawGrid function with reduced top margin
const drawGrid = () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = '#000';
ctx.lineWidth = 4;
const patternSize = 400;
const numRows = 4;
const topMargin = 100; // Reduced from 300
const bottomMargin = 300; // Keep original bottom margin
// Calculate available space with asymmetric margins
const availableHeight = canvas.height - (topMargin + bottomMargin);
// Calculate row spacing with increased gaps
const totalPatternHeight = numRows * patternSize;
const totalGapHeight = availableHeight - totalPatternHeight;
const rowGap = totalGapHeight / (numRows - 1);
// Calculate horizontal centering
const totalWidth = patternSize * 5;
const xOffset = (canvas.width - totalWidth) / 2;
// Draw each row
for(let i = 0; i < numRows; i++) {
const y = topMargin + i * (patternSize + rowGap);
drawPatternRow(xOffset, y, patternSize);
}
};
drawGrid();
canvas.addEventListener('click', drawGrid);
</script>
</body>
</html>
|