Skip to content

Commit a404794

Browse files
committed
New example for rotating text
1 parent 58615bd commit a404794

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Text Rotation.
3+
*
4+
* Draws letters to the screen and rotates them at different angles.
5+
*/
6+
7+
PFont f;
8+
float angleRotate = 0.0;
9+
10+
void setup() {
11+
size(640, 360);
12+
background(0);
13+
14+
pixelDensity(2);
15+
16+
// Create the font from the .ttf file in the data folder
17+
f = createFont("SourceCodePro-Regular.ttf", 18);
18+
textFont(f);
19+
}
20+
21+
void draw() {
22+
background(0);
23+
24+
strokeWeight(1);
25+
stroke(153);
26+
27+
pushMatrix();
28+
float angle1 = radians(45);
29+
translate(100, 180);
30+
rotate(angle1);
31+
text("45 DEGREES", 0, 0);
32+
line(0, 0, 150, 0);
33+
popMatrix();
34+
35+
pushMatrix();
36+
float angle2 = radians(270);
37+
translate(200, 180);
38+
rotate(angle2);
39+
text("270 DEGREES", 0, 0);
40+
line(0, 0, 150, 0);
41+
popMatrix();
42+
43+
pushMatrix();
44+
translate(440, 180);
45+
rotate(radians(angleRotate));
46+
text(int(angleRotate) % 360 + " DEGREES", 0, 0);
47+
line(0, 0, 150, 0);
48+
popMatrix();
49+
50+
angleRotate += 0.25;
51+
52+
stroke(255, 0, 0);
53+
strokeWeight(4);
54+
point(100, 180);
55+
point(200, 180);
56+
point(440, 180);
57+
}
Binary file not shown.

content/examples_basics.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
<cat label="Typography">
121121
<ex p5="true" file="Letters.html">Letters</ex>
122122
<ex p5="true" file="Words.html">Words</ex>
123+
<ex p5="true" file="TextRotation.html">Text Rotation</ex>
123124
</cat>
124125
<cat label="Web">
125126
<ex p5="true" file="EmbeddedLinks.html">Embedded Links</ex>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Text Rotation.
3+
*
4+
* Draws letters to the screen and rotates them at different angles.
5+
*/
6+
7+
var f;
8+
var angleRotate = 0.0;
9+
10+
function setup() {
11+
var canvas = createCanvas(640, 360);
12+
canvas.parent("p5container");
13+
background(0);
14+
15+
// Create the font from the .ttf file in the data folder
16+
textFont("Source Code Pro", 18);
17+
}
18+
19+
function draw() {
20+
background(0);
21+
22+
23+
push();
24+
var angle1 = radians(45);
25+
translate(100, 180);
26+
rotate(angle1);
27+
noStroke();
28+
fill(255);
29+
text("45 DEGREES", 0, 0);
30+
strokeWeight(1);
31+
stroke(153);
32+
line(0, 0, 150, 0);
33+
pop();
34+
35+
push();
36+
var angle2 = radians(270);
37+
translate(200, 180);
38+
rotate(angle2);
39+
noStroke();
40+
fill(255);
41+
text("270 DEGREES", 0, 0);
42+
strokeWeight(1);
43+
stroke(153);
44+
line(0, 0, 150, 0);
45+
pop();
46+
47+
push();
48+
translate(440, 180);
49+
rotate(radians(angleRotate));
50+
noStroke();
51+
fill(255);
52+
text(int(angleRotate) % 360 + " DEGREES", 0, 0);
53+
strokeWeight(1);
54+
stroke(153);
55+
line(0, 0, 150, 0);
56+
pop();
57+
58+
angleRotate += 0.25;
59+
60+
stroke(255, 0, 0);
61+
strokeWeight(4);
62+
point(100, 180);
63+
point(200, 180);
64+
point(440, 180);
65+
}

0 commit comments

Comments
 (0)