added conways, handouts
This commit is contained in:
parent
f2fb36f646
commit
7ddb2379d7
3
conways/clip.m
Normal file
3
conways/clip.m
Normal file
@ -0,0 +1,3 @@
|
||||
function R = clip(X, x_min, x_max)
|
||||
R = (X >= x_max) & ~(X <= x_min);
|
||||
end
|
28
conways/conway.m
Normal file
28
conways/conway.m
Normal file
@ -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
|
3
conways/feedback/clip.m
Normal file
3
conways/feedback/clip.m
Normal file
@ -0,0 +1,3 @@
|
||||
function R = clip(X, x_min, x_max)
|
||||
R = (X >= x_max) & ~(X <= x_min);
|
||||
end
|
30
conways/feedback/conway.m
Normal file
30
conways/feedback/conway.m
Normal file
@ -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
|
12
conways/feedback/growth.m
Normal file
12
conways/feedback/growth.m
Normal file
@ -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
|
3
conways/feedback/update.m
Normal file
3
conways/feedback/update.m
Normal file
@ -0,0 +1,3 @@
|
||||
function G_iter = update(G)
|
||||
G_iter = clip(G + growth(G), 0, 1);
|
||||
end
|
1
conways/feedback/zaza.jpeg
Symbolic link
1
conways/feedback/zaza.jpeg
Symbolic link
@ -0,0 +1 @@
|
||||
../zaza.jpeg
|
12
conways/growth.m
Normal file
12
conways/growth.m
Normal file
@ -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
|
3
conways/update.m
Normal file
3
conways/update.m
Normal file
@ -0,0 +1,3 @@
|
||||
function G_iter = update(G)
|
||||
G_iter = clip(G + growth(G), 0, 1);
|
||||
end
|
BIN
conways/zaza.jpeg
Normal file
BIN
conways/zaza.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 46 KiB |
BIN
handouts/210_EC.pdf
Normal file
BIN
handouts/210_EC.pdf
Normal file
Binary file not shown.
BIN
handouts/ece210b-extra.pdf
Normal file
BIN
handouts/ece210b-extra.pdf
Normal file
Binary file not shown.
BIN
handouts/ece210b-hw01.pdf
Normal file
BIN
handouts/ece210b-hw01.pdf
Normal file
Binary file not shown.
BIN
handouts/ece210b-hw02.pdf
Normal file
BIN
handouts/ece210b-hw02.pdf
Normal file
Binary file not shown.
BIN
handouts/ece210b-hw03.pdf
Normal file
BIN
handouts/ece210b-hw03.pdf
Normal file
Binary file not shown.
BIN
handouts/ece210b-hw04.pdf
Normal file
BIN
handouts/ece210b-hw04.pdf
Normal file
Binary file not shown.
BIN
handouts/ece210b-hw05.pdf
Normal file
BIN
handouts/ece210b-hw05.pdf
Normal file
Binary file not shown.
BIN
handouts/ece210b-hw06.pdf
Normal file
BIN
handouts/ece210b-hw06.pdf
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user