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

              
                <h1 class="head">Doraemon's Holographic Rarity Card</h1>
<div class="container">
  <canvas id="canvas"></canvas>
</div>

              
            
!

CSS

              
                
body{
  background-color: #000;
}
.container{
  height: 100vh;
  width: 100vw;
  background-color: #000;
  position: relative;

  canvas{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
}

.head{
  position: fixed;
  z-index: 1;
  top: 50px;
  left: 50px;
  font-size: 20px;
  color: #fff;
}
              
            
!

JS

              
                window.addEventListener("DOMContentLoaded", init);

function init() {
  const width  = 500;
  const height = 500;

  // ==========================================
  // create renderer
  // ==========================================
  const renderer = new THREE.WebGLRenderer({
    canvas: document.getElementById("canvas")
  });
  renderer.setSize(width, height);
  renderer.setPixelRatio(window.devicePixelRatio);


  // ==========================================
  // create camera
  // ==========================================
  var [left, right, top, bottom, near, far] = [-1, 1, 1, -1, 0, -1];
  const camera = new THREE.OrthographicCamera(
    left, right, top, bottom, near, far
  );
  
  
  // ==========================================
  // create shaders
  // ==========================================
  const fragmentShader = `
  
varying vec2 vUV;
uniform float time;
uniform vec2 resolution;

// ======================
// variavles
// ======================
const float PI    = 3.1415926;
const vec3  white = vec3(1.0);
const vec3  black = vec3(0.0);

// ======================
// functions
// ======================
void bgColor(vec2 p, inout vec3 i){
  vec2 q  = mod(p, 0.1) - 0.1;
  float s = sin(time);
  float c = cos(time);

  q *= mat2(c,s,-s,c);

  float v = 0.1 / abs(q.y) * abs(q.x);
  float r = v * abs(sin(time * 6.0) + 1.5);
  float g = v * abs(sin(time * 4.0) + 1.5);
  float b = v * abs(sin(time * 3.0) + 1.5);

  vec3 color = vec3(r,g,b);
  i = color;
}

// circle
void circle(vec2 p, vec2 offset, float size, vec3 color, inout vec3 i){
  float l = length(p - offset);

  if(l < size) {
    i = color;
  }
}

// ellipse
void ellipse(vec2 p, vec2 offset, vec2 prop, float size, vec3 color, inout vec3 i){
  vec2 q = (p - offset) / prop;

  if(length(q) < size){
    i = color;
  }
}

// ellipseLine
void ellipseLine(vec2 p, vec2 offset, vec2 prop, float small, float large, vec3 color, inout vec3 i){
  vec2 q = (p - offset) / prop ;
  float l = length(q);

  if(l > small && l < large){
    i = color;
  }
}

// circleLine
void circleLine(vec2 p, vec2 offset, float small, float large, vec3 color, inout vec3 i){
  vec2 q = p - offset;
  float l = length(q);

  if(l > small && l < large){
    i = color;
  }
}

// arcLine
void arcLine(vec2 p, vec2 offset, float small, float large, float rad, float height, vec3 color, inout vec3 i) {
  float s = sin(rad);
  float c = cos(rad);

  vec2 q = (p - offset) * mat2(c, -s, s, c);

  float l = length(q);

  if(l > small && l < large && q.y > height){
    i = color;
  }
}

// oblong
void oblong(vec2 p, vec2 offset, float size, float rad, vec3 color, inout vec3 i){

  float s = sin(rad);
  float c = cos(rad);

  vec2 q = ((p - offset) / size)* mat2(c, -s, s, c) ;

  if(abs(q.x) < 1.0 && abs(q.y) < .01){
    i = color;
  }
}

// Vertical
void Vertical(vec2 p, vec2 offset, float size, float rad, vec3 color, inout vec3 i){

  float s = sin(rad);
  float c = cos(rad);

  vec2 q = ((p - offset) / size)* mat2(c, -s, s, c) ;

  if(abs(q.x) < .01 && abs(q.y) < 1.0){
    i = color;
  }
}



// ======================
// output
// ======================
void main(void){
  vec2 p = (gl_FragCoord.xy * 2.0 - resolution.xy) / min(resolution.x, resolution.y);

  // noseColor
  float l = 0.4 / length(p + 0.9);
  vec3 noseColor = vec3(1.0, l, l);

  // faceColor
  float w = 0.6 / length(p + 0.9);
  vec3 faceColor = vec3(w * 0.2 + 0.1, w * 0.7 + 0.1 , 1.0);

  vec3 baseColor = vec3(1.0);


  bgColor(p, baseColor);

  circle(p, vec2(0.0, -0.99), 0.9, faceColor, baseColor);
  circleLine(p, vec2(0.0,-0.99), 0.9, 0.91, black, baseColor);
  ellipse(p, vec2(0.0, -1.01), vec2(1.0, 0.8), 0.8, white, baseColor);
  ellipseLine(p, vec2(0.0, -1.01),vec2(1.0, 0.8), 0.8, 0.81, black, baseColor);

  ellipse(p, vec2(0.19, -0.39), vec2(0.9, 1.0), 0.2, white, baseColor); 
  ellipse(p, vec2(-0.19, -0.39), vec2(0.9, 1.0), 0.2, white, baseColor);
  ellipse(p, vec2(0.1, -0.44), vec2(0.9, 1.0), 0.05, black, baseColor);
  ellipse(p, vec2(-0.1, -0.44), vec2(0.9, 1.0), 0.05, black, baseColor);
  ellipse(p, vec2(0.1, -0.44), vec2(0.9, 1.0), 0.02, white, baseColor);
  ellipse(p, vec2(-0.1, -0.44), vec2(0.9, 1.0), 0.02, white, baseColor);
  ellipseLine(p, vec2(0.19, -0.39),vec2(0.9, 1.0), 0.2, 0.212, black, baseColor);
  ellipseLine(p, vec2(-0.19, -0.39),vec2(0.9, 1.0), 0.2, 0.212, black, baseColor);

  circle(p, vec2(0.0, -0.61), 0.1, noseColor, baseColor);
  circleLine(p, vec2(0.0, -0.61), 0.1, 0.11, black, baseColor);

  oblong(p, vec2(-.41,-.6), .25, PI * -0.9, black, baseColor);
  oblong(p, vec2(-.42,-.75), .25, PI * 1., black, baseColor);
  oblong(p, vec2(-.4,-.895), .25, PI * -0.1, black, baseColor);

  oblong(p, vec2(.41,-.6), .25, PI * 0.9, black, baseColor);
  oblong(p, vec2(.42,-.75), .25, PI * 1., black, baseColor);
  oblong(p, vec2(.4,-.895), .25, PI * 0.1, black, baseColor);

  Vertical(p, vec2(0,-.97), .25, PI * 1., black, baseColor);

  circle(p, vec2(-0.8, -0.99), 0.2, white, baseColor);
  circleLine(p, vec2(-0.8,-0.99), 0.2, 0.21, black, baseColor);

  circle(p, vec2(0.8, -0.99), 0.2, white, baseColor);
  circleLine(p, vec2(0.8,-0.99), 0.2, 0.21, black, baseColor);

  gl_FragColor = vec4(baseColor, 1.0);

}
  `;
  
  const vertexShader= ` 
varying vec2 vUV;
uniform float time;

void main(void){
  // gl_Position = vec4(position, 1.0);
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);



  vUV= uv;
}
  `;

  // ==========================================
  // create object
  // ==========================================
  var [w, h, wSegments, hSegments] = [2, 2, 10, 10,];
  const geometry = new THREE.PlaneGeometry(
    w, h, wSegments, hSegments
  );

  const material = new THREE.ShaderMaterial({
    fragmentShader : fragmentShader,
    vertexShader   : vertexShader,
    uniforms: {
      resolution: {
        value: new THREE.Vector2(renderer.domElement.width, renderer.domElement.width)
      },
      offset: {
        value: new THREE.Vector2(0.0, 0.0)
      },
      time: {
        value: 0.0
      }
    }
  });

  const mesh = new THREE.Mesh(geometry, material);


  // ==========================================
  // create scene
  // ==========================================
  const scene = new THREE.Scene();
  scene.add(mesh);


  // ==========================================
  // functions
  // ==========================================

  function tick() {
    requestAnimationFrame(tick);

    // camera
    const canvas = renderer.domElement;
    camera.aspect = canvas.clientWidth / canvas.clientHeight;
    camera.updateProjectionMatrix();

    // time
    const second = performance.now() / 1000;
    material.uniforms.time.value = second;

    // render
    renderer.render(scene, camera);
  };


  // ==========================================
  // init
  // ==========================================
  tick();

};

/*
Copyright (c) 2021 ShoyaKajita
Released under the MIT license
https://codepen.io/ShoyaKajita/pen/yLMNVZe?editors=1010
*/
              
            
!
999px

Console