File tree 1 file changed +62
-0
lines changed
src/data/examples/en/19_Typography 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * @name Text Rotation
3
+ * @description Draws letters to the screen and rotates them at different angles.
4
+ * (ported from https://processing.org/examples/textrotation.html)
5
+ */
6
+
7
+ let font ,
8
+ fontsize = 32 ;
9
+
10
+ let angleRotate = 0.0 ;
11
+
12
+ function setup ( ) {
13
+ createCanvas ( 710 , 400 ) ;
14
+ background ( 0 ) ;
15
+
16
+ // Ensure the .ttf or .otf font stored in the assets directory
17
+ // is loaded before setup() and draw() are called
18
+ font = loadFont ( 'assets/SourceSansPro-Regular.otf' ) ;
19
+
20
+ // Set text characteristics
21
+ textFont ( font ) ;
22
+ }
23
+
24
+ function draw ( ) {
25
+ background ( 0 ) ;
26
+
27
+ strokeWeight ( 1 ) ;
28
+ stroke ( 153 ) ;
29
+
30
+ push ( ) ;
31
+ let angle1 = radians ( 45 ) ;
32
+ translate ( 100 , 180 ) ;
33
+ rotate ( angle1 ) ;
34
+ // Draw the letter to the screen
35
+ text ( "45 DEGREES" , 0 , 0 ) ;
36
+ line ( 0 , 0 , 150 , 0 ) ;
37
+ pop ( ) ;
38
+
39
+ push ( ) ;
40
+ let angle2 = radians ( 270 ) ;
41
+ translate ( 200 , 180 ) ;
42
+ rotate ( angle2 ) ;
43
+ // Draw the letter to the screen
44
+ text ( "270 DEGREES" , 0 , 0 ) ;
45
+ line ( 0 , 0 , 150 , 0 ) ;
46
+ pop ( ) ;
47
+
48
+ push ( ) ;
49
+ translate ( 440 , 180 ) ;
50
+ rotate ( radians ( angleRotate ) ) ;
51
+ text ( int ( angleRotate ) % 360 + " DEGREES " , 0 , 0 ) ;
52
+ line ( 0 , 0 , 150 , 0 ) ;
53
+ pop ( ) ;
54
+
55
+ angleRotate += 0.25 ;
56
+
57
+ stroke ( 255 , 0 , 0 ) ;
58
+ strokeWeight ( 4 ) ;
59
+ point ( 100 , 180 ) ;
60
+ point ( 200 , 180 ) ;
61
+ point ( 440 , 180 ) ;
62
+ }
You can’t perform that action at this time.
0 commit comments