Mercurial > hg > medcouple
comparison talk/code/showalgo.m @ 66:916349600c4b
algorithm-visualisation code
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Wed, 18 May 2016 17:03:43 -0400 |
parents | |
children | 1aa38f4846e0 |
comparison
equal
deleted
inserted
replaced
65:364a0c9df823 | 66:916349600c4b |
---|---|
1 H = load("H"); | |
2 L = load("L") + 1; | |
3 R = load("R") + 1; | |
4 P = load("P") + 1; | |
5 Q = load("Q") + 1; | |
6 Ptot = load("Ptotal"); | |
7 Qtot = load("Qtotal"); | |
8 remaining = load("remaining"); | |
9 mc = load("mc"); | |
10 jackpot = load("jackpot"); | |
11 Am = load("Am"); | |
12 Am(end+1) = mc; | |
13 | |
14 colidx = 1:columns(H); | |
15 | |
16 origH = repmat((H+1)/2, 1, 1, 3); | |
17 | |
18 for iter = 1:length(Am) | |
19 ## Reset the image | |
20 imgH = origH; | |
21 | |
22 ## Make greater-than red | |
23 red = imgH(:,:,1); | |
24 red(colidx < L(iter, :)') = 1; | |
25 imgH(:, :, 1) = red; | |
26 | |
27 ## Make less-than blue | |
28 blue = imgH(:,:,3); | |
29 blue(colidx > R(iter, :)') = 1; | |
30 imgH(:, :, 3) = blue; | |
31 | |
32 imshow(imgH); | |
33 pause | |
34 | |
35 ## Make the guess yellow | |
36 [i,j] = find(Am(iter) == H); | |
37 imgH(i,j,1) = imgH(i,j,2) = 1; | |
38 imgH(i,j,3) = 0; | |
39 | |
40 imshow(imgH); | |
41 pause | |
42 | |
43 if iter == length(Am) | |
44 break; | |
45 endif | |
46 | |
47 ## Check the left side | |
48 imgLeft = imgH; | |
49 red = imgH(:, :, 1); | |
50 green = imgH(:, :, 2); | |
51 blue = imgH(:, :, 3); | |
52 | |
53 idx = colidx > P(iter,:)'; | |
54 | |
55 ## Brighten blue | |
56 blue(idx) = 1; | |
57 | |
58 ## Dim red and green | |
59 red(idx) .*= 0.5; | |
60 green(idx) .*= 0.5; | |
61 | |
62 imgLeft(:,:,2) = green; | |
63 imgLeft(:,:,3) = blue; | |
64 | |
65 ## Make the guess yellow again | |
66 [i,j] = find(Am(iter) == H); | |
67 imgH(i,j,1) = imgH(i,j,2) = 1; | |
68 imgH(i,j,3) = 0; | |
69 | |
70 imshow(imgLeft); | |
71 pause | |
72 | |
73 ## Check the right side | |
74 imgRight = imgH; | |
75 red = imgH(:, :, 1); | |
76 green = imgH(:, :, 2); | |
77 blue = imgH(:, :, 3); | |
78 | |
79 idx = colidx < Q(iter,:)'; | |
80 | |
81 ## Brighten red | |
82 blue(idx) = 1; | |
83 | |
84 ## Dim blue and green | |
85 blue(idx) .*= 0.5; | |
86 green(idx) .*= 0.5; | |
87 | |
88 imgRight(:,:,2) = green; | |
89 imgRight(:,:,3) = blue; | |
90 | |
91 ## Make the guess yellow again | |
92 [i,j] = find(Am(iter) == H); | |
93 imgH(i,j,1) = imgH(i,j,2) = 1; | |
94 imgH(i,j,3) = 0; | |
95 | |
96 imshow(imgRight); | |
97 pause | |
98 | |
99 endfor |