forked from joeyklee/aloha-processing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1775 lines (1444 loc) · 73.1 KB
/
index.html
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Processing Workshop</title>
<meta name="description" content="Data Vis Talk">
<meta name="author" content="Joey Lee">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="assets/style/reveal.css">
<link rel="stylesheet" href="assets/style/night.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="assets/style/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match(/print-pdf/gi) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName('head')[0].appendChild(link);
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1><em>Aloha Processing!</em> </h1>
<h2>An introduction to Processing</h2>
<p>
<small>
<a href="http://www.jk-lee.com" target='_blank'>Joey Lee</a> /
<a href="https://github.com/joeyklee" target='_blank'>@joeyklee</a>
</small>
<br />
<small>Geographical Sciences 472: Data Visualization & Cartography</small>
</p>
</section>
<section>
<h1>Examples of Things Made in Processing</h1>
</section>
<section>
<h1>Aaron Koblin</h1>
<h2>Flight Patterns + Senseable City Lab</h2>
</section>
<section>
<iframe width="960" height="700" src="https://www.youtube.com/embed/4v4XxlfVk3o" frameborder="0" allowfullscreen></iframe>
</section>
<section>
<h1>Pedro Cruz</h1>
<h2>Portugal's Blood Vessels</h2>
</section>
<section>
<iframe src="https://player.vimeo.com/video/31031656" width="960" height="700" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</section>
<section>
<h1>Ben Mandeberg</h1>
<h2>Midi Mirror</h2>
</section>
<section>
<iframe src="https://player.vimeo.com/video/40382774" width="960" height="700" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<p><a href="https://vimeo.com/40382774">Tommy Wiseau Midi Mirror demo</a> from <a href="https://vimeo.com/benmandeberg">Ben Mandeberg</a> on <a href="https://vimeo.com">Vimeo</a>.</p>
</section>
<section>
<h1>Jer Thorp</h1>
<h2>Science, Art, & Design</h2>
</section>
<section>
<iframe width="960" height="700" src="https://www.youtube.com/embed/-q6aA5qdCzU" frameborder="0" allowfullscreen></iframe>
</section>
<section>
<h1>Christopher Pietsch, Gunnar Friedrich, Pierre La Baume, David Ikuye and Luis Grass</h1>
<h2>LiquidData </h2>
</section>
<section>
<iframe src="https://player.vimeo.com/video/43120464" width="960" height="700" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</section>
<section>
<h1>Casey Reas</h1>
<h2>A Mathematical Theory of Communication </h2>
</section>
<section>
<iframe src="https://player.vimeo.com/video/136017050?color=99cd4f" width="960" height="700" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<p><a href="https://vimeo.com/136017050">Eyeo 2015 – Casey Reas</a> from <a href="https://vimeo.com/eyeofestival">Eyeo Festival // INSTINT</a> on <a href="https://vimeo.com">Vimeo</a>.</p>
<p>See: 36:40</p>
</section>
<section>
<h1>MIT Senseable City Lab</h1>
<h2>Live Singapore! </h2>
</section>
<section>
<iframe width="960" height="700" src="https://www.youtube.com/embed/2aEPkyOBtRo" frameborder="0" allowfullscreen></iframe>
</section>
<section>
<h1>Pixtil</h1>
<h2>Generative Textiles</h2>
</section>
<section>
<img src="http://www.creativeapplications.net/wp-content/uploads/2015/05/pixtil_03.jpg">
<center> Delphine Saltet and Olivier Paradeise, Pixtil (http://www.creativeapplications.net/processing/pixtil-weaving-generative-patterns-using-traditional-textile-techniques/)</center>
</section>
<section>
<h1>Benedikt Groß</h1>
<h2>Metrography</h2>
</section>
<section>
<img src="http://www.looksgood.de/log/wp-content/uploads/2012/02/metrography_black_1.png">
<center> Benedikt Groß, Metrography (http://benedikt-gross.de/log/2012/02/metrography-london-tube-map-to-large-scale-collective-mental-map/)</center>
</section>
<section>
<h1>Now let's learn!</h1>
<h2>All of the documentation can be found at the repo here: <a href="https://github.com/joeyklee/aloha-processing">https://github.com/joeyklee/aloha-processing</a></h2>
</section>
<section>
<h3>What You'll Need</h3>
<ul>
<li>Download <a href="https://processing.org/download/">Processing</a> for your specific operating system.</li>
<li>The confidence, curiosity and enthusiasm to learn and the drive to teach yourself and the patience to help those around you.</li>
</ul>
</section>
<section>
<h3>What you need to do:</h3>
<ul>
<li>Do the <a href="http://hello.processing.org/">One hour of code</a> with Dan Shiffman to get familiar with Processing and the concepts we'll dive further into today.</li>
</ul>
</section>
<section>
<p>In this workshop we will be introduced to <a href="https://processing.org">Processing</a> - a programming language and environment developed "to promote literacy within the visual arts and visual literacy within technology". Processing is used across a variety of communities but has had particular success within the art and design community (and data visualization community) for its strength in generating visual and interactive output.
</section>
<section>
We will will use Processing to:</p>
<ol>
<li>Become familiar with the fundamental concepts of programming visual outputs with code.</li>
<li>Build our confidence in using code as a material/tool to turn our ideas into something tangible.</li>
<li>Learn about the process of deconstructing tasks into modular steps (don't worry if this doesn't mean anything to you yet!).</li>
<li>Get introduced to the ways in which code can create accountability for the visualization process.</li>
</ol>
</section>
<section>
<p>We will use the concepts learned in this workshop throughout the rest of the course to learn how to systematically approach data visualization problems and explore other tools and methods of producing visuals with data.</p>
</section>
<section>
<h3>Learning Outcome / Assignment:</h3>
<p> For your assignment choose <strong>one</strong> these three Proun drawings by El Lissitzsky.</p>
<p><img width="250" src="https://upload.wikimedia.org/wikipedia/commons/8/8f/Lissitzky_Proun_93.jpg" alt="" />
<img width="250" src="http://www.mpsaz.org/dobson/staff/hxfinzer/academic_decathlon/art_reproductions_2012_2013/images/14_proun.jpg" alt="" />
<img width="250" src="https://upload.wikimedia.org/wikipedia/commons/b/b9/Lazar_El_Lissitzky_-_Kestnermappe_Proun,_Rob._Levnis_and_Chapman_GmbH_Hannover_-5_-_Google_Art_Project.jpg" alt="" /></p>
<p>You will develop <strong>2 versions</strong>:</p>
<ol>
<li>The first will be a version as close to the image as possible.</li>
<li>The second will be a <strong>remix</strong> of the image - playing with the composition through the use of alternative colors, strokeWeight, object positioning, etc. - save your code in a separate file!</li>
</ol>
</section>
<section>
<h2>S2. Introduction to Processing</h2>
</section>
<section>
<p>"Processing is for writing software to make images, animations, and interactions. The idea is to write a single line of code, and have a circle show up on the screen. Add a few more lines of code, and the circle follows the mouse. Another line of code, and the circle changes color when the mouse is pressed. We call this sketching with code. You write one line, then add another, then another, and so on. The result is a program created one piece at a time. " - Casey Reas & Ben Fry, <em>Getting Started With Processing</em></p>
</section>
<section>
<p>"Processing relates software concepts to principles of visual form, motion, and interaction. It integrates a programming language, development environment, and teaching methodology into a unified system. Processing was created to teach fundamentals of computer programming within a visual context, to serve as a software sketchbook, and to be used as a production tool. Students, artists, design professionals, and researchers use it for learning, prototyping, and production" - Casey Reas, <em>Processing, A Programming Handbook for Visual Designers and Artists</em></p>
</section>
<section>
<p>"Software is a unique medium with unique qualities... Every programming language is a distinct material...Sketching is necessary for the development of ideas...Programming is not just for engineers..." - Casey Reas, <em>Processing, A Programming Handbook for Visual Designers and Artists</em></p>
</section>
<section>
<p>In the last 10 years, Processing has become one of the most used tools for creating visual outputs (among other things). It has a wide usership in many communities, one being the data visualization community because it allows for flexible and custom exploration of data, it is powerful in dealing with large datasets, and has a relatively friendly syntax and large user community.</p>
</section>
<section>
<h2>S3. The Community</h2>
<p>The ethos of Processing is to create an open environment to engage with technology. There's an active community of artists, designers, and scientists from all different domains helping to develop the language & make Processing more accessible. If you continue to work in Processing, you'll definitely find lots of examples and support to help turn your ideas into something tangible. These are some photos of the people that are helping to make Processing bigger, better, and easier to learn.
<p><img width="250" src="https://pbs.twimg.com/profile_images/54057404/Photo_14.jpg"> </br>
<a href="http://shiffman.net/">Dan Shiffman</a></p>
</section>
<section>
<h2>S4. The Processing Environment</h2>
</section>
<section>
<h3>The Text Editor & Display Window</h3>
<p>The Processing Development Environment (IDE) looks like this:
<img width="500" src="assets/img/pde.png" alt="" /></p>
<center>Credits: "Getting started with Processing" - Fry </center>
<p>PDE Elements:</p>
</section>
<section>
<h1>S5. Getting Started</h1>
</section>
<section>
<p>If you did the <a href="http://hello.processing.org/">One hour of code</a> with Dan Shiffman, you should now be familiar with with these fundamental concepts in the context of a <strong>static sketch</strong> and <strong>dynamic sketch</strong>:</p>
</section>
<section>
<h2>A static sketch</h2>
<p><img src="assets/img/basic-sketch.png" alt="" /></p>
<p>A static program runs sequentially, from top to bottom.</p>
</section>
<section>
<ul>
<li>
<p>setting the <strong>canvas size</strong> using the <strong>size()</strong> function.</p>
<pre><code>
// size();
size(700, 500);
</code></pre></li>
<li>
<p>setting the <strong>background color</strong> of a canvas using <strong>RGB</strong> color parameters.</p>
<pre><code>
// background();
background(217, 250, 240);
</code></pre></li>
<li>
<p>adding <strong>color</strong> to <strong>shapes</strong> and <strong>strokes</strong> using <strong>RGB</strong> color parameters to the following <strong>functions</strong>:</p>
<pre><code>
// fill();
fill(255, 137, 82);
// stroke();
stroke(255, 82, 82);
</code></pre></li>
</ul>
</section>
<section>
<ul>
<li>
<p>drawing <strong>shapes</strong> using <strong>functions</strong> and using <strong>screen coordinates values</strong> to set the shapes. Some Processing shape functions you know are:</p>
<pre><code>
// ellipse();
ellipse(width * 0.25, height * 0.25, 50, 50);
// rect();
rect(width * 0.5, height * 0.5, 50, 50);
</code></pre></li>
</ul>
</section>
<section>
<h2>A dynamic sketch</h2>
<p>A dynamic sketch makes use of Processing's <strong>setup()</strong> and <strong>draw()</strong> functions to structure a logic for <strong>interaction</strong> and <strong>animations</strong>.</p>
<p>Together they look something like this:</p>
<p><img width="600" src="assets/img/setup&draw.png" alt="" /></p>
<center> credits: "Learning Processing" - Shiffman </center>
</section>
<section>
<p><strong>A Responsive Ellipse-drawing tool</strong><br>
<img width="250" src="assets/img/dynamic-sketch.png" alt="" /></p>
<p>Run this in your PDE and we'll break it down line-by-line:</p>
<pre><code>
void setup() {
size(700, 500);
background(255);
}
void draw() {
if (mousePressed) {
background(255);
}
ellipse(mouseX,mouseY,40,40);
}
</code></pre>
</section>
<section>
<p><strong>setup()</strong> Set up your sketch by calling all statements that only need to occur once during your drawing - this might be things like the size() of your canvas.</p>
<p><strong>draw()</strong> Continuously repeat the statements within this function - continually evaluate the statements in a loop, over and over and over, forever.</p>
<p>Here, the computer is continually asking, "is the mousePressed?", "how about now?", "and now?", "how about now?", for infinity. When you finally press the mouse, it will change the background color to white and "erase" the ellipses you've drawn, but only as long as your mouse is pressed.</p>
<p><strong>NOTE</strong>: <strong>mousePressed</strong> is equal to <strong>TRUE</strong> whenever your mouse is pressed and <strong>FALSE</strong> otherwise. Therefore it is a <strong>variable</strong> which stores a <strong>boolean</strong> of either <strong>TRUE</strong> or <strong>FALSE</strong> in response to a mouse <strong>event</strong>.</p>
</section>
<section>
<p>What the above example shows is:</p>
<ul>
<li>our basic understanding of <strong>conditional</strong> statement using the <strong>if statement</strong>.</li>
<li>the use of <strong>variables</strong> - in this case the <strong>in-built</strong> variables called <strong>mouseX</strong>, <strong>mouseY</strong>, and <strong>mousePressed</strong>.</li>
</ul>
</section>
<section>
<h2>Dynamic Sketch Remix</h2>
<p>Take 5 minutes now and remix the code from the "dynamic sketch":</p>
<ul>
<li>add 1 more new shape that responds to your <strong>mouseX</strong> and <strong>mouseY</strong> and</li>
<li>Use the conditional to affect the color of the shapes by the <strong>mousePressed</strong>.</li>
</ul>
</section>
<section>
<p>Here's a sample of a sketch that tracks the speed of your mouse in the X and Y direction and maps it to colored bars:</p>
<img width = "250" src="assets/img/mouse-speed.png" alt="" />
<pre><code>
void setup() {
size( 700, 500);
smooth();
noStroke();
}
void draw() {
if (mousePressed) {
background(255);
fill( 0, 0, 255);
} else {
// create a random fill with transparency
fill(random(100), random(255), random(255), random(50, 100));
}
// make a variable for the radius which calculates a radius for the ellipse based on the speed of the mouse
// mouseX is the current screen location of the mouse
// pmouseX is the previous screen location of the mouse
// thus the absolute difference of the current location minus the previous location is the speed
int speedX = abs(mouseX-pmouseX );
int speedY = abs(mouseY-pmouseY );
// responsive bar
rect(width*0.25, height*0.75, 30, speedY*-2);
rect(width*0.25+30, height*0.75+15, speedX*2, 30);
}
</code></pre>
</section>
<section>
<h3>Saving your work</h3>
<p>When you're programming, saving your work is super important. Let's save our first program.</p>
<ul>
<li>From the PDE, go to "save..."</li>
<li>Navigate to a folder called "Sketches" (or create one if there isn't already)</li>
<li>Save your work with a name that doesn't include spaces. The convention is to use "camel case" ,like:
<ul>
<li>"myFirstSketch"</li>
</ul>
</li>
</ul>
<p>You'll notice when you save your "sketch" the file type will be added to the end of whatever you called your progam. So if you named your project "myFirstSketch", you will see in your folder "myFirstSketch.pde". The ".pde" is the processing file type (similar to when you see a .csv or .py or .r or .xls, etc etc).</p>
</section>
<section>
<h1><center> <em>How do you feel? Empowered? Confused? Excited? </em> </center></h1>
</section>
<section>
<h1><center> <em>Let's learn more! </em> </center></h1>
</section>
<section>
<h1>S6: Fundamentals</h1>
</section>
<section>
<h2>S6.1: Structure</h2>
<p>Voltaire once said, "If you wish to converse with me, define your terms". In this section, we're going to define a number of terms so we can all speak the same language when refering to the different elements of a program.</p>
</section>
<section>
<p>What you should learn and remember from this section are:</p>
<ol>
<li>comments</li>
<li>printing</li>
<li><strong>functions</strong> can have a number of <strong>parameters</strong> that are passed <strong>arguments</strong>
<ul>
<li>e.g. size() is a <strong>function</strong> that has two <strong>parameters</strong>: <strong>width</strong> and <strong>height</strong>. We can pass 2 numbers in like 700 and 500 which are the <strong>arguments</strong>.</li>
</ul>
</li>
<li>expressions & statements</li>
</ol>
</section>
<section>
<h3>S6.1.1: comments</h3>
<p>Remember seeing those double forward slashes (//) in the programs above? these are called <strong>comments</strong> - they are invisible to the computer and do not get evaluated by the computer.</p>
<p>These are useful when programming to help you (and others who read your code) keep track of what's happening in your program and allows you to test different functions and statements.</p>
</section>
<section>
<p>We can use two methods of comments:</p>
<p>For <strong>single line comments</strong>: //</p>
<pre><code>
// fill(255, 0, 0);
// ellipse(250, 100, 50, 50);
</code></pre>
<p>OR</p>
<p><strong>Block comments</strong> for multiple lines of code:</p>
<pre><code>
/*
fill(255, 0, 0);
ellipse(250, 100, 50, 50);
*/
</code></pre>
</section>
<section>
<p>TIP: We can use comments to help us structure our logical steps when writing code. For example:</p>
<pre><code>
// first set the canvas size
// next set the canvas color
// next draw a circle in the center of the canvas. Since the canvas is 700 pixels wide and 500 pixels tall, the center must be at (350, 250).
// next draw a triangle about 1/3 the width of the canvas
// ...
</code></pre>
</section>
<section>
<h3>S6.1.2: Printing to the console:</h3>
<p>The most basic way to get feedback from a computer is by "printing to the console." We can do this by using the <em>print()</em> or <em>println()</em> functions. The difference between <em>print()</em> and <em>println()</em> is that <em>print()</em> does not start a new line break after each function call. If this seems like a bunch of hogwash, try out the examples below :)</p>
<p><em>print()</em></p>
<pre><code>
print("Hello World");
print("My name is Joey");
print("It is raining outside");
</code></pre>
<p><em>println()</em></p>
<pre><code>
println("Hello World");
println("My name is Joey");
println("It is raining outside");
</code></pre>
</section>
<section>
<h3>S6.1.3: functions</h3>
<p><strong>Functions</strong> allow you to draw shapes, set colors, calculate numbers, and to execute many other types of actions. A function’s name is usually a lowercase word followed by parentheses. Functions have <strong>parameters</strong> in which you fill in with <strong>arguments</strong>.</p>
<p>The comma-separated elements between the parentheses are the <strong>parameters</strong> that you fill with <strong>arguments</strong>, and they affect the way the function works. Some functions have no parameters and others have many. This program demonstrates the size() and background() functions.
cont.</p>
</section>
<section>
<pre><code>
// The size function has two parameters.
//The first sets the width of the display window and the second sets the height
// the arguements here are 200, 200
size(200, 200);
// This version of the background function has one parameter.
// It sets the gray value for the background of the display window in the range of 0 (black) to 255 (white)
// the argument here is 102
background(102);
</code></pre>
</section>
<section>
<h3>S6.1.4: expressions & statements:</h3>
<p>Using an analogy to human languages, a software expression is like a phrase. Software expressions are often combinations of operators such as +, *, and / that operate on the values to their left and right. A software expression can be as basic as a single number or can be a long combination of elements. An expression always has a value, determined by evaluating its contents.</p>
<p>Expressions</p>
<pre><code>
// expression // value
10 < 50 true
// expression // value
5*3 15
</code></pre>
</section>
<section>
<p>A Statement</p>
<p>A statement - composed of a set of expressions - is like a sentence that gets translated into machine readable code that instructs the computer to do something. For example we see that the collection of these expressions makes a statement (below) that tell the computer to do a particular task.</p>
<pre><code>
size(200, 200); // Runs the size() function to set the canvas size
int x; // Declares a new variable x as an integer type
x = 102; // Assigns the value 102 to the variable x
background(x); // Runs the background() function
</code></pre>
</section>
<section>
<h2>S6.2: Shape</h2>
<p>Let's dive into how we can draw shapes with Processing.</p>
</section>
<section>
<h3>S6.2.1: coordinates</h3>
<p>The coordinate space of a Processing canvas is set using the <em>size()</em> function. The parameters for <em>width</em> and <em>height</em> sets the number of pixels that will be in the <em>x-coordinate</em> space and <em>y-coordinate</em> space.</p>
<p>The Processing canvas starts at (0,0) at the top-left corner of the canvas.</p>
<p><img width="500" src="assets/img/coordinate-space.png" alt="" /></p>
<center>Credits: "A Programming Handbook for Visual Artists and Designers" - Reas & Fry</center>
<!-- <p>*for your reference: Processing also comes with a number of other renderers including a 3D renderer, but we won't get into this now - just something to think about!</p> -->
</section>
<section>
<h3>S6.2.2: primitives</h3>
<p>Processing's primitive shapes are the bread and butter of making visual output with code. As we saw in our first program in which we made a square and circle with one function, there are other primitive shapes that we can use. These primitives are listed below:</p>
</section>
<section>
<p><strong>point(x,y)</strong></p>
<p><img src="assets/img/point.png" alt="" /></p>
<p>Experiment: draw 5 points in a row on your screen</p>
</section>
<section>
<p><strong>line(x1, y1, x2, y2)</strong></p>
<p><img src="assets/img/line.png" alt="" /></p>
<p>Experiment: draw 3 "x's" on your screen using lines</p>
</section>
<section>
<p><strong>triangle(x1, y1, x2, y2, x3, y3)</strong></p>
<p><img src="assets/img/triangle.png" alt="" /></p>
<p>Experiment: draw 3 triangles if different sizes slightly overlapping eachother</p>
</section>
<section>
<p><strong>quad(x1, y1, x2, y2, x3, y3, x4, y4)</strong></p>
<p><img src="assets/img/quad.png" alt="" /></p>
<p>Experiment: draw 1 funky quadrilateral</p>
</section>
<section>
<p><strong>rect(x, y, width, height)</strong></p>
<p><img src="assets/img/rect.png" alt="" /></p>
<p>Experiment: draw 2 rectangles with exactly the same arguements - use the rectMode(CENTER) function for 1 of the rectangles and see what it does.</p>
</section>
<section>
<p><strong>ellipse(x, y, width, height)</strong></p>
<p><img src="assets/img/ellipse.png" alt="" /></p>
<p>Experiment: draw a "bullseye" target with 6 ellipses. Play will fill colors to change the color of each ellipse.</p>
</section>
<section>
<p><strong>bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2)</strong></p>
<p><img src="assets/img/bezier.png" alt="" /></p>
<p>Experiment: draw 1 bezier curve to see how it works.</p>
</section>
<section>
<h3>S6.2.3: properties</h3>
<p>In Processing we can change the properties of the shapes to affect their fill color, stroke color, and drawing mode. Let's go over a few of them here:</p>
<h4>Basic Color properties</h4>
<p><em>If we use RGB color space</em>:</p>
<pre><code>
* value1 = red (between 0 - 255)
* value2 = green (between 0 - 255)
* value3 = blue (between 0 - 255)
* alpha = transparency (between 0 - 100)
</code></pre>
</section>
<section>
<p><em>Processing comes with a handy Color tool to select colors</em></p>
<p><img src="assets/img/colortool.png" alt="" /></p>
</section>
<section>
<p><strong>fill()</strong></p>
<pre><code>
fill(value1, value2, value3)
fill(value1, value2, value3, alpha)
</code></pre>
</section>
<section>
<p><strong>noFill()</strong></p>
<p>Use the <em>noFill()</em> function if you don't want a fill color</p>
<pre><code>
size(700, 500);
// with fill
fill(242, 172, 20);
ellipse(width*0.25, height * 0.5, 150, 150);
// no fill
noFill();
ellipse(width*0.75, height * 0.5, 150, 150);
</code></pre>
<p><img width="400" src="assets/img/nofill.png" alt="" /></p>
<p>Experiment: make your own example using noFill() with another set of shapes like a triangle and rectangle.</p>
</section>
<section>
<h4>Basic Stroke Properties</h4>
<p><strong>stroke()</strong></p>
<pre><code>
stroke(value1, value2, value3)
stroke(value1, value2, value3, alpha)
</code></pre>
</section>
<section>
<p><strong>noStroke()</strong></p>
<p>Use the <em>noStroke()</em> function if you don't want a stroke color</p>
<pre><code>
size(700, 500);
// no stroke
noStroke();
fill(242, 172, 20);
ellipse(width*0.25, height * 0.5, 150, 150);
// black stroke
stroke(0);
fill(242, 172, 20);
ellipse(width*0.75, height * 0.5, 150, 150);
</code></pre>
<p><img width="250"src="assets/img/nostroke.png" alt="" /></p>
</section>
<section>
<p><strong>strokeWeight()</strong></p>
<p>You can use the <em>strokeWeight()</em> function to change the width of the stroke.</p>
<pre><code>
size(700, 500);
strokeWeight(1);
line(width*0.25, height * 0.25, width*0.75, height * 0.25);
strokeWeight(3);
line(width*0.25, height * 0.35, width*0.75, height * 0.35);
strokeWeight(5);
line(width*0.25, height * 0.45, width*0.75, height * 0.45);
strokeWeight(7);
line(width*0.25, height * 0.55, width*0.75, height * 0.55);
strokeWeight(9);
line(width*0.25, height * 0.65, width*0.75, height * 0.65);
strokeWeight(10);
line(width*0.25, height * 0.75, width*0.75, height * 0.75);
</code></pre>
</section>
<section>
<p><img src="assets/img/strokeWeight.png" alt="" /></p>
<p>Experiment: make your own example using strokeWeight(), noFill(), stroke(), and noStroke() with a set of slightly overlapping rectangles.</p>
</section>
<section>
<h3>S6.2.4: custom shapes</h3>
<p>In Processing we can create our own shapes from a series of vertices. We can do by sandwiching a series of <em>vertex(x,y)</em> functions in between the <em>beginShape()</em> and <em>endShape()</em> functions.</p>
</section>
<section>
<p>For example - let's make a funny fish:</p>
<p><img src="assets/img/processing_beginShape-01.png" alt="" /></p>
</section>
<section>
<pre><code>
size(700, 500);
strokeWeight(4);
// right eye
fill(255);
ellipse(width*0.6, height*0.2, 50, 100);
fill(0);
ellipse(width*0.6, height*0.15, 25, 50);
// body
fill(255);
stroke(0);
beginShape();
vertex(width*0.25, height*0.75);
vertex(width*0.35, height*0.15);
vertex(width*0.45, height*0.25);
vertex(width*0.65, height*0.25);
vertex(width*0.55, height*0.85);
endShape(CLOSE);
// left eye
fill(255);
ellipse(width*0.5, height*0.35, 50, 100);
fill(0);
ellipse(width*0.5, height*0.3, 25, 50);
</code></pre>
</section>
<section>
<h1>S7: Data & Variables & Computation</h1>
</section>
<section>
<p>What is data? Data could be anything from the time of day, the location of a bus stop, the color of your hair, and even the location of your mouse on the screen and the keys you pressed to login to your email. In general, data often consists of measurements of physical characteristics whether it be a digital photo of your dog or the precipitation in Vancouver.</p>
</section>
<section>
<p>Processing can store, modify, and manipulate many different kinds of data, including numbers, letters, words, colors, images, fonts, and boolean values (true, false).</p>
<p>One of the key features of programming is the ability to store values and/or data to variables. Below are the main data types in Processing - and programming in general - and examples of how to store them to a variable in Processing. NOTE: Processing (the java version) is strongly typed and thus we must declare what the data type will be when assigning data to a variable. If this sounds crazy, have a look at the examples below :)</p>
</section>
<section>
<p>In the following sections we are going to quick go through:</p>
<ol>
<li>Arithmetic and mathematical functions</li>
<li>Relational expressions (remember, what does the crocodile want to eat?)</li>
<li>Variables & data types</li>
</ol>
</section>
<section>
<h2>Arithmetic & Functions</h2>
<p>Here's a list of the main arithmetic functions in Processing. There are others including functions for making exponents, doing square roots, making log transformations, etc - for a full list check the Processing Documentation.</p>
<pre><code>
+ (add)
- (subtract)
* (multiply)
/ (divide)
% (modulus)
() (parentheses)
++ (increment)
-- (decrement)
+= (add assign)
-= (subtract assign)
*= (multiply assign)
/= (divide assign)
- (negation)
ceil()
floor()
round()
min()
max()
</code></pre>
</section>
<section>
<h2>Relational Expressions</h2>
<p> A relational expression is made up of two values that are compared with a relational operator. In Processing, two values can be compared with relational operators as follows:</p>
<pre><code>
Expression Evaluation
3> 5 false
3< 5 true
5< 3 false
5> 3 true
</code></pre>
</section>
<section>
<p>In Processing, we have these relational operators at our fingertips in order to evaluate truthy or falsy values:</p>
<pre><code>
Operator Meaning
> greater than
< less than
>= greater than or equal to <= less than or equal to
== equivalent to
!= not equivalent to
</code></pre>
</section>
<section>
<h2>Variables and Data Types</h2>
<p>In the earlier examples we saw the use of variables like <strong>mouseX</strong>, <strong>mouseY</strong> , and <strong>mousePressed</strong>. What we know about these variables is that they <strong>store data</strong> like the <strong>location of the x- and y- coordinate of the mouse</strong> or if the <strong>mouse is pressed</strong>.</p>
</section>
<section>
<p>In programming languages, we can <strong>define our own variables to store data</strong> and in turn work with that data running calculations, statistics and/or visualizing it.</p>
<p>Before we work through an example here are the <strong>fundamental data types</strong> in Processing, <strong>how to declare them</strong>, and <strong>assign them a value</strong>:</p>
</section>
<section>
<p><strong><em>NOTE: remember our fancy dancy println() function? For each of the following examples, pass each of these variables into the println() function to show the value of the variables in the PDE console. Otherwise, your code will run, but you won't get any feedback ;)</em></strong></p>
</section>
<section>
<ul>
<li><h3>integer numbers</h3>
<ul>
<li>Integers are whole numbers such as 12, -120, 8, and 934.</li>
<li>Processing represents integer data with the "int" data type. With variables, we can:</li>
<li><p><strong>Assign single values to a variable:</strong></p>
<pre><code>
// x is an integer equal to 10
int x = 10;
</code></pre>
<ul>
<li>This reads: <strong>x</strong> is an <strong>integer</strong> equal to <strong>10</strong></li>
</ul>
</li>
</ul>
</section>
<section>
<ul>
<li><p><strong>Assign an expression to a variable:</strong></p>
<pre><code>
// y is an integer equal to 5 times 5
int y = 5 * 5;
</code></pre>
<ul>
<li>This reads: <strong>y</strong> is an <strong>integer</strong> equal to the product of <strong>5 and 5</strong></li>
</ul>
</li>
</ul>
</section>
<section>
<ul>
<li><p><strong>Assign an expression involving other variables to a variable:</strong></p>
<pre><code>
// z is an integer equal to the sum of x and y
int z = x - y ;
</code></pre>
<ul>
<li>This reads: <strong>z</strong> is an <strong>integer</strong> equal to the sum of <strong>variable x and variable y</strong></li>
</ul>
</li>
</ul>
</li>
</ul>
</section>
<section>
<ul>
<li><h3>floating numbers</h3>
<ul>
<li>Floating-point numbers have a decimal point for creating fractions of whole numbers such as 12.8, -120.75, 8.125, and 934.82736.</li>
<li>Processing represents floating-point data with the "float" data type:</li>
<li><p><strong>Assign single values to a variable:</strong></p>
<pre><code>
// i is an floating number equal to 95.7
float i = 10.5
</code></pre></li>
</ul>
</section>
<section>
<ul>
<li><p><strong>Assign an expression to a variable:</strong></p>
<pre><code>
// j is an float equal to 5.0 times 5.0
float j = 5.0 * 5.0;
</code></pre></li>
</ul>
</section>
<section>
<ul>
<li><p><strong>Assign an expression involving other variables to a variable:</strong></p>
<pre><code>
// k is a normalized difference between variables i and j
float k = i - j / i + j ;
</code></pre>
<ul>
<li>This reads: <strong>k</strong> is an <strong>float</strong> equal to the difference of <strong>variable i and variable j</strong> divided by the sum of <strong>variable i and varible j</strong></li>
</ul>
</ul>
</section>
<section>
<ul>
<li><h3>strings</h3>
<ul>
<li>A string is a sequence of characters.</li>
<li>Processing represents string data with the "String" data type:</li>
<li><p><strong>Assign single values to a variable:</strong></p>
<pre><code>
// exclamation is a string containing the sentence "hello world!"
String exclamation = "My Gosh! ";
</code></pre></li>
</ul>
</section>
<section>
<ul>
<li><p><strong>Assign an expression to a variable:</strong></p>
<pre><code>
// task is a String expression "Hey yo"
String task = "I'm" + " " + "programming.";
</code></pre>
<ul>
<li>you can combine strings using the "+" operator.</li>
</ul>
</li>
</ul>
</section>
<section>
<ul>
<li><p><strong>Assign an expression involving other variables to a variable:</strong></p>
<pre><code>
// realization is a string concatenating the variable exclamation and task
String realization = exclamation + task;
// use the text() function to render the text to the canvas
text(realization, width/2, height/2);
</code></pre></li>
</ul>
</li>
</ul>
</section>
<section>
<h2>Boolean</h2>
<ul>
<li>A boolean is a true or false value. (remember the <strong>mousePressed</strong> value?)</li>
<li>Processing represents boolean data with the "boolean" data type:</li>
<li><p><strong>Assign single values to a variable:</strong></p>
<pre><code>
// trueLove is a a boolean type set to true
boolean trueLove = true;
</code></pre></li>
</ul>
</section>
<section>
<ul>
<li><p><strong>Assign an expression to a variable:</strong></p>
<pre><code>
// falseExpression is a boolean type showing false for the expression 10 is less than 5
boolean falseExpression = 10 < 5;
</code></pre>
<ul>