Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# p5_clock
# Interactive P5 Plane Map

This example demonstrates a simple interactive map using [p5.js](https://p5js.org/). Click anywhere on the canvas to add a plane that moves across the screen. Planes wrap around the edges.

Open `index.html` in a web browser to view the demo.
16 changes: 16 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Plane Map</title>
<style>
body { margin:0; overflow:hidden; }
#defaultCanvas0 { display:block; }
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.min.js"></script>
<script src="sketch.js"></script>
</body>
</html>
50 changes: 50 additions & 0 deletions sketch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
let planes = [];
let planeImg;

function setup() {
createCanvas(windowWidth, windowHeight);
imageMode(CENTER);
// load plane icon as triangle if planeImg not loaded
}

function preload() {
planeImg = loadImage('https://upload.wikimedia.org/wikipedia/commons/e/e0/Plane_font_awesome.svg', () => {}, () => { planeImg = null; });
}

function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}

function draw() {
background(200, 220, 255); // simple blue background representing sky/map

// update and draw planes
for (let plane of planes) {
plane.x += plane.vx;
plane.y += plane.vy;

if (plane.x > width) plane.x = 0;
if (plane.x < 0) plane.x = width;
if (plane.y > height) plane.y = 0;
if (plane.y < 0) plane.y = height;

push();
translate(plane.x, plane.y);
rotate(plane.angle);
if (planeImg) {
image(planeImg, 0, 0, 20, 20);
} else {
fill(255, 0, 0);
noStroke();
triangle(-10, 8, 10, 0, -10, -8);
}
pop();
}
}

function mousePressed() {
// add new plane at mouse with random velocity
let angle = random(TWO_PI);
let speed = random(1, 3);
planes.push({ x: mouseX, y: mouseY, vx: cos(angle)*speed, vy: sin(angle)*speed, angle });
}