Wayward Walker Worms

Size
3,123 Kb
Views
54,648

How do I make an wayward walker worms?

Yet another random walk Pen.Constant step size. Directions: right, up, left, down. Each walker has a tail (history) which makes it a walker worm.. What is a wayward walker worms? How do you make a wayward walker worms? This script and codes were developed by Johan Karlsson on 12 August 2022, Friday.

Wayward Walker Worms Previews

Wayward Walker Worms - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Wayward Walker Worms</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src='https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.6/p5.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Wayward Walker Worms - Script Codes CSS Codes

html, body { margin: 0; background-color: black; overflow: hidden;
}
canvas { display: block;
}

Wayward Walker Worms - Script Codes JS Codes

"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Walker = function () { function Walker(stepSize) { _classCallCheck(this, Walker); this.x = floor(random(w / stepSize)) * stepSize; this.y = floor(random(h / stepSize)) * stepSize; this.stepSize = stepSize; this.hue = random(60) + 260; this.tail = []; this.tailLength = 20; } Walker.prototype.walk = function walk() { if (this.tail.length > this.tailLength) { this.tail.splice(0, 1); } var angle = random(angles); this.x += cos(angle) * this.stepSize; this.y += sin(angle) * this.stepSize; this.tail.push([this.x, this.y]); stroke(this.hue, 100, 55, 1); for (var i = 0; i < this.tail.length - 1; i++) { var p1 = this.tail[i]; var p2 = this.tail[i + 1]; line(p1[0], p1[1], p2[0], p2[1]); } this.bounce(); }; Walker.prototype.bounce = function bounce() { if (this.x < 0) this.x = 0; if (this.x > w) this.x = w; if (this.y < 0) this.y = 0; if (this.y > h) this.y = h; }; return Walker;
}();
var angles = undefined;
var nrOfWalkers = undefined;
var walkers = undefined;
var stepSize = undefined;
var w = undefined;
var h = undefined;
function setup() { nrOfWalkers = 50; angles = [0, PI / 2, PI, 3 * PI / 2]; stepSize = 8; setWidthAndHeigt(); walkers = []; for (var i = 0; i < nrOfWalkers; i++) { var walker = new Walker(stepSize); walkers.push(walker); } createCanvas(w, h); strokeWeight(2); colorMode(HSL);
}
function draw() { background("black"); walkers.forEach(function (w) { return w.walk(); });
}
function windowResized() { setWidthAndHeigt(); resizeCanvas(w, h);
}
function setWidthAndHeigt() { w = round(windowWidth / stepSize) * stepSize; h = round(windowHeight / stepSize) * stepSize;
}
Wayward Walker Worms - Script Codes
Wayward Walker Worms - Script Codes
Home Page Home
Developer Johan Karlsson
Username DonKarlssonSan
Uploaded August 12, 2022
Rating 4.5
Size 3,123 Kb
Views 54,648
Do you need developer help for Wayward Walker Worms?

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!

Johan Karlsson (DonKarlssonSan) Script Codes
Create amazing Facebook ads 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!