cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

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.

            
              <canvas id="trigonometri" width="2000" height="1000"></canvas>
            
          
!
            
              html, body {
  text-align: center;
  float: none;
  padding: 0;
  margin: 0;
}

canvas {
  width: 100%;
  height: 50%;
  padding: 0;
  margin: 0;
}

 
            
          
!
            
              window.onload = function() {
  var canvas = document.getElementById("trigonometri");
  c = canvas.getContext("2d");
  var angle = 90;
  var amplitute = 250;
  var centerx = canvas.width / 2;
  var centery = canvas.height / 2;
  var x = 0;
  var y = centery;
  var speedx = 3;
  var speedy = .008;
  var gradientx1 = centerx-200;
  var gradientx2 = centerx+200;
  var gradienty1 = centery-200;
  var gradienty2 = centery+300;

  var g1 = c.createLinearGradient(500, 0, 2000, 1000);
  g1.addColorStop(0, "pink");
  g1.addColorStop(1, "darkviolet");
  c.fillStyle = g1;
  c.fillRect(0, 0, canvas.width, canvas.height);

  var g2 = c.createLinearGradient(gradientx1, gradienty1, gradientx2, gradienty2);
  g2.addColorStop(0, "deeppink");
  g2.addColorStop(1, "darkviolet");
  c.fillStyle = g2;
  c.arc(centerx, centery, 200, 0, Math.PI * 2, false);
  c.fill();

  
  c.font = "20px Verdana";
  c.fillStyle = "rgba(255,255,255,.5)";
  var txt = "I AM FEELING GREAT!";
  var widthtext = c.measureText(txt).width;
  var halftext = widthtext / 2;
  c.fillText(txt, centerx - halftext, centery + centery / 1.5);
  


  c.font = "30px Verdana";
  c.fillStyle = "rgba(255,255,255,.6)";
  var txta = "▼";
  var widthtexta = c.measureText(txta).width;
  var halftexta = widthtexta / 2;
  c.fillText(txta, centerx - halftexta, centery - centery / 1.5);
  
  requestAnimationFrame(function draw(){
    
    c.beginPath();
    c.moveTo(x,y);
    
    x += speedx;
    angle += speedy;
    
    y = centery + Math.sin(angle)*amplitute;
    z = centery + Math.sin(angle)*-amplitute;
    
    c.lineTo(x,y);
    c.lineWidth = 3;
    c.strokeStyle = "rgba(255,255,255,.5)";
    c.stroke();
    
    
    
    requestAnimationFrame(draw);
    
  });
  requestAnimationFrame(function drawa(){
    
    c.beginPath();
    c.moveTo(x,z);
    x += speedx;
    angle += speedy;
   
    
    z = centery + Math.sin(angle)*(-amplitute);
    
    c.lineTo(x,z);
    c.lineWidth = 3;
    c.strokeStyle = "rgba(255,255,255,.5)";
    c.stroke();
    
    
    
    requestAnimationFrame(drawa);
    
  });
};
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console