-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardDisplayer.m
59 lines (49 loc) · 1.51 KB
/
CardDisplayer.m
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
function CardDisplayer
skin = "Fish";
deck = "deck2";
cardCount = 40;
folder = "cards\" + skin + "\" + deck;
cards = zeros(1653, 1653, 3, 40);
randomList = randperm(cardCount);
cardList = randomList(1:3);
for cardIndex = 1:cardCount
img = imread(folder + "\" + int2str(cardIndex) + ".png");
img(:, 1 : 5, :) = 0;
img(:, end-4 : end, :) = 0;
cards(:,:,:,cardIndex) = double(imresize(img, 0.25)) / 255;
disp("Loading cards:" + cardIndex + "/" + cardCount);
end
fig = uifigure(1);
fig.Position = [0 0 1972 658];
windowSize = fig.Position(3:4);
uiimg = uiimage(fig, "Position",[0 0 windowSize]);
reshuffleBtn = uibutton(fig,'push',...
'Position',[0 0 100 25],...
'Text', "Reshuffle",...
'ButtonPushedFcn', @(button, event) showNewCards() ...
);
addBtn = uibutton(fig,'push',...
'Position',[125 0 100 25],...
'Text', "Add",...
'ButtonPushedFcn', @(button, event) addCard() ...
);
function addCard()
cardList = randomList(1:min(length(cardList) + 1, cardCount));
showCards();
end
function showNewCards()
randomList = randperm(cardCount);
cardList = randomList(1:3);
showCards();
end
function showCards()
img = [];
uiimg.Position = [0 0 fig.Position(3:4)];
reshuffleBtn.Position = [0 0 100 25];
addBtn.Position = [125 0 100 25];
for cardShowingIndex = 1:length(cardList)
img = [img cards(:,:,:,cardList(cardShowingIndex))];
end
uiimg.ImageSource = img;
end
end