Skip to content

Commit 48515fa

Browse files
committed
fix everything
1 parent 96d85b3 commit 48515fa

32 files changed

+3064
-3013
lines changed

notebooks/week1/abstraction.jl

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ macro bind(def, element)
1313
end
1414
end
1515

16+
# ╔═╡ da1d65a0-ec42-11ea-0141-334c9eeeb035
17+
begin
18+
using Pkg
19+
Pkg.activate(mktempdir())
20+
Pkg.add(["PlutoUI", "Images", "ImageMagick"])
21+
using PlutoUI
22+
using Images
23+
end
24+
1625
# ╔═╡ 5ef51c3a-70a7-11eb-2023-31113399a57f
1726
html"""
1827
<div style="
@@ -85,17 +94,6 @@ The goal of this section is to introduce you to the notion of abstraction. You c
8594
Before we get lost talking about the foundations of number theory, I will present you with a few examples that represent one to me.
8695
"
8796

88-
# ╔═╡ 0504ac94-70ee-11eb-1c4e-977d9e7d35c9
89-
one = [
90-
1,
91-
1.0,
92-
"one",
93-
1//1,
94-
oneimage,
95-
[1 0; 0 1],
96-
corgi,
97-
]
98-
9997
# ╔═╡ 6fcac482-70ee-11eb-0b80-ff41c708053b
10098
md"Each of the items in this list is a specific, or **_specialized_** representation of _one_:
10199
1. as an integer
@@ -111,9 +109,6 @@ Of course, these are just a few examples of _one_. People have been representing
111109
The difference between these ones to me is clear. In fact, I just articulated it to you. Now, let's turn to how a computer sees _one_ differently based on what I type.
112110
"
113111

114-
# ╔═╡ 0b1668ba-ec42-11ea-3e50-ed97c5b17ced
115-
computer_ones = typeof.(one)
116-
117112
# ╔═╡ 9ebc079a-70f0-11eb-07d9-f9e80f3f4584
118113
md"So to a computer, all of these are different types."
119114

@@ -122,26 +117,6 @@ md"### What is a collection of _one_s?
122117
123118
Now, I want to make a collection of ones for some reason. Below is a way for you to experiment building this collection with different _one_s. As you do this experiment, I want you to look at what stays in the same in the Julia output, and what doesn't."
124119

125-
# ╔═╡ b2239b96-70ef-11eb-0b85-21ecab25dc9f
126-
begin
127-
one_keys = ["1", "1.0", "one", "1//1", "Cute One", "2x2 Identity", "One Corgi"]
128-
selections = one_keys .=> one_keys
129-
lookup_element = Dict(one_keys .=> one)
130-
md"$(@bind element_key Select(selections))"
131-
end
132-
133-
# ╔═╡ 4251f668-70aa-11eb-3d89-35f8d53b7d9b
134-
# your chosen one
135-
element = lookup_element[element_key]
136-
137-
# ╔═╡ f1568d10-ec41-11ea-3dd2-a9cb273ce5b8
138-
#its type
139-
typeof(element)
140-
141-
# ╔═╡ ab02d850-ec41-11ea-10b2-a1b600b12658
142-
# a 3x4 array of this one.
143-
array = fill(element,3,4)
144-
145120
# ╔═╡ f6886d90-70ed-11eb-07c4-471ee267e7c1
146121
md"""
147122
Before we even look at the output, I am amazed that this code even ran. Are you telling me that the computer doesn't care which _one_ I am using in my array?
@@ -182,12 +157,6 @@ begin
182157
"""
183158
end
184159

185-
# ╔═╡ 5363a400-ec44-11ea-284e-d13a8872551c
186-
begin
187-
one_image_array = fill(oneimage,3,4)
188-
insert(corgi, one_image_array, i, j)
189-
end
190-
191160
# ╔═╡ 71ac08ea-7145-11eb-237d-5506adfb9533
192161
begin
193162
one_number_array = fill(1,3,4)
@@ -208,15 +177,6 @@ md"""
208177
## Appendix
209178
"""
210179

211-
# ╔═╡ da1d65a0-ec42-11ea-0141-334c9eeeb035
212-
begin
213-
using Pkg
214-
Pkg.activate(mktempdir())
215-
Pkg.add(["PlutoUI", "Images", "ImageMagick"])
216-
using PlutoUI
217-
using Images
218-
end
219-
220180
# ╔═╡ 1a2a9000-ec43-11ea-3f39-8312ea286a92
221181
begin
222182
oneimage = load(download("https://gallery.yopriceville.com/var/albums/Free-Clipart-Pictures/Decorative-Numbers/Cute_Number_One_PNG_Clipart_Image.png?m=1437447301"))
@@ -225,6 +185,46 @@ begin
225185
end
226186

227187

188+
# ╔═╡ 0504ac94-70ee-11eb-1c4e-977d9e7d35c9
189+
one = [
190+
1,
191+
1.0,
192+
"one",
193+
1//1,
194+
oneimage,
195+
[1 0; 0 1],
196+
corgi,
197+
]
198+
199+
# ╔═╡ 0b1668ba-ec42-11ea-3e50-ed97c5b17ced
200+
computer_ones = typeof.(one)
201+
202+
# ╔═╡ b2239b96-70ef-11eb-0b85-21ecab25dc9f
203+
begin
204+
one_keys = ["1", "1.0", "one", "1//1", "Cute One", "2x2 Identity", "One Corgi"]
205+
selections = one_keys .=> one_keys
206+
lookup_element = Dict(one_keys .=> one)
207+
md"$(@bind element_key Select(selections))"
208+
end
209+
210+
# ╔═╡ 4251f668-70aa-11eb-3d89-35f8d53b7d9b
211+
# your chosen one
212+
element = lookup_element[element_key]
213+
214+
# ╔═╡ f1568d10-ec41-11ea-3dd2-a9cb273ce5b8
215+
#its type
216+
typeof(element)
217+
218+
# ╔═╡ ab02d850-ec41-11ea-10b2-a1b600b12658
219+
# a 3x4 array of this one.
220+
array = fill(element,3,4)
221+
222+
# ╔═╡ 5363a400-ec44-11ea-284e-d13a8872551c
223+
begin
224+
one_image_array = fill(oneimage,3,4)
225+
insert(corgi, one_image_array, i, j)
226+
end
227+
228228
# ╔═╡ Cell order:
229229
# ╟─5ef51c3a-70a7-11eb-2023-31113399a57f
230230
# ╟─60ae819a-70a7-11eb-31d4-750c7f5dc6ca

notebooks/week1/images.jl

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ macro bind(def, element)
1313
end
1414
end
1515

16+
# ╔═╡ 74b008f6-ed6b-11ea-291f-b3791d6d1b35
17+
begin
18+
import Pkg
19+
Pkg.activate(mktempdir())
20+
Pkg.add([
21+
Pkg.PackageSpec(name="ImageIO", version="0.5"),
22+
Pkg.PackageSpec(name="ImageShow", version="0.2"),
23+
Pkg.PackageSpec(name="FileIO", version="1.6"),
24+
Pkg.PackageSpec(name="PNGFiles", version="0.3.6"),
25+
Pkg.PackageSpec(name="Colors", version="0.12"),
26+
Pkg.PackageSpec(name="ColorVectorSpace", version="0.8"),
27+
Pkg.PackageSpec(name="PlutoUI", version="0.7"),
28+
Pkg.PackageSpec(name="HypertextLiteral", version="0.5")
29+
])
30+
31+
using Colors, ColorVectorSpace, ImageShow, FileIO
32+
using PlutoUI
33+
using HypertextLiteral
34+
end
35+
36+
# ╔═╡ 71a1e08a-6abc-48d5-b177-5184dbdd76a8
37+
filter!(LOAD_PATH) do path
38+
path != "@v#.#"
39+
end;
40+
1641
# ╔═╡ e91d7926-ec6e-41e7-aba2-9dca333c8aa5
1742
html"""
1843
<div style="
@@ -74,31 +99,6 @@ md"""
7499
_When running this notebook for the first time, this could take up to 15 minutes. Hang in there!_
75100
"""
76101

77-
# ╔═╡ 74b008f6-ed6b-11ea-291f-b3791d6d1b35
78-
begin
79-
import Pkg
80-
Pkg.activate(mktempdir())
81-
Pkg.add([
82-
Pkg.PackageSpec(name="ImageIO", version="0.5"),
83-
Pkg.PackageSpec(name="ImageShow", version="0.2"),
84-
Pkg.PackageSpec(name="FileIO", version="1.6"),
85-
Pkg.PackageSpec(name="PNGFiles", version="0.3.6"),
86-
Pkg.PackageSpec(name="Colors", version="0.12"),
87-
Pkg.PackageSpec(name="ColorVectorSpace", version="0.8"),
88-
Pkg.PackageSpec(name="PlutoUI", version="0.7"),
89-
Pkg.PackageSpec(name="HypertextLiteral", version="0.5")
90-
])
91-
92-
using Colors, ColorVectorSpace, ImageShow, FileIO
93-
using PlutoUI
94-
using HypertextLiteral
95-
end
96-
97-
# ╔═╡ 71a1e08a-6abc-48d5-b177-5184dbdd76a8
98-
filter!(LOAD_PATH) do path
99-
path != "@v#.#"
100-
end;
101-
102102
# ╔═╡ ca1b507e-6017-11eb-34e6-6b85cd189002
103103
md"""
104104
# Images as examples of data all around us
@@ -272,18 +272,6 @@ Even more fun is to use your own webcam. Try pressing the enable button below. T
272272
press the camera to capture an image. Kind of fun to keep pressing the button as you move your hand etc.
273273
"""
274274

275-
# ╔═╡ d6742ea0-1106-4f3c-a5b8-a31a48d33f19
276-
@bind webcam_data1 camera_input()
277-
278-
# ╔═╡ 1d7375b7-7ea6-4d67-ab73-1c69d6b8b87f
279-
myface1 = process_raw_camera_data(webcam_data1);
280-
281-
# ╔═╡ 6224c74b-8915-4983-abf0-30e6ba04a46d
282-
[
283-
myface1 myface1[ : , end:-1:1]
284-
myface1[end:-1:1, :] myface1[end:-1:1, end:-1:1]
285-
]
286-
287275
# ╔═╡ cef1a95a-64c6-11eb-15e7-636a3621d727
288276
md"""
289277
## Inspecting your data
@@ -343,12 +331,6 @@ md"""
343331
We can also use variables as indices...
344332
"""
345333

346-
# ╔═╡ 94b77934-713e-11eb-18cf-c5dc5e7afc5b
347-
row_i,col_i
348-
349-
# ╔═╡ ff762861-b186-4eb0-9582-0ce66ca10f60
350-
philip[row_i, col_i]
351-
352334
# ╔═╡ 13844ebf-52c4-47e9-bda4-106a02fad9d7
353335
md"""
354336
...and these variables can be controlled by sliders!
@@ -360,6 +342,12 @@ md"""
360342
# ╔═╡ 6511a498-7ac9-445b-9c15-ec02d09783fe
361343
@bind col_i Slider(1:size(philip)[2], show_value=true)
362344

345+
# ╔═╡ 94b77934-713e-11eb-18cf-c5dc5e7afc5b
346+
row_i,col_i
347+
348+
# ╔═╡ ff762861-b186-4eb0-9582-0ce66ca10f60
349+
philip[row_i, col_i]
350+
363351
# ╔═╡ c9ed950c-dcd9-4296-a431-ee0f36d5b557
364352
md"""
365353
### Locations in an image: Range indexing
@@ -565,29 +553,6 @@ function create_bar()
565553
return missing
566554
end
567555

568-
# ╔═╡ d862fb16-edf1-11ea-36ec-615d521e6bc0
569-
colored_line(create_bar())
570-
571-
# ╔═╡ e3394c8a-edf0-11ea-1bb8-619f7abb6881
572-
if !@isdefined(create_bar)
573-
not_defined(:create_bar)
574-
else
575-
let
576-
result = create_bar()
577-
if ismissing(result)
578-
still_missing()
579-
elseif isnothing(result)
580-
keep_working(md"Did you forget to write `return`?")
581-
elseif !(result isa Vector) || length(result) != 100
582-
keep_working(md"The result should be a `Vector` with 100 elements.")
583-
elseif result[[1,50,100]] != [0,1,0]
584-
keep_working()
585-
else
586-
correct()
587-
end
588-
end
589-
end
590-
591556
# ╔═╡ 693af19c-64cc-11eb-31f3-57ab2fbae597
592557
md"""
593558
## Reducing the size of an image
@@ -791,18 +756,6 @@ md"""
791756
We can do the same to create different size matrices, by creating two sliders, one for reds and one for greens. Try it out!
792757
"""
793758

794-
# ╔═╡ 2a94a2cf-b697-4b0b-afd0-af2e35af2bb1
795-
@bind webcam_data camera_input()
796-
797-
# ╔═╡ 3e0ece65-b8a7-4be7-ae44-6d7210c2e15b
798-
myface = process_raw_camera_data(webcam_data);
799-
800-
# ╔═╡ 4ee18bee-13e6-4478-b2ca-ab66100e57ec
801-
[
802-
myface myface[ : , end:-1:1]
803-
myface[end:-1:1, :] myface[end:-1:1, end:-1:1]
804-
]
805-
806759
# ╔═╡ ace86c8a-60ee-11eb-34ef-93c54abc7b1a
807760
md"""
808761
# Summary
@@ -821,15 +774,15 @@ md"""
821774
----
822775
"""
823776

824-
# ╔═╡ 45815734-ee0a-11ea-2982-595e1fc0e7b1
825-
bigbreak
826-
827777
# ╔═╡ 5da8cbe8-eded-11ea-2e43-c5b7cc71e133
828778
begin
829779
colored_line(x::Vector{<:Real}) = Gray.(Float64.((hcat(x)')))
830780
colored_line(x::Any) = nothing
831781
end
832782

783+
# ╔═╡ d862fb16-edf1-11ea-36ec-615d521e6bc0
784+
colored_line(create_bar())
785+
833786
# ╔═╡ e074560a-601b-11eb-340e-47acd64f03b2
834787
hint(text) = Markdown.MD(Markdown.Admonition("hint", "Hint", [text]))
835788

@@ -851,9 +804,32 @@ correct(text=rand(yays)) = Markdown.MD(Markdown.Admonition("correct", "Got it!",
851804
# ╔═╡ e0a4fc10-601b-11eb-211d-03570aca2726
852805
not_defined(variable_name) = Markdown.MD(Markdown.Admonition("danger", "Oopsie!", [md"Make sure that you define a variable called **$(Markdown.Code(string(variable_name)))**"]))
853806

807+
# ╔═╡ e3394c8a-edf0-11ea-1bb8-619f7abb6881
808+
if !@isdefined(create_bar)
809+
not_defined(:create_bar)
810+
else
811+
let
812+
result = create_bar()
813+
if ismissing(result)
814+
still_missing()
815+
elseif isnothing(result)
816+
keep_working(md"Did you forget to write `return`?")
817+
elseif !(result isa Vector) || length(result) != 100
818+
keep_working(md"The result should be a `Vector` with 100 elements.")
819+
elseif result[[1,50,100]] != [0,1,0]
820+
keep_working()
821+
else
822+
correct()
823+
end
824+
end
825+
end
826+
854827
# ╔═╡ e0a6031c-601b-11eb-27a5-65140dd92897
855828
bigbreak = html"<br><br><br><br><br>";
856829

830+
# ╔═╡ 45815734-ee0a-11ea-2982-595e1fc0e7b1
831+
bigbreak
832+
857833
# ╔═╡ e0b15582-601b-11eb-26d6-bbf708933bc8
858834
function camera_input(;max_size=150, default_url="https://i.imgur.com/SUmi94P.png")
859835
"""
@@ -1058,6 +1034,12 @@ function camera_input(;max_size=150, default_url="https://i.imgur.com/SUmi94P.pn
10581034
""" |> HTML
10591035
end
10601036

1037+
# ╔═╡ d6742ea0-1106-4f3c-a5b8-a31a48d33f19
1038+
@bind webcam_data1 camera_input()
1039+
1040+
# ╔═╡ 2a94a2cf-b697-4b0b-afd0-af2e35af2bb1
1041+
@bind webcam_data camera_input()
1042+
10611043
# ╔═╡ e891fce0-601b-11eb-383b-bde5b128822e
10621044

10631045
function process_raw_camera_data(raw_camera_data)
@@ -1093,6 +1075,24 @@ function process_raw_camera_data(raw_camera_data)
10931075
RGB.(reds, greens, blues)
10941076
end
10951077

1078+
# ╔═╡ 1d7375b7-7ea6-4d67-ab73-1c69d6b8b87f
1079+
myface1 = process_raw_camera_data(webcam_data1);
1080+
1081+
# ╔═╡ 6224c74b-8915-4983-abf0-30e6ba04a46d
1082+
[
1083+
myface1 myface1[ : , end:-1:1]
1084+
myface1[end:-1:1, :] myface1[end:-1:1, end:-1:1]
1085+
]
1086+
1087+
# ╔═╡ 3e0ece65-b8a7-4be7-ae44-6d7210c2e15b
1088+
myface = process_raw_camera_data(webcam_data);
1089+
1090+
# ╔═╡ 4ee18bee-13e6-4478-b2ca-ab66100e57ec
1091+
[
1092+
myface myface[ : , end:-1:1]
1093+
myface[end:-1:1, :] myface[end:-1:1, end:-1:1]
1094+
]
1095+
10961096
# ╔═╡ 3ef77236-1867-4d02-8af2-ff4777fcd6d9
10971097
exercise_css = html"""
10981098
<style>

0 commit comments

Comments
 (0)