---
agentTools:
  projectIndex: https://whsjs.readme.io/llms.txt
---

# Basic sphere («Hello World» example)

Creating a basic sphere that falls down on the plane.

To create whitestorm.js app you should make a basic HTML document with `html`, `head` and `body` tags. Next step is to include Whitestorm.js to the document and main app script file. You can do it simply using `script` tag.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/9513b2d-helloworld.png",
        "helloworld.png",
        1919,
        929,
        "#203a42"
      ],
      "caption": ""
    }
  ]
}
[/block]

Try this [helloworld demo online](https://whs-dev.surge.sh/examples/#basic/helloworld).

[block:api-header]
{
  "type": "basic",
  "title": "App"
}
[/block]

The first thing you should setup is the App object. **When you do this, you do multiple things at once:**

* Setup `THREE.Scene`
* Make a perspective camera and add it to the scene.
* Apply background and other renderer options.
* Set auto resize (in addition).

[block:code]
{
  "codes": [
    {
      "code": "const app = new WHS.App([\n  new WHS.app.ElementModule(),\n  new WHS.app.SceneModule(),\n  new WHS.app.CameraModule({\n    position: new THREE.Vector3(0, 0, 50)\n  }),\n  new WHS.app.RenderingModule({bgColor: 0x162129}),\n  new WHS.app.ResizeModule()\n]);",
      "language": "javascript",
      "name": "app.js"
    }
  ]
}
[/block]

[block:callout]
{
  "type": "info",
  "title": "You can also use a preset of modules",
  "body": "`App` has it's own preset for simple apps quickstart."
}
[/block]

[block:callout]
{
  "type": "info",
  "title": "Why is the color in Hexadecimal format?",
  "body": "Simply following Three.js' [best practice](https://threejs.org/docs/api/math/Color.html)."
}
[/block]

[block:code]
{
  "codes": [
    {
      "code": "const app = new WHS.App(\n  new WHS.BasicAppPreset() // setup for :\n  // ElementModule\n  // SceneModule\n  // CameraModule\n  // RenderingModule\n);",
      "language": "javascript",
      "name": "app.js"
    }
  ]
}
[/block]

[block:api-header]
{
  "type": "basic",
  "title": "Sphere"
}
[/block]

Next thing is a sphere. We define it's geometry in the following parameter. It has `radius`, `widthSegments` and `heightSegments` - all of them are not required in WhitestormJS and have their defaullt values. `material` is the following `THREE.Material` instance that should be used.

[block:code]
{
  "codes": [
    {
      "code": "// const app = ...\n\nconst sphere = new WHS.Sphere({ // Create sphere component.\n  geometry: {\n    radius: 3,\n    widthSegments: 32,\n    heightSegments: 32\n  },\n\n  material: new THREE.MeshBasicMaterial({\n    color: 0xF2F2F2\n  }),\n\n  position: [0, 10, 0]\n});\n\nsphere.addTo(app); // Add sphere to world.",
      "language": "javascript"
    }
  ]
}
[/block]

[block:api-header]
{
  "type": "basic",
  "title": "Plane"
}
[/block]

And the last thing, add the plane and start rendering:

[block:code]
{
  "codes": [
    {
      "code": "// const app = ...\n// const sphere = ...\n\nnew WHS.Plane({\n  geometry: {\n    width: 100,\n    height: 100\n  },\n\n  material: new THREE.MeshBasicMaterial({\n    color: 0x447F8B\n  }),\n\n  rotation: {\n    x: - Math.PI / 2\n  }\n}).addTo(app);\n\napp.start(); // Start animations and physics simulation.",
      "language": "javascript"
    }
  ]
}
[/block]