A Pen by Ben Matthews

Developer
Size
3,008 Kb
Views
20,240

How do I make an a pen by ben matthews?

What is a a pen by ben matthews? How do you make a a pen by ben matthews? This script and codes were developed by Ben Matthews on 10 September 2022, Saturday.

A Pen by Ben Matthews Previews

A Pen by Ben Matthews - Script Codes HTML Codes

<!DOCTYPE html>
<html class="https://github.com/processing/p5.js/releases/download/0.5.6/p5.min.js">
<head> <meta charset="UTF-8"> <title>A Pen by Ben Matthews</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src='https://github.com/processing/p5.js/releases/download/0.5.6/p5.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

A Pen by Ben Matthews - Script Codes CSS Codes

* { margin:0; padding:0; }
html, body { width:100%; height:100%; }
canvas { display:block; }

A Pen by Ben Matthews - Script Codes JS Codes

window.addEventListener('resize', resize, false);
function Point(x, y){ this.x = x; this.y = y;
}
var screenRadius = 0;
var cutoffMod = 0;
var cutoffRadius = 0;
var speedMod = 2;
var positionExponent = 1.1;
var notes = [];
var notes2 = [];
var midiFile = "https://www.unm.edu/~bmatthews1/hosted/Prelude.mid";
//pitch out of 88
//veolicy 0 - 1
//duration in seconds/timesteps
function Note(velocity, pitch, duration){ this.length = duration; this.distance = cutoffRadius; this.angle = (PI/6)*(pitch%12) + random()*PI/6; this.hue = ((pitch%12)/12)*60; this.bal = ((floor(pitch/12))/7)*50 + 20; this.distanceMod = floor(pitch/12)*10; this.angleMod = velocity*(PI/12); this.offScreen = false; console.log("length " + this.length); this.center = new Point(0, 0);
}
Note.prototype.tick = function(){ this.distance += speedMod; // this.angle += .01;
}
Note.prototype.render = function(){ var distCalc = this.distance - this.length; var dist1 = distCalc; var dist2 = this.distance; // var dist1 = 0;
// if (distCalc < 0) dist1 = pow(abs(distCalc), 1/positionExponent);
// else dist1 = pow(distCalc, positionExponent);
// var dist2 = pow(this.distance - this.distanceMod, positionExponent); // console.log("dist: " + dist1 + ", " + dist2); dist2 = Math.min(dist2, screenRadius); dist1 = Math.max(dist1, 0); if (dist1 > screenRadius){ console.log("removing note"); this.offScreen = true; return; } noStroke(); fill(this.hue, 100, this.bal); var halfWay = dist1 + (dist2 - dist1)/2; this.center.x = width/2 + cos(this.angle)*halfWay; this.center.y = height/2 + sin(this.angle)*halfWay; var p1 = new Point(width/2 + cos(this.angle + this.angleMod)*dist1, height/2 + sin(this.angle + this.angleMod)*dist1); var p2 = new Point(width/2 + cos(this.angle - this.angleMod)*dist1, height/2 + sin(this.angle - this.angleMod)*dist1); var p4 = new Point(width/2 + cos(this.angle + this.angleMod)*dist2, height/2 + sin(this.angle + this.angleMod)*dist2); var p3 = new Point(width/2 + cos(this.angle - this.angleMod)*dist2, height/2 + sin(this.angle - this.angleMod)*dist2); quad(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y);
}
function setup(){ createCanvas(); colorMode(HSB, 360, 100, 100, 100); ellipseMode(CENTER); resize(); notes = []; for (var i = 0; i < 10; i++){ notes.push([]); } notes2 = [];
}
function draw(){ background(0); if (notes.length < 10) return; fill(0, 100, 100); ellipse(width/2, height/2, 5); noFill(); stroke(0, 100, 100); ellipse(width/2, height/2, cutoffRadius*2); strokeWeight(0.2); for (var i = 0; i < 12; i++){ var angle = ((PI*2)*(i/12)) - PI; var x = width/2 + cos(angle)*screenRadius; var y = height/2 + sin(angle)*screenRadius; line(width/2, height/2, x, y); } var count = 0; for (var i = 0; i < notes.length; i++){ for (var j = 0; j < notes[i].length; j++){ notes[i][j].tick(); notes[i][j].render(); if (notes[i][j].offScreen){ notes[i].splice(j, 1); j--; } count++; } } stroke(120, 60, 60); fill(120, 60, 60); strokeWeight(2); notes2.sort(function(a, b){ return a.angle - b.angle; // return (a.distance*PI*2 + a.angle) - (b.distance*PI*2 + b.angle); })
// var prevX = width/2;
// var prevY = height/2;
// for (var i = 0; i < notes2.length; i++){
// if (notes2[i].offScreen){
// notes2.splice(i, 1);
// i--;
// continue;
// }
// var x = notes2[i].center.x;
// var y = notes2[i].center.y;
// ellipse(x, y, 10);
// line(x, y, prevX, prevY);
// prevX = x;
// prevY = y;
// } if (random() < .2){ console.log("adding note"); var velocity = random()*.3 + .2; var pitch = floor(random()*88); var duration = 100; var note = new Note(velocity, pitch, duration); console.log(floor(pitch/12)); notes[floor(pitch/12)].push(note); notes2.push(note); }
}
function onsuccess(){ console.log("loaded file!")
}
function resize(){ resizeCanvas(window.innerWidth, window.innerHeight); screenRadius = sqrt(width*width + height*height)/2; cutoffRadius = cutoffMod*screenRadius;
}
A Pen by Ben Matthews - Script Codes
A Pen by Ben Matthews - Script Codes
Home Page Home
Developer Ben Matthews
Username tsuhre
Uploaded September 10, 2022
Rating 4
Size 3,008 Kb
Views 20,240
Do you need developer help for A Pen by Ben Matthews?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Ben Matthews (tsuhre) Script Codes
Create amazing art & images with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!