Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

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

              
                <div class="wrapper">
  <h1>Testing mouse trailing line</h1>

  <img src="https://assets.codepen.io/11487/project2.jpg" width="600" alt="">

  <p>Lorem ipsum dolor sit amet <a href="#">consectetur</a> adipisicing elit. Nisi sapiente magni ea assumenda saepe at, illo, modi debitis inventore, atque libero? Rem ea modi sapiente doloremque beatae ipsam aliquam! Libero!</p>

  <h1>Lorem ipsum dolor sit amet consectetur adipisicing elit. Ab asperiores tempora in unde, quas id maxime labore sint debitis ea quisquam repellat esse, necessitatibus quibusdam iure rem omnis! Hic, minima.</h1>
</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}
html, body {
  height: 100%;
  max-height: 100%;
  background: transparent;
  margin: 0;
  padding: 0;
}

canvas {
  max-width: 100%;
  max-height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  // right: 0;
  // bottom: 0;
  z-index: -1;
  transition: opacity 250ms linear;
  // background: transparent;
  // display: none;
  margin: 0;
  padding: 0;
}

.wrapper {
  max-width: 1200px;
  margin: 0 auto;
}
              
            
!

JS

              
                
// // All the paths
// let paths = [];
// // Are we painting?
// let painting = false;
// // How long until the next circle
// let next = 0;
// // Where are we now and where were we?
// let current;
// let previous;

// function setup() {
//   createCanvas(720, 400);
//   current = createVector(0,0);
//   previous = createVector(0,0);
// };

// function draw() {
//   background(200);
  
//   // If it's time for a new point
//   if (millis() > next && painting) {

//     // Grab mouse position      
//     current.x = mouseX;
//     current.y = mouseY;

//     // New particle's force is based on mouse movement
//     let force = p5.Vector.sub(current, previous);
//     force.mult(0.05);

//     // Add new particle
//     paths[paths.length - 1].add(current, force);
    
//     // Schedule next circle
//     next = millis() + random(100);

//     // Store mouse values
//     previous.x = current.x;
//     previous.y = current.y;
//   }

//   // Draw all paths
//   for( let i = 0; i < paths.length; i++) {
//     paths[i].update();
//     paths[i].display();
//   }
// }

// // Start it up
// function mouseMoved() {
//   next = 0;
//   painting = true;
//   previous.x = mouseX;
//   previous.y = mouseY;
//   paths.push(new Path());
// }

// // Stop
// function mouseReleased() {
//   // painting = false;
// }

// // A Path is a list of particles
// class Path {
//   constructor() {
//     this.particles = [];
//     this.hue = random(100);
//   }

//   add(position, force) {
//     // Add a new particle with a position, force, and hue
//     this.particles.push(new Particle(position, force, this.hue));
//   }
  
//   // Display plath
//   update() {  
//     for (let i = 0; i < this.particles.length; i++) {
//       this.particles[i].update();
//     }
//   }  
  
//   // Display plath
//   display() {    
//     // Loop through backwards
//     for (let i = this.particles.length - 1; i >= 0; i--) {
//       // If we shold remove it
//       if (this.particles[i].lifespan <= 0) {
//         this.particles.splice(i, 1);
//       // Otherwise, display it
//       } else {
//         this.particles[i].display(this.particles[i+1]);
//       }
//     }
  
//   }  
// }

// // Particles along the path
// class Particle {
//   constructor(position, force, hue) {
//     this.position = createVector(position.x, position.y);
//     this.velocity = createVector(force.x, force.y);
//     this.drag = 0.95;
//     this.lifespan = 255;
//   }

//   update() {
//     // Move it
//     this.position.add(this.velocity);
//     // Slow it down
//     this.velocity.mult(this.drag);
//     // Fade it out
//     this.lifespan--;
//   }

//   // Draw particle and connect it with a line
//   // Draw a line to another
//   display(other) {
//     stroke(0, this.lifespan);
//     fill(0, this.lifespan/2);    
//     ellipse(this.position.x,this.position.y, 8, 8);    
//     // If we need to draw a line
//     if (other) {
//       line(this.position.x, this.position.y, other.position.x, other.position.y);
//     }
//   }
// }

// function setup() {
//   createCanvas(1000, 800);
//   strokeWeight(22);
// }
// function draw() {
//   background(204);
//   line(mouseX, mouseY, pmouseX, pmouseY);
// }


// function setup() {
//   createCanvas(1400, 800);
//   background(50);
// }
// function draw() {
//   // noFill();
//   stroke(255);
//   strokeWeight(1);
//   line(mouseX, mouseY, pmouseX, pmouseY);
// }



// function setup() {
//   createCanvas(1100, 700);
//   noCursor();
// }
// function draw() {
//   background(204);
//   if (mouseIsPressed == true) {
//     cursor(HAND);  // Draw cursor as hand
//   }
//   else {
//     cursor(CROSS); // Draw cursor as cross
//   }
//   line(mouseX, 0, mouseX, height);
//   line(0, mouseY, height, mouseY);
// }


// function setup() {
//   //slow down the frameRate to make it more visible
//   // frameRate(10);
//   createCanvas(1100, 700);
// }

// function draw() {
//   background(244, 248, 252);
//   line(mouseX, mouseY, pmouseX, pmouseY);
// }







let canvas;
let animEnded = false;
let clearDrawing;
// let isMoving = false;
// let x = 1;
// let y = 1;
// let easing = 0.05;

function setup() {
  // createCanvas(windowWidth, windowHeight);
  createCanvas(displayWidth, displayHeight);
  canvas = document.getElementsByTagName("canvas")[0];
  document.addEventListener('transitionend', function(){
    clear();
    canvas.style.opacity = '1';
  });
}

function draw() { 
    // canvas.style.opacity = '1';
  line(mouseX, mouseY, pmouseX, pmouseY);
  strokeWeight(4);
}

function windowResized() {
  // resizeCanvas(windowWidth, windowHeight);
  resizeCanvas(displayWidth, displayHeight);
}


// function update() {
//   if ( animEnded ) {
//     alert('hi')
//     clear();
//   }
// }

function mouseMoved(event) {
  canvas.style.opacity = '1';
  window.clearTimeout(clearDrawing);
  // document.removeEventListener(transitionend);
  clearDrawing = window.setTimeout(function(){
    canvas.style.opacity = '0';
    // clear();
  }, 800);
}













// let x = [],
//   y = [],
//   segNum = 25,
//   segLength = 30;

// for (let i = 0; i < segNum; i++) {
//   x[i] = 0;
//   y[i] = 0;
// }

// function setup() {
//   createCanvas(windowWidth, windowHeight);
//   background(255);
//   strokeWeight(5);
//   stroke(0);
// }

// function draw() {
//   background(255);
//   dragSegment(0, mouseX, mouseY);
//   for (let i = 0; i < x.length - 1; i++) {
//     dragSegment(i + 1, x[i], y[i]);
//   }
// }

// function dragSegment(i, xin, yin) {
//   const dx = xin - x[i];
//   const dy = yin - y[i];
//   const angle = atan2(dy, dx);
//   x[i] = xin - cos(angle) * segLength;
//   y[i] = yin - sin(angle) * segLength;
//   segment(x[i], y[i], angle);
// }

// function segment(x, y, a) {
//   push();
//   translate(x, y);
//   rotate(a);
//   line(0, 0, segLength, 0);
//   pop();
// }

              
            
!
999px

Console