cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

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.

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
Loading ..................

Console