• Remix
  • Share
  • New Entry

on 28 Nov 2023
  • 6
  • 9
  • 0
  • 0
  • 1341
drawframe(1);
Write your drawframe function below
function drawframe(f)
rng(2,"twister")
numRows = 15;
numCols = 15;
cuboidWidth = 1;
cuboidDepth = rand();
figure;
for row = 1:numRows
for col = 1:numCols
xPos = col * (cuboidWidth + 0.2);
yPos = row * (cuboidDepth + 0.2);
zPos = 0;
cuboidHeight = rand();
vertices = [
xPos, yPos, zPos;
xPos + cuboidWidth, yPos, zPos;
xPos + cuboidWidth, yPos + cuboidDepth, zPos;
xPos, yPos + cuboidDepth, zPos;
xPos, yPos, zPos + cuboidHeight+f/10;
xPos + cuboidWidth, yPos, zPos + cuboidHeight+f/20;
xPos + cuboidWidth, yPos + cuboidDepth, zPos + cuboidHeight+f/10;
xPos, yPos + cuboidDepth, zPos + cuboidHeight+f/20;
];
faces = [
1, 2, 3, 4;
5, 6, 7, 8;
1, 5, 8, 4;
2, 6, 7, 3;
1, 2, 6, 5;
3, 4, 8, 7;
];
buildingColors = [
0.6, 0.6, 0.6;
0.2, 0.2, 0.2;
0.3, 0.3, 0.3;
0.05, 0.05, 0.05;
0.1, 0.1, 0.1;
0.4, 0.4, 0.4];
Colors = buildingColors(mod(row-1, size(buildingColors, 1)) + 1, :);
patch('Vertices', vertices, 'Faces', faces, 'FaceColor', Colors, 'EdgeColor', 'k');
end
end
streetWidth = 0.2;
for row = 1:numRows + 1
for col = 1:numCols
xPos = col * (cuboidWidth + 0.2);
yPos = row * (cuboidDepth + 0.2) - streetWidth/2;
zPos = 0;
streetVertices = [
xPos, yPos, zPos;
xPos + cuboidWidth, yPos, zPos;
xPos + cuboidWidth, yPos + streetWidth, zPos;
xPos, yPos + streetWidth, zPos;
];
streetFaces = [
1, 2, 3, 4;
];
patch('Vertices', streetVertices, 'Faces', streetFaces, 'FaceColor', [0.5, 0.5, 0.5], 'EdgeColor', 'k');
end
end
axis equal;
axis off
grid on;
view(3);
rotate3d on;
zoom(2);
end
Animation
Remix Tree