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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

            
              <div class="container">
  <canvas id="canvas" resize="true"></canvas>
  <div class="content">
    <h1 class="headline">Insight & Imagination</h1>  
    <h2 class="subheadline">Drag the shapes. Not optimized for mobile, yet.</h2>
    <h2 class="subheadline"></h2>
    <h2 class="subheadline">Built with <a href="http://paperjs.org">PaperJS</a>.</h2>
  </div>
</div>
            
          
!
            
              * {
  box-sizing: border-box ;
}

@mixin mq($breakpoint) {
  @media screen and ( min-width: $breakpoint ) {
    @content;
  }
}

$mdBreak: 768px;

::selection {
  color: #ffffff;
  background: #000000; }

html,
body {
	width: 100%;
	height: 100%;
	text-rendering: font-smoothing;
	color: #000000;
}

.container {
	z-index: 10;
}

canvas {
	cursor: move;
	z-index: -1;
  width: 100%;
	height: 500px;
	background: #ffffff;
 
  @include mq($mdBreak) {
    width: calc(100% - 180px);
  
	  margin-left: 180px;
  }
}

.content {
  position: absolute;
	top: 0;
	left: 0;
  
	max-width: 450px;
  
  padding-top: 80px;
}

.headline {
	position: relative;
	margin: 0 0 40px;
	font-family: 'Playfair Display', serif;
	font-size: 52px;
	font-weight: 700;
  
  @include mq($mdBreak) {
    font-size: 72px;
  }
}

.subheadline {
  margin: 0 0 10px;
  font-family: 'Arial', sans-serif;
	font-size: 14px;
  font-weight: 400;
  //text-transform: uppercase;
  letter-spacing: 0.35px;
}

a {
  color: #000000;
  text-decoration: underline;
  
  &:hover {
    color: #ffffff;
    background: #000000;
  }
}
            
          
!
            
              paper.install(window);
paper.setup(document.getElementById("canvas"));

var canvasWidth, 
    canvasHeight,
    canvasMiddleX,
    canvasMiddleY,
    pair1Position;

var pair1GroupMask,
    pair1Mask,
    pair1raster,
    pair1GroupShape,
    pair1Shape1,
    pair1Shape2,
    pair1Shape2Offset,
    pair1Result,
    activeItem1;

function getCanvasBounds() {
  canvasWidth = view.size.width;
  canvasHeight = view.size.height;
  canvasMiddleX = canvasWidth / 2;
  canvasMiddleY = canvasHeight / 2;

  pair1Position = {
    x: canvasMiddleX, 
    y: canvasMiddleY,
  };
};

getCanvasBounds();

function createPair1() {
  // Build Shape Mask
  pair1GroupMask = new Group();
  pair1Mask = new Path({
    pathData: 'M331.9,3.6l-331,45l231,304l445-156l-76-196l-148,54L331.9,3.6z',
    clipMask: true,
    parent: pair1GroupMask,
    fillColor: 'red',
  });

  pair1raster = new Raster({
    source: 'http://connorhubeny.com/finn/exp1/img/boston-sm.jpg',
    position: pair1Mask.position,

    parent: pair1GroupMask,
  }); 

  pair1raster.onLoad = function raster1Load() {
    window.requestAnimationFrame(function() {
      const scaleAmount = pair1Mask.bounds.width / pair1raster.bounds.width;
      pair1raster.scale(scaleAmount + 0.15);
    });
  };

  pair1GroupMask.position = pair1Position;

  // Build interactive shapes
  pair1GroupShape = new Group({ insert: false }); // Don't insert in DOM.

  pair1Shape1 = new Path({
    pathData: 'M331.9,3.6l-331,45l231,304l445-156l-76-196l-148,54L331.9,3.6z',
    position: pair1Position,

    parent: pair1GroupShape,
    fillColor: 'white',
    name: 'pair1Shape1',
  });

  pair1Shape2 = new Path({
    pathData: 'M111.5,86.6l16,138l96,107l270-2l88-308l-133,4L111.5,86.6z',
    parent: pair1GroupShape,
    position: pair1Position,
    fillColor: 'white',
    name: 'pair1Shape2',
  });
};

createPair1();

view.onMouseDown = function paperOnMouseDown(event) {
  var hitResult1 = pair1GroupShape.hitTest(event.point);
  activeItem1 = hitResult1 && hitResult1.item;
};

view.onMouseDrag = function paperOnMouseDrag(event) {
  // Move shape
  if (activeItem1) {
    const itemBounds = activeItem1.bounds;

    activeItem1.position.x += event.delta.x;
    activeItem1.position.y += event.delta.y;

    if (activeItem1.name === 'pair1Shape1') {
      pair1GroupMask.position = pair1Shape1.position;
    }
  }
  
  // Constrain to canvas
  var itemBounds = activeItem1.bounds;
  // Shape hit Left edge
  if (itemBounds.x <= 0) {
    activeItem1.position.x = (itemBounds.width / 2);
    if (activeItem1.name === 'pair1Shape1') {
      pair1GroupMask.position.x = (itemBounds.width / 2);
    }
  }
  // Shape hit Right edge
  if ((itemBounds.x + itemBounds.width) >= view.bounds.width) {
    activeItem1.position.x = view.bounds.width - (itemBounds.width / 2 );
    if (activeItem1.name === 'pair1Shape1') {
      pair1GroupMask.position.x = view.bounds.width - (itemBounds.width / 2 );
    }
  }
  // Shape hit Top edge
  if (itemBounds.y <= 0) {
    activeItem1.position.y = (itemBounds.height / 2);
    if (activeItem1.name === 'pair1Shape1') {
      pair1GroupMask.position.y = (itemBounds.height / 2);
    }
  }
  // Shape hit Bottom edge
  if ((itemBounds.y + itemBounds.height) >= view.bounds.height) {
    activeItem1.position.y = view.bounds.height - (itemBounds.height / 2);
    if (activeItem1.name == 'pair1Shape1') {
      pair1GroupMask.position.y = view.bounds.height - (itemBounds.height / 2);
    }
  }
};

view.onMouseUp = function paperOnMouseUp(event) {
  activeItem1 = null;
};

view.onFrame = function paperOnFrame(event) {
  const xOffset = Math.cos(event.count / 80) * 70;
  const yOffset = Math.sin(event.count / 80) * 40;
  if (activeItem1 !== pair1Shape2) {
    pair1Shape2.position.x = pair1Position.x + xOffset;
    pair1Shape2.position.y = pair1Position.y + yOffset;
  }
  
  // Remove the result of the last path operation:
  if (pair1Result) {
    pair1Result.remove();
  }

  pair1Result = pair1Shape1.exclude(pair1Shape2);

  pair1Result.fillColor = 'white';
  pair1Result.strokeColor = '#c8c8c8';
  pair1Result.moveBelow(pair1GroupMask);
  pair1GroupMask.insertBelow(pair1Result);
};
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console