How do I create an x by y grid and how do I color each grid section?

24 ビュー (過去 30 日間)
Ryan Burrows
Ryan Burrows 2018 年 10 月 26 日
コメント済み: Walter Roberson 2018 年 10 月 27 日
I am currently creating the game stratego on matlab. I am not sure how to physically create the game board though. I am looking for something quite simple, just a grid pattern where I can manually color each square whatever color I want. Please help
  5 件のコメント
Walter Roberson
Walter Roberson 2018 年 10 月 27 日
pcolor() is really surf() followed by view(2).
pcolor() interpolates face colors according to the surrounding four nodes.
If you want face colors directly you should be using imagesc()

サインインしてコメントする。

採用された回答

jonas
jonas 2018 年 10 月 26 日
編集済み: jonas 2018 年 10 月 26 日
You could use pcolor, here's a checkerboard example
A = repmat([repmat([1 0],1,10);repmat([0 1],1,10)],10,1)
pcolor(A)
You can build a color palette like this
cmap = [0 0 0;1 1 1;1 0 0;0 0 1;0 1 0];
colormap(cmap)
Now you can paint with these colors, by assigning values between, for example, 0 and 4 (you have 5 colors).
A(10,10)=4;
Makes the square at [10;10] green

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by