Last active
December 9, 2023 12:17
-
-
Save sorin-ref/7f1964ebd838ff36ebb8be292c33da88 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SceneKit | |
import PlaygroundSupport | |
var sceneView = SCNView() | |
PlaygroundPage.current.liveView = sceneView | |
sceneView.backgroundColor = .black | |
var scene = SCNScene() | |
sceneView.scene = scene | |
var universe = scene.rootNode | |
var camera = SCNCamera() | |
var observer = SCNNode() | |
observer.camera = camera | |
observer.position = SCNVector3(x: 0, y: 15, z: 50) | |
universe.addChildNode(observer) | |
var light = SCNLight() | |
light.type = .directional | |
var torch = SCNNode() | |
torch.light = light | |
torch.position = SCNVector3(x: 5, y: 20, z: 60) | |
universe.addChildNode(torch) | |
var sunObject = SCNSphere(radius: 3) | |
var sunMaterial = sunObject.firstMaterial! | |
sunMaterial.diffuse.contents = UIColor.yellow | |
var sun = SCNNode(geometry: sunObject) | |
universe.addChildNode(sun) | |
observer.look(at: sun.position) | |
torch.look(at: sun.position) | |
var earthOrbit = SCNNode() | |
sun.addChildNode(earthOrbit) | |
var earthObject = SCNSphere(radius: 1) | |
var earthMaterial = earthObject.firstMaterial! | |
earthMaterial.diffuse.contents = UIColor.blue | |
var earth = SCNNode(geometry: earthObject) | |
earthOrbit.addChildNode(earth) | |
earth.position = SCNVector3(x: -12, y: 0, z: 0) | |
earthOrbit.runAction( | |
.repeatForever( | |
.rotateBy(x: 0, y: 2 * CGFloat.pi, z: 0, duration: 10))) | |
var moonOrbit = SCNNode() | |
earth.addChildNode(moonOrbit) | |
var moonObject = SCNSphere(radius: 0.5) | |
var moonMaterial = moonObject.firstMaterial! | |
moonMaterial.diffuse.contents = UIColor.gray | |
var moon = SCNNode(geometry: moonObject) | |
moonOrbit.addChildNode(moon) | |
moon.position = SCNVector3(x: -2, y: 0, z: 0) | |
moonOrbit.runAction( | |
.repeatForever( | |
.rotateBy(x: 0, y: 2 * CGFloat.pi, z: 0, duration: 1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment