-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcroissant.js
More file actions
54 lines (44 loc) · 1.15 KB
/
croissant.js
File metadata and controls
54 lines (44 loc) · 1.15 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
/**
* An croissant word layout to represent France.
* @class
*/
class Croissant extends WordShape {
/**
* @constructor
* @param {string} words - words displayed in a croissant shape
*
* @returns {void}
*/
constructor(words) {
super(words);
}
/**
* Displays the words in a croissant layout
*
* @returns {void}
*/
display() {
push();
fill(232, 199, 137);
textAlign(CENTER, CENTER);
let baseRadius = 120; //base radius of crescent
let arcStart = PI/4;
let arcEnd = 3*PI/4;
let angleStep = (arcEnd - arcStart) / (this.words.length - 1);
for (let i = 0; i < this.words.length; i++) {
textSize(12 * this.sizeFactors[i]);
let angle = arcStart + i * angleStep;
//slight bulge in the middle of the croissant
let radiusVariation = 10 * sin((PI * i) / this.words.length);
let radius = baseRadius + radiusVariation;
let x = radius * cos(angle);
let y = radius * sin(angle);
push();
translate(x, y);
rotate(angle); //aligning the words in an arc shape
text(this.words[i], 0, 0);
pop();
}
pop();
}
}