Toggle navigation
Sign Up
Log In
Explore
Works
Folders
Tools
Collections
Artists
Groups
Groups
Topics
Tasks
Tasks
Jobs
Teams
Jobs
Recommendation
More Effects...
JS
"use strict";"object"!=typeof window.CP&&(window.CP={}),window.CP.PenTimer={programNoLongerBeingMonitored:!1,timeOfFirstCallToShouldStopLoop:0,_loopExits:{},_loopTimers:{},START_MONITORING_AFTER:2e3,STOP_ALL_MONITORING_TIMEOUT:5e3,MAX_TIME_IN_LOOP_WO_EXIT:2200,exitedLoop:function(o){this._loopExits[o]=!0},shouldStopLoop:function(o){if(this.programKilledSoStopMonitoring)return!0;if(this.programNoLongerBeingMonitored)return!1;if(this._loopExits[o])return!1;var t=this._getTime();if(0===this.timeOfFirstCallToShouldStopLoop)return this.timeOfFirstCallToShouldStopLoop=t,!1;var i=t-this.timeOfFirstCallToShouldStopLoop;if(i
this.STOP_ALL_MONITORING_TIMEOUT)return this.programNoLongerBeingMonitored=!0,!1;try{this._checkOnInfiniteLoop(o,t)}catch(n){return this._sendErrorMessageToEditor(),this.programKilledSoStopMonitoring=!0,!0}return!1},_sendErrorMessageToEditor:function(){try{if(this._shouldPostMessage()){var o={action:"infinite-loop",line:this._findAroundLineNumber()};parent.postMessage(JSON.stringify(o),"*")}else this._throwAnErrorToStopPen()}catch(t){this._throwAnErrorToStopPen()}},_shouldPostMessage:function(){return document.location.href.match(/boomerang/)},_throwAnErrorToStopPen:function(){throw"We found an infinite loop in your Pen. We've stopped the Pen from running. Please correct it or contact support@codepen.io."},_findAroundLineNumber:function(){var o=new Error,t=0;if(o.stack){var i=o.stack.match(/boomerang\S+:(\d+):\d+/);i&&(t=i[1])}return t},_checkOnInfiniteLoop:function(o,t){if(!this._loopTimers[o])return this._loopTimers[o]=t,!1;var i=t-this._loopTimers[o];if(i>this.MAX_TIME_IN_LOOP_WO_EXIT)throw"Infinite Loop found on loop: "+o},_getTime:function(){return+new Date}},window.CP.shouldStopExecution=function(o){var t=window.CP.PenTimer.shouldStopLoop(o);return t===!0&&console.warn("An infinite loop (or loop taking too long) was detected, so we stopped its execution. Sorry!"),t},window.CP.exitedLoop=function(o){window.CP.PenTimer.exitedLoop(o)}; var BLUE, RED; var tris; function setup() { createCanvas(windowWidth, windowHeight); BLUE = color('#1E2630'); RED = color('#FB3550'); initializeTriangulation(); } function initializeTriangulation() { tris = []; var pts = []; pts.push(createVector(0, 0)); pts.push(createVector(width, 0)); pts.push(createVector(width, height)); pts.push(createVector(0, height)); var n = ~~(width / 300 * height / 300); for (var i = 0; i < n; i++) { if (window.CP.shouldStopExecution(1)) { break; } pts.push(createVector(~~random(width), ~~random(height))); } window.CP.exitedLoop(1); var triangulation = Delaunay.triangulate(pts.map(function (pt) { return [ pt.x, pt.y ]; })); for (var i = 0; i < triangulation.length; i += 3) { tris.push(new Triangle(pts[triangulation[i]], pts[triangulation[i + 1]], pts[triangulation[i + 2]])); } } function Triangle(_a, _b, _c) { this.a = _a; this.b = _b; this.c = _c; this.r = random(0.8); this.n = ~~(dist(_a.x, _a.y, (this.b.x + this.c.x) / 2, (this.b.y + this.c.y) / 2) / random(25, 50)) + 1; this.drawTo = ~~random(3); this.draw = function () { noStroke(); fill(lerpColor(RED, BLUE, this.r)); triangle(this.a.x, this.a.y, this.b.x, this.b.y, this.c.x, this.c.y); switch (this.drawTo) { case 0: this.drawLines(this.a, this.b, this.c); break; case 1: this.drawLines(this.c, this.a, this.b); break; case 2: this.drawLines(this.b, this.a, this.c); break; } stroke(BLUE); strokeJoin(BEVEL); strokeWeight(15); noFill(); triangle(this.a.x, this.a.y, this.b.x, this.b.y, this.c.x, this.c.y); }; this.drawLines = function (from, to1, to2) { var c = cos(frameCount / 360 * TWO_PI) / 2; for (var i = 1; i <= this.n; i++) { if (window.CP.shouldStopExecution(2)) { break; } var p1 = createVector(lerp(from.x, to1.x, (i - 1) / this.n), lerp(from.y, to1.y, (i - 1) / this.n)); var p2 = createVector(lerp(from.x, to2.x, (i - 1) / this.n), lerp(from.y, to2.y, (i - 1) / this.n)); var p3 = createVector(lerp(from.x, to2.x, (i - 0.5 + c) / this.n), lerp(from.y, to2.y, (i - 0.5 + c) / this.n)); var p4 = createVector(lerp(from.x, to1.x, (i - 0.5 + c) / this.n), lerp(from.y, to1.y, (i - 0.5 + c) / this.n)); noStroke(); fill(BLUE); quad(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y); } window.CP.exitedLoop(2); }; } function draw() { background(RED); tris.forEach(function (t) { return t.draw(); }); if (frameCount % 720 == 0) initializeTriangulation(); } function mousePressed() { initializeTriangulation(); } function windowResized() { resizeCanvas(windowWidth, windowHeight); initializeTriangulation(); }
CSS
* { margin: 0; padding: 0; } canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
HTML
Join Effecthub.com
Working with Global Gaming Artists and Developers!
Login
Sign Up
Or Login with Your Email Address:
Email
Password
Remember
Or Sign Up with Your Email Address:
Your Email
This field must contain a valid email
Set Password
Password should be at least 1 character
Stay informed via email