Sand Traveler

Developer
Size
2,467 Kb
Views
20,240

How do I make an sand traveler?

An attempted recreation of Jared Tarbell's "Sand Traveler"See: http://www.complexification.net/gallery/machines/sandTraveler/index.php. What is a sand traveler? How do you make a sand traveler? This script and codes were developed by Ben Matthews on 10 September 2022, Saturday.

Sand Traveler Previews

Sand Traveler - Script Codes HTML Codes

<!DOCTYPE html>
<html class="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.7/p5.min.js">
<head> <meta charset="UTF-8"> <title>Sand Traveler</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <button id="generate" onclick="createAttractors()">generate</button> <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>

Sand Traveler - Script Codes CSS Codes

* { margin:0; padding:0; }
html, body { width:100%; height:100%; }
canvas { display:block; }
#generate { position: absolute; top: 10px; left: 10px;
}

Sand Traveler - Script Codes JS Codes

window.addEventListener('resize', resize, false);
var numAttractors = 500;
var numParticles = 1;
var attractors = [];
var speed = .5;
function Attractor(){ this.x = floor(random()*width); this.y = floor(random()*height); this.xMove = random()*speed; this.yMove = random()*speed; this.moveTo = undefined; var hue = random()*15 + 25; var sat = random()*100; var bal = random()*100; this.color = color(hue, sat, bal, 20);
}
Attractor.prototype.render = function(){ if (this.moveTo == undefined) return; var xDiff = this.moveTo.x - this.x; var yDiff = this.moveTo.y - this.y; var angle = atan2(yDiff, xDiff); this.x += cos(angle)*speed; this.y += sin(angle)*speed; var radius = sqrt(xDiff*xDiff + yDiff*yDiff)/5; // fill(this.color); // ellipse(this.x, this.y, radius); stroke(this.color); for (var i = 0; i < numParticles; i++){ var randA = random()*2*PI - PI; var randR = random()*radius; var x = cos(randA)*randR + this.x; var y = sin(randA)*randR + this.y; point(x, y) }
}
function setup(){ createCanvas(); colorMode(HSB, 360, 100, 100, 100); angleMode(DEGREES); resize(); createAttractors();
}
function createAttractors(){ background(0); attractors = []; for (var i = 0; i < numAttractors; i++){ attractors.push(new Attractor()); } for (var i = 0; i < numAttractors; i++){ var a = attractors[i]; while(a.moveTo == undefined){ var index = floor(random()*numAttractors); var cand = attractors[index]; if (!(cand.x == a.x && cand.y == a.y)){ a.moveTo = cand; } } }
}
function draw(){ noStroke(); for (var n = 0; n < 10; n++){ for (var i = 0; i < attractors.length; i++){ attractors[i].render(); } }
}
function resize(){ resizeCanvas(window.innerWidth, window.innerHeight);
}
Sand Traveler - Script Codes
Sand Traveler - Script Codes
Home Page Home
Developer Ben Matthews
Username tsuhre
Uploaded September 10, 2022
Rating 3
Size 2,467 Kb
Views 20,240
Do you need developer help for Sand Traveler?

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 video scripts 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!