-
Notifications
You must be signed in to change notification settings - Fork 4
/
IntroProgrammingIJ.html
804 lines (472 loc) · 17.5 KB
/
IntroProgrammingIJ.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Introduction to Data Analysis with Python</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/cci.css">
<link href="https://fonts.googleapis.com/css?family=Poppins" rel="stylesheet">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/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>
</head>
<body>
<div class="reveal">
<!-- Header logo -->
<!--img style="position:fixed;top:1em;right:1em;" src="img/logo_cci.png" width="15%"-->
<!-- Slide Title -->
<header style="position: absolute;top: 1em; left: 1em; z-index:10;"></header>
<div class="slides">
<section data-menu-title="Title">
<h2>Introduction to Programming in Fiji</h2>
<h4>Erick Martins Ratamero<br>Research Fellow</h4>
</section>
<section data-menu-title="Introduction" data-state="intro0">
<h2>Hello</h2>
<br/>
<br/>
<br/>
<a href="https://twitter.com/erickratamero" target="_blank">@erickratamero</a>
</section>
<section data-state="intro0">
<h2>
<b>Acknowledgements</b>
</h2>
<ul>
<li>Philo van Kemenade (<a href="twitter.com/phivk">@phivk</a>) from whom I "stole" the general structure of the presentation and some of the images </li>
<li>(original at <a href="https://slides.com/phivk/intro2python">https://slides.com/phivk/intro2python</a>)</li>
</ul>
</section>
<section data-state="intro0">
<h2>
<b>This Workshop</b>
</h2>
<ul>
<li>Building blocks</li>
<li>Putting the pieces together</li>
<li>Writing complete structures</li></ul>
</section>
<section data-state="intro0">
<h2>These Slides</h2>
<br/>
<br/>
<br/>
<a href="http://tiny.cc/introfiji" target="_blank">tiny.cc/introfiji</a>
<br/>
</section>
<section data-state="python">
<h2>Getting help</h2>
<p>Documentation at <a href="https://imagej.nih.gov/ij/developer/macro/functions.html" target="_blank">https://imagej.nih.gov/ij/developer/macro/functions.html</a> </p>
<p>Plugins -> Macro -> Record is your best friend</p>
</section>
<section data-menu-title="Building Blocks" data-state="bb">
<h1>
Building Blocks
</h1>
</section>
<section data-state="bb">
<h2>VARIABLES</h2>
<img src="img-py/var-name-red.png"/>
<br/>
<font color="#e06666">
<b><i>Variables</i></b></font> store <i>values</i> under a specified name
<br/>
</section>
<section data-state="bb">
<h2>VARIABLES</h2>
<img src="img-py/vars-nametags.png"/>
</section>
<section data-state="bb">
<h2>Assigning variables in Fiji</h2>
<pre><code>name = "Erick";
gender = "male";
height = 1.73; </code></pre>
</section>
<section data-state="bb">
<h2>Types of variables</h2>
<p>Variables can store values of different <b><i>types</i></b>:</p>
<p style="text-align: left;">
<font color="#e06666"><b>string</b></font> - a sequence of characters, comprising text
</p>
<pre><code>"a", "London", 'X', 'General Assembly'</code></pre>
<p style="text-align: left;">
<font color="#e06666"><b>int</b></font> - an integer, or whole number
</p>
<pre><code>1, 5, 9999, -7</code></pre>
<p style="text-align: left;">
<font color="#e06666"><b>float</b></font> - a floating point number (using a decimal point)
</p>
<pre><code>3.14, 1.68, 1.0</code></pre>
<p style="text-align: left;">
<font color="#e06666"><b>bool</b></font> - boolean; binary true or false values
</p>
<pre><code>true, false</code></pre>
</section>
<section data-state="bb">
<h2>Changing types</h2>
<p>'Casting' a variable to another type requires some of the <a href="https://imagej.nih.gov/ij/developer/macro/functions.html" target="_blank">built-in functions</a> we have mentioned.</p>
<p>
<br/>
</p>
<pre><code>a = parseInt("42");
b = parseFloat("1.69");
c = d2s(1.5333, 2);
print(c); //"1.53"
</code></pre>
<br/>
</section>
<section data-state="bb">
<h2>Exercise
</h2>
<br/>
Choose 4 things in this room and create variables of 4 different types based on them
</section>
<section data-state="bb">
<h2>Operators</h2>
<p>
<span class="s1">You can process the values in your variables by
<b>
<i>
<font color="#e06666">operators</font>
</i>
</b>:
</span>
</p>
<table width="100%" cellspacing="10" cellpadding="5" border="0">
<tbody>
<tr>
<td>
<font style="font-size: 30px;" color="#e06666">
<b>=</b>
</font>
</td>
<td>
<font style="font-size: 30px;">Assignment: assign a value to a variable </font>
</td>
</tr>
<tr>
<td>
<font style="font-size: 30px;" color="#e06666">
<b>==</b>
</font>
</td>
<td>
<font style="font-size: 30px;">Comparison: are two variables equal?</font>
</td>
</tr>
<tr>
<td>
<font style="font-size: 30px;" color="#e06666">
<b>!=</b>
</font>
</td>
<td>
<font style="font-size: 30px;">Comparison: are two variables not equal?</font>
</td>
</tr>
<tr>
<td>
<p class="p1">
<span class="s1">
<b>
<font style="font-size: 30px;" color="#e06666"><, >, <=, >=</font>
</b>
</span>
</p>
</td>
<td>
<font style="font-size: 30px;">Less-than, greater-than, less or equal, greater or equal</font>
</td>
</tr>
<tr>
<td>
<font style="font-size: 30px;" color="#e06666">
<b>+, -, *, /</b>
</font>
</td>
<td>
<font style="font-size: 30px;">Mathematical operators</font>
</td>
</tr>
<tr></tr>
<tr>
<td>
<font style="font-size: 30px;" color="#e06666">
<b>&& (and), || (or)</b>
</font>
</td>
<td>
<font style="font-size: 30px;">Logical operators</font>
</td>
</tr>
</tbody>
</table>
</section>
<section data-state="bb">
<h2>
Questions?
</h2>
</section>
<section data-state="bb">
<h2>Exercise</h2>
<p>
Create two
<font color="#e06666">
<i>string variables</i>
</font>:
</p>
<p>
<i>first</i> for your first name and <i>last</i> for your last name.
</p>
<p>
Can you make your full name by combining <i>first</i> and <i>last</i>?
</p>
<p>
<font color="#e06666">
(Cheating encouraged)
</font>
</p>
</section>
<section data-state="bb">
<h2>
Collections
</h2>
</section>
<section data-state="bb">
<h2>Collections of Values</h2>
Values can also be stored in a
<font color="#e06666">
<b>
<i>collection</i>
</b>
</font>:
<p><b>we'll only talk about the Array</b></p>
</section>
<section data-state="bb">
<h2>Arrays</h2>
<p>
We can store multiple values in an <b><i><font color="#e06666">array</font>:</i></b>
</p>
<pre><code class="python">>>> l = newArray(1,3,9,4,884328881);
>>> n = newArray('first', 'second', 'third', 'fourth');
>>> m = Array.concat(l,n);
>>> print(m[6]);
'second'</code></pre>
<br/>An array is a ordered sequence of items (between [...]) each with their own index.
<br/>
</section>
<section data-state="bb">
<h2>Some array examples
<br/>
</h2>
<pre><code class="java">
// This macro demonstrates how to use the Array.* functions.
requires("1.42j");
a1 = newArray(10, 5, 15, 2, 1.23456);
a2 = Array.copy(a1);
list("copy", a2);
a2 = Array.trim(a1, 2);
list("trim", a2);
Array.sort(a1);
list("sort", a1);
Array.getStatistics(a1, min, max, mean, std);
print("stats");
print(" min: "+min);
print(" max: "+max);
print(" mean: "+mean);
print(" std dev: "+std);
Array.fill(a1, -1);
list("fill", a1);
a1 = newArray("one", "two", "three", "four");
print("");
a2 = Array.copy(a1);
list("copy", a2);
a2 = Array.trim(a1, 2);
list("trim", a2);
Array.sort(a1);
list("sort", a1);
function list(name, a) {
print(name);
for (i=0; i< a.length; i++)
print(" "+a[i]);
}
</code></pre>
</section>
<section data-state="bb">
<h2>
Questions?
</h2>
</section>
<section data-menu-title="Putting the pieces together" data-state="pp">
<h1>
Putting the pieces together
</h1>
</section>
<section data-state="pp">
<h1>
Loops
</h1>
</section>
<section data-state="pp">
<h2>For Loops</h2>
<p>
You use <i><font color="#e06666">loops</font></i> to repeat a statement.
</p>
<p>
A <b><i><font color="#e06666">for-loop</font></i></b> is useful when you know how many times you want to repeat an action (e.g. for every item in a list)
</p>
<pre><code class="C">for (start; condition; increment){
do something
}</code></pre>
</section>
<section data-state="pp">
<h2>For Loops</h2>
<p>for example:
</p>
<pre><code class="C">ages = newArray(18, 21, 16, 12);
for(i=0; i< lengthOf(ages); i++){
print(ages[i]);
}
....
18
21
16
12 </code></pre>
</section>
<section data-state="pp">
<h2>While Loops</h2>
<p>A <b><i><font color="#e06666">while-loop</font></i></b> is useful when you don’t know when you want to stop looping yet.
</p>
<p>A while-loop statement checks a <i>condition</i> and loops until the condition is no longer satisfied.
</p>
<pre><code class="C">while (condition){
do something;
}
</code></pre>
</section>
<section data-state="pp">
<h2>While Loops</h2>
<p>for example:
</p>
<pre><code class="C">x = 5;
while(x > 0){
print("hooray!");
x = x - 1;
}
...
hooray!
hooray!
hooray!
hooray!
hooray!
</code></pre>
</section>
<section data-state="pp">
<h2>
Conditional Statements
</h2>
</section>
<section data-state="pp">
<h2>Conditional statements</h2>
<p><b><i><font color="#e06666">Conditional statements</font></i></b> enable you to deal with multiple options.
</p>
<p>
A part of your code is executed based on the truth value of a condition. You perform conditional checks with: <b>if, else</b>
</p>
<pre><code class="python">if(condition){
action
}
else{
final action
}</code></pre>
<pre><code class="C">age = 17;
if(age < 18){
print("no drinks for you");
}
...
no drinks for you</code></pre>
</section>
<section data-state="pp">
<h2>
Functions
</h2>
</section>
<section data-state="pp">
<h2>Functions</h2>
<p><font color="#e06666"><b><i>Functions</i></b></font> perform a collections of tasks, bundled under a specific name
</p>
<p>Take input <i>argument(s)</i>, execute statement(s), return output
</p>
<p>
Input and output can be of all different types
</p>
<pre><code class="C">name = "Erick Ratamero";
length = lengthOf(name);
print(length);</code></pre>
<br/>
</section>
<section data-state="pp">
<h2>Built in functions</h2>
<p>
<a href="https://imagej.nih.gov/ij/developer/macro/functions.html" target="_blank">https://imagej.nih.gov/ij/developer/macro/functions.html</a>
</p>
</section>
<section data-state="pp">
<h2>Functions</h2>
<p>You can also <i>define</i> your own functions like this:
</p>
<pre><code class="C">function function_name(argument(s)){
actions with argument(s)
return statement
}
</code></pre>
<pre><code class="C">function calculate(x, y, sigma){
factor = exp(-1.0*(pow(x,2)+pow(y,2))/(2*pow(sigma,2)));
return factor;
}</code></pre>
</section>
<section data-state="pp">
<h2>
Questions?
</h2>
</section>
</div>
<img style="position:fixed;bottom:1em;right:1em;" src="img/logo_WMS.jpg" width="10%">
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
controls: false,
slideNumber: true, //-- Added for development
dependencies: [
{ src: 'plugin/markdown/marked.js' },
{ src: 'plugin/markdown/markdown.js' },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/menu/menu.js' }
],
menu: {
hideMissingTitles: true,
themes: false,
transitions: false,
//markers: true,
numbers: true,
openButton: false,
titleSelector: 'span.menu-title'
}
});
</script>
</body>
</html>