-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph-paper.html
More file actions
179 lines (158 loc) · 8.47 KB
/
graph-paper.html
File metadata and controls
179 lines (158 loc) · 8.47 KB
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
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="description" content="Papier quadrillé à imprimer avec espacement et subdivisions personnalisables. Idéal pour les graphiques, dessins techniques et plans.">
<title>Papier quadrillé - PaperKit</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="format-a4.css">
<script defer src="https://cloud.umami.is/script.js" data-website-id="3d089b60-6919-490c-954f-451842d8f854"></script>
</head>
<body>
<div id="main">
<div id="info">
<nav>
<a href="index.html">← retour à la liste des modèles</a>
</nav>
<h1>Papier quadrillé <span class="badge">A4</span></h1>
<p>Cette page est <a href="#" onclick="window.print(); return false;">imprimable</a> sur un format de papier A4 afin d'obtenir une grille millimétrée.</p>
<h2>Options</h2>
<div class="slider-group">
<div class="slider-header">
<label for="spacing">Espacement des lignes principales</label>
<div class="value"><span id="spacingValue">5</span> mm</div>
</div>
<input type="range" id="spacing" name="spacing" min="1" max="20" value="5">
</div>
<div class="slider-group">
<div class="slider-header">
<label for="subdivisions">Subdivisions</label>
<div class="value"><span id="subdivisionsValue">1</span></div>
</div>
<input type="range" id="subdivisions" name="subdivisions" min="1" max="10" value="1">
</div>
<div class="slider-group">
<div class="slider-header">
<label for="margin">Largeur de la marge</label>
<div class="value"><span id="marginValue">5</span> mm</div>
</div>
<input type="range" id="margin" name="margin" min="1" max="20" value="5">
</div>
<div class="print-button">
<button onclick="window.print()">Imprimer</button>
</div>
<div class="credits">
<a href="https://github.com/alexandregrignon/PaperKit">PaperKit</a>
</div>
</div>
<div class="paper">
<svg id="grid" width="210mm" height="297mm" xmlns="http://www.w3.org/2000/svg">
<!-- La grille sera générée par le script -->
</svg>
</div>
</div>
<script>
(function(){
var pageWidth = 210;
var pageHeight = 297;
var svg = document.getElementById("grid");
function createGrid(spacing, subdivisions, pageMargin) {
// Calcul de la zone effective
var effectiveWidth = pageWidth - 2 * pageMargin;
var effectiveHeight = pageHeight - 2 * pageMargin;
// Calcul du nombre de lignes
var nX = Math.floor(effectiveWidth / spacing) + 1;
var nY = Math.floor(effectiveHeight / spacing) + 1;
// Calcul de marge additionnelle pour centrer la grille
var extraMarginX = (effectiveWidth - (nX - 1) * spacing) / 2;
var extraMarginY = (effectiveHeight - (nY - 1) * spacing) / 2;
// Position de départ de la grille
var marginX = pageMargin + extraMarginX;
var marginY = pageMargin + extraMarginY;
// Création des groupes pour séparer visuellement les lignes principales et secondaires
const mainLines = document.createElementNS("http://www.w3.org/2000/svg", "g");
mainLines.setAttribute("stroke", "#bbb");
mainLines.setAttribute("stroke-width", "0.2mm");
const subLines = document.createElementNS("http://www.w3.org/2000/svg", "g");
subLines.setAttribute("stroke", "#ddd");
subLines.setAttribute("stroke-width", "0.1mm");
// Lignes verticales
for (var i = 0; i < nX; i++) {
var x = marginX + i * spacing;
// Ligne principale
var mainLine = document.createElementNS("http://www.w3.org/2000/svg", "line");
mainLine.setAttribute("x1", x + "mm");
mainLine.setAttribute("y1", marginY + "mm");
mainLine.setAttribute("x2", x + "mm");
mainLine.setAttribute("y2", (marginY + (nY - 1) * spacing) + "mm");
mainLines.appendChild(mainLine);
// Lignes de subdivision (sauf pour la dernière section)
if (i < nX - 1 && subdivisions > 1) {
const subSpacing = spacing / subdivisions;
for (let s = 1; s < subdivisions; s++) {
const subX = x + s * subSpacing;
const subLine = document.createElementNS("http://www.w3.org/2000/svg", "line");
subLine.setAttribute("x1", subX + "mm");
subLine.setAttribute("y1", marginY + "mm");
subLine.setAttribute("x2", subX + "mm");
subLine.setAttribute("y2", (marginY + (nY - 1) * spacing) + "mm");
subLines.appendChild(subLine);
}
}
}
// Lignes horizontales
for (var j = 0; j < nY; j++) {
var y = marginY + j * spacing;
// Ligne principale
var mainLine = document.createElementNS("http://www.w3.org/2000/svg", "line");
mainLine.setAttribute("x1", marginX + "mm");
mainLine.setAttribute("y1", y + "mm");
mainLine.setAttribute("x2", (marginX + (nX - 1) * spacing) + "mm");
mainLine.setAttribute("y2", y + "mm");
mainLines.appendChild(mainLine);
// Lignes de subdivision (sauf pour la dernière section)
if (j < nY - 1 && subdivisions > 1) {
const subSpacing = spacing / subdivisions;
for (let s = 1; s < subdivisions; s++) {
const subY = y + s * subSpacing;
const subLine = document.createElementNS("http://www.w3.org/2000/svg", "line");
subLine.setAttribute("x1", marginX + "mm");
subLine.setAttribute("y1", subY + "mm");
subLine.setAttribute("x2", (marginX + (nX - 1) * spacing) + "mm");
subLine.setAttribute("y2", subY + "mm");
subLines.appendChild(subLine);
}
}
}
// Ajout des lignes au SVG (d'abord les subdivisions, puis les lignes principales)
svg.appendChild(subLines);
svg.appendChild(mainLines);
}
var spacingSlider = document.getElementById("spacing");
var subdivisionsSlider = document.getElementById("subdivisions");
var marginSlider = document.getElementById("margin");
var spacingValue = document.getElementById("spacingValue");
var subdivisionsValue = document.getElementById("subdivisionsValue");
var marginValue = document.getElementById("marginValue");
function updateGrid() {
var spacing = parseInt(spacingSlider.value);
var subdivisions = parseInt(subdivisionsSlider.value);
var pageMargin = parseInt(marginSlider.value);
spacingValue.textContent = spacing;
subdivisionsValue.textContent = subdivisions;
marginValue.textContent = pageMargin;
// Clear existing grid
while (svg.firstChild) {
svg.removeChild(svg.firstChild);
}
createGrid(spacing, subdivisions, pageMargin);
}
spacingSlider.addEventListener("input", updateGrid);
subdivisionsSlider.addEventListener("input", updateGrid);
marginSlider.addEventListener("input", updateGrid);
// Création initiale de la grille
createGrid(5, 1, 5);
})();
</script>
</body>
</html>