diff --git a/conways/clip.m b/conways/clip.m new file mode 100644 index 0000000..900e334 --- /dev/null +++ b/conways/clip.m @@ -0,0 +1,3 @@ +function R = clip(X, x_min, x_max) + R = (X >= x_max) & ~(X <= x_min); +end diff --git a/conways/conway.m b/conways/conway.m new file mode 100644 index 0000000..b81249f --- /dev/null +++ b/conways/conway.m @@ -0,0 +1,28 @@ +%%%% Conway's Game of Life. For MATLAB Seminar. James Ryan 2024 + +function conway(image_path) + if (~exist('image_path', 'var')) + close all; clear; clc; + imageIn = randi([0 1], 480, 640); + else % image path specified (eg: `conway("zaza.jpeg")`) + imageIn = importdata(image_path); + imageIn = 0.2989*imageIn(:,:,1) ... + + 0.5870*imageIn(:,:,2) ... + + 0.1140*imageIn(:,:,3); + + imageMean = cast(mean(imageIn),"uint8"); + imageIn = ~(clip(imageIn, imageMean - 1, ... + imageMean)); + end + + [imageLong imageLat] = size(imageIn); + + board = imshow(imageIn, InitialMagnification=imageLong); + pause(0.25); + % Run conways! + while true + pause(0.5); + board.CData = update(board.CData); + drawnow; + end +end diff --git a/conways/feedback/clip.m b/conways/feedback/clip.m new file mode 100644 index 0000000..900e334 --- /dev/null +++ b/conways/feedback/clip.m @@ -0,0 +1,3 @@ +function R = clip(X, x_min, x_max) + R = (X >= x_max) & ~(X <= x_min); +end diff --git a/conways/feedback/conway.m b/conways/feedback/conway.m new file mode 100644 index 0000000..61abd38 --- /dev/null +++ b/conways/feedback/conway.m @@ -0,0 +1,30 @@ +%%%% Conway's Game of Life. For MATLAB Seminar. James Ryan 2024 + % <+.5> + +function conway(image_path) + if (~exist('image_path', 'var')) + close all; clear; clc; + imageIn = randi([0 1], 480, 640); + else % image path specified (eg: `conway("zaza.jpeg")`) + imageIn = importdata(image_path); + imageIn = 0.2989*imageIn(:,:,1) ... + + 0.5870*imageIn(:,:,2) ... + + 0.1140*imageIn(:,:,3); + + imageMean = cast(mean(imageIn),"uint8"); + imageIn = ~(clip(imageIn, imageMean - 1, ... + imageMean)); + % <+.2> holy shit thank you + end + + [imageLong imageLat] = size(imageIn); + + board = imshow(imageIn, InitialMagnification=imageLong); + pause(0.25); + % Run conways! + while true + pause(0.5); + board.CData = update(board.CData); + drawnow; + end +end diff --git a/conways/feedback/growth.m b/conways/feedback/growth.m new file mode 100644 index 0000000..e2413c9 --- /dev/null +++ b/conways/feedback/growth.m @@ -0,0 +1,12 @@ +% growth function: given some matrix, determines whether a cell's neighbor +% should die or live. +% for any given entry u in matrix U: +% u == 3 --> u_iter = 1 +% u > 3 OR u < 2 --> u_iter = -1 +% else u = 0 +function U_iter = growth(U) + K = [1 1 1; 1 0 1; 1 1 1]; + + U_iter = conv2(U, K, 'same'); + U_iter = (U_iter == 3) - (U_iter > 3 | U_iter < 2); +end diff --git a/conways/feedback/update.m b/conways/feedback/update.m new file mode 100644 index 0000000..e8d6ff5 --- /dev/null +++ b/conways/feedback/update.m @@ -0,0 +1,3 @@ +function G_iter = update(G) + G_iter = clip(G + growth(G), 0, 1); +end diff --git a/conways/feedback/zaza.jpeg b/conways/feedback/zaza.jpeg new file mode 120000 index 0000000..1e2f8c1 --- /dev/null +++ b/conways/feedback/zaza.jpeg @@ -0,0 +1 @@ +../zaza.jpeg \ No newline at end of file diff --git a/conways/growth.m b/conways/growth.m new file mode 100644 index 0000000..e2413c9 --- /dev/null +++ b/conways/growth.m @@ -0,0 +1,12 @@ +% growth function: given some matrix, determines whether a cell's neighbor +% should die or live. +% for any given entry u in matrix U: +% u == 3 --> u_iter = 1 +% u > 3 OR u < 2 --> u_iter = -1 +% else u = 0 +function U_iter = growth(U) + K = [1 1 1; 1 0 1; 1 1 1]; + + U_iter = conv2(U, K, 'same'); + U_iter = (U_iter == 3) - (U_iter > 3 | U_iter < 2); +end diff --git a/conways/update.m b/conways/update.m new file mode 100644 index 0000000..e8d6ff5 --- /dev/null +++ b/conways/update.m @@ -0,0 +1,3 @@ +function G_iter = update(G) + G_iter = clip(G + growth(G), 0, 1); +end diff --git a/conways/zaza.jpeg b/conways/zaza.jpeg new file mode 100644 index 0000000..dd165e0 Binary files /dev/null and b/conways/zaza.jpeg differ diff --git a/handouts/210_EC.pdf b/handouts/210_EC.pdf new file mode 100644 index 0000000..2f29d8a Binary files /dev/null and b/handouts/210_EC.pdf differ diff --git a/handouts/ece210b-extra.pdf b/handouts/ece210b-extra.pdf new file mode 100644 index 0000000..29f7a7c Binary files /dev/null and b/handouts/ece210b-extra.pdf differ diff --git a/handouts/ece210b-hw01.pdf b/handouts/ece210b-hw01.pdf new file mode 100644 index 0000000..11fb9bd Binary files /dev/null and b/handouts/ece210b-hw01.pdf differ diff --git a/handouts/ece210b-hw02.pdf b/handouts/ece210b-hw02.pdf new file mode 100644 index 0000000..adc40be Binary files /dev/null and b/handouts/ece210b-hw02.pdf differ diff --git a/handouts/ece210b-hw03.pdf b/handouts/ece210b-hw03.pdf new file mode 100644 index 0000000..007f9f7 Binary files /dev/null and b/handouts/ece210b-hw03.pdf differ diff --git a/handouts/ece210b-hw04.pdf b/handouts/ece210b-hw04.pdf new file mode 100644 index 0000000..be89b78 Binary files /dev/null and b/handouts/ece210b-hw04.pdf differ diff --git a/handouts/ece210b-hw05.pdf b/handouts/ece210b-hw05.pdf new file mode 100644 index 0000000..4fff612 Binary files /dev/null and b/handouts/ece210b-hw05.pdf differ diff --git a/handouts/ece210b-hw06.pdf b/handouts/ece210b-hw06.pdf new file mode 100644 index 0000000..0f5ceb8 Binary files /dev/null and b/handouts/ece210b-hw06.pdf differ