Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<!doctype html>
<html>
  <head>
    <title>Stars1</title>
    <style>
      body { max-width: 100%; }
      /* feel free to style the canvas any way you want. If you want it to
      use the entire window, set width: 100% and height: 100%. */
      
      canvas {
          width: 80%;
          height: 500px;
          display: block;
          margin: 10px auto;
      }
    </style>
  </head>
<body>

  <h1>Stars1</h1>
  
  <p>One interpolated color star</p>

</body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                // We always need a scene

var scene = new THREE.Scene();

// ====================================================================

// function to create a Geometry for a three-pointed star with four triangular faces
// size is the radius of the circle that circumscribes the star

var size = 50;

function starGeometry (size) {
  var starGeom = new THREE.Geometry();
  var angle;
  var lens = [size, size/4];
  for (var i = 0; i < 6; i++) {
     angle = i*(Math.PI/3);
     len = lens[i % 2];
     starGeom.vertices.push(new THREE.Vector3(len*Math.cos(angle), len*Math.sin(angle)));
  }
  starGeom.faces.push(new THREE.Face3(0,1,5));
  starGeom.faces.push(new THREE.Face3(1,2,3));
  starGeom.faces.push(new THREE.Face3(3,4,5));
  starGeom.faces.push(new THREE.Face3(1,3,5));
  return starGeom;
}

// ====================================================================

// vector of colors to use for the 6 vertices of the star geometry
var colors = [new THREE.Color("red"), new THREE.Color("orange"), new THREE.Color("yellow"), 
              new THREE.Color("green"), new THREE.Color("blue"), new THREE.Color("violet")];

// create a star using color interpolation of the triangular faces

var starGeom = starGeometry(size);      // create the initial geometry

starGeom.vertexColors = colors;         // setup vertex colors

TW.computeFaceColors(starGeom);         // setup vertex colors for each face

// create material that uses vertex colors and is double-sided
var starMaterial = new THREE.MeshBasicMaterial( {vertexColors: THREE.VertexColors,
                                                 side: THREE.DoubleSide} );

// create mesh and add to scene
var starMesh = new THREE.Mesh(starGeom, starMaterial);
scene.add(starMesh);

// ================================================================

var renderer = new THREE.WebGLRenderer();

TW.mainInit(renderer,scene);

TW.cameraSetup(renderer,
               scene,
               {minx: -size, maxx: size,
                miny: -size, maxy: size,
                minz: 5, maxz: 5});

              
            
!
999px

Console