Olympic rings with Wolfram Language's UnityLink​
​by Kotaro Okazaki
The Tokyo Olympic Games are about to begin. The athletes from more than 200 countries will compete. My family has some tickets, but we will be watching the games at home.

Init

In[]:=
Needs["UnityLink`"]​​UnityOpen["OlympicRings"]

Generating Regions

In[]:=
(*domino*)​​width=2.5;​​height=5.0;​​depth=1.0;​​coordinates={{0,0},{width,0},{width,depth},{0,depth}};​​polygon=Polygon[coordinates];​​line=BoundaryMeshRegion[{{0},{height}},Point[{{1},{2}}]];​​regionDomino=RegionBoundary[RegionProduct[BoundaryMeshRegion[polygon],line]];
In[]:=
(*floor*)​​width=60.0;​​height=1.0;​​depth=85.0;​​coordinates={{0,0},{width,0},{width,depth},{0,depth}};​​polygon=Polygon[coordinates];​​line=BoundaryMeshRegion[{{0},{height}},Point[{{1},{2}}]];​​regionFloor=RegionBoundary[RegionProduct[BoundaryMeshRegion[polygon],line]];

Preparing the Project

In[]:=
(*Directories*)​​CreateUnityAssetDirectory[{"Meshes","Materials","Scenes","Prefabs"}];
In[]:=
(*Meshes*)​​meshDomino=CreateUnityMesh[File["Meshes/domino"],regionDomino];​​meshFloor=CreateUnityMesh[File["Meshes/floor"],regionFloor];
In[]:=
(*Materials*)​​whiteMaterial=CreateUnityMaterial[File["Materials/White"],CMYKColor[0,0,0,0]];​​blueMaterial=CreateUnityMaterial[File["Materials/Blue"],CMYKColor[1,.37,0,0]];​​greenMaterial=CreateUnityMaterial[File["Materials/Green"],CMYKColor[1,0,1,0]];​​blackMaterial=CreateUnityMaterial[File["Materials/Black"],CMYKColor[0,0,0,1]];​​redMaterial=CreateUnityMaterial[File["Materials/Red"],CMYKColor[0,.94,.65,0]];​​yellowMaterial=CreateUnityMaterial[File["Materials/Yellow"],CMYKColor[0,.34,.91,0]];
In[]:=
(*Prefabs*)​​domino=CreateUnityGameObject["domino",meshDomino];​​CreateUnityRigidbody[domino];​​domino[["MeshCollider","convex"]]=True;​​domino[["SharedMaterial"]]=blueMaterial;prefabBlue=CreateUnityPrefab[File["Prefabs/PrefabBlue"],domino];domino[["SharedMaterial"]]=blackMaterial;​​prefabBlack=CreateUnityPrefab[File["Prefabs/PrefabBlack"],domino];domino[["SharedMaterial"]]=redMaterial;​​prefabRed=CreateUnityPrefab[File["Prefabs/PrefabRed"],domino];​​domino[["SharedMaterial"]]=yellowMaterial;​​prefabYellow=CreateUnityPrefab[File["Prefabs/PrefabYellow"],domino];​​domino[["SharedMaterial"]]=greenMaterial;​​prefabGreen=CreateUnityPrefab[File["Prefabs/PrefabGreen"],domino];​​DeleteUnityGameObject[domino]

Setting the Scene

In[]:=
(*Scene*)​​CreateUnityScene[File["Scenes/OlympicRings"]];
In[]:=
(*Floor*)​​name="Floor";​​go=CreateUnityGameObject[name,meshFloor];​​go[["MeshCollider","convex"]]=True;​​go[["Transform","Position"]]={-21,-1,-16};​​go[["SharedMaterial"]]=whiteMaterial;
In[]:=
(*fiveRings*)​​createring[parentname_,prefab_]:=Module[{parent,dominocnt,name},​​parent=CreateUnityTransform[parentname];​​dominocnt=16;​​Do[​​name="Domino_"<>StringPadLeft[ToString[i],3,"0"];​​CreateUnityGameObject[name,prefab,Properties{"Position"8*{Cos[2(i-1)Pi/dominocnt],0,Sin[2(i-1)Pi/dominocnt]},​​"EulerAngles"{If[i1,20.0`,0.`],-(360/(2Pi))*2(i-1)Pi/dominocnt,0.`},​​"Parent"parent}];​​,{i,dominocnt}​​]​​]​​​​(*blue*)​​createring["DominoBlue",prefabBlue];​​(*black*)​​createring["DominoBlack",prefabBlack];​​dominosbase=FindUnityGameObject["DominoBlack"];​​dominosbase[["Position"]]={0,0,25};​​(*red*)​​createring["DominoRed",prefabRed];​​dominosbase=FindUnityGameObject["DominoRed"];​​dominosbase[["Position"]]={0,0,50}​​(*yellow*)​​createring["DominoYellow",prefabYellow];​​dominosbase=FindUnityGameObject["DominoYellow"];​​dominosbase[["Position"]]={20,0,12}​​(*green*)​​createring["DominoGreen",prefabGreen];​​dominosbase=FindUnityGameObject["DominoGreen"];​​dominosbase[["Position"]]={20,0,37}
In[]:=
(*MainCamera*)​​camera=FindUnityComponent[All,"Camera"];​​camera[["Transform","Position"]]={8,50,20};​​camera[["Transform","EulerAngles"]]={90.`,0.`,90.`};​​camera[["ClearFlags"]]="SolidColor";​​camera[["BackgroundColor"]]=GrayLevel[1];