Compare commits
No commits in common. "8d3c94ea3e9ef1e23472410c8090b852f0ae3687" and "fd2df012afd94cf86d572b83f0c0b294ce262127" have entirely different histories.
8d3c94ea3e
...
fd2df012af
@ -1,15 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="https://cdn.jsdelivr.net/npm/p5@1.9.0/lib/p5.js"></script>
|
||||
<script src="sketch.js"></script>
|
||||
<style>
|
||||
body {
|
||||
background: #212121;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
@ -1,42 +0,0 @@
|
||||
let position
|
||||
let velocity
|
||||
let accelaration
|
||||
|
||||
function setup() {
|
||||
createCanvas(600, 300)
|
||||
|
||||
position = createVector(width/2, height/2)
|
||||
velocity = createVector(0, 0)
|
||||
accelaration = createVector(0, 0)
|
||||
}
|
||||
|
||||
function draw() {
|
||||
let keyCodeW = 87
|
||||
let keyCodeS = 83
|
||||
|
||||
accelaration.x = 0
|
||||
if (keyIsDown(keyCodeW)) {
|
||||
accelaration.x += 0.001
|
||||
}
|
||||
if (keyIsDown(keyCodeS)) {
|
||||
accelaration.x -= 0.001
|
||||
}
|
||||
|
||||
velocity.add(p5.Vector.mult(accelaration, deltaTime))
|
||||
velocity.limit(2)
|
||||
|
||||
if (position.x < 0) {
|
||||
velocity.x = 0
|
||||
position.x = 0
|
||||
}
|
||||
if (position.x > width) {
|
||||
velocity.x = 0
|
||||
position.x = width
|
||||
}
|
||||
|
||||
position.add(p5.Vector.mult(velocity, deltaTime))
|
||||
|
||||
background(255)
|
||||
|
||||
circle(position.x, position.y, 10)
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="https://cdn.jsdelivr.net/npm/p5@1.9.0/lib/p5.js"></script>
|
||||
<script src="sketch.js"></script>
|
||||
<style>
|
||||
body {
|
||||
background: #212121;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
@ -1,62 +0,0 @@
|
||||
class Walker {
|
||||
constructor(x = 0, y = 0) {
|
||||
this.t = createVector(0, 10000)
|
||||
this.position = createVector(x, y)
|
||||
this.velocity = createVector(0, 0)
|
||||
this.accelaration = createVector(0, 0)
|
||||
this.topSpeed = 50
|
||||
}
|
||||
|
||||
step() {
|
||||
this.accelaration = createVector(
|
||||
map(noise(this.t.x), 0, 1, -1, 1),
|
||||
map(noise(this.t.y), 0, 1, -1, 1)
|
||||
).normalize()
|
||||
this.accelaration.mult(50)
|
||||
|
||||
const dt = deltaTime/1000
|
||||
this.velocity.add(p5.Vector.mult(this.accelaration, dt))
|
||||
this.velocity.limit(this.topSpeed)
|
||||
this.position.add(p5.Vector.mult(this.velocity, dt))
|
||||
this.t.add(createVector(dt, dt))
|
||||
|
||||
|
||||
if (this.position.x < 0) {
|
||||
this.position.x += width
|
||||
}
|
||||
if (this.position.x > width) {
|
||||
this.position.x -= width
|
||||
}
|
||||
|
||||
if (this.position.y < 0) {
|
||||
this.position.y += height
|
||||
}
|
||||
if (this.position.y > height) {
|
||||
this.position.y -= height
|
||||
}
|
||||
}
|
||||
|
||||
draw() {
|
||||
stroke(0)
|
||||
line(
|
||||
this.position.x, this.position.y,
|
||||
this.position.x + this.accelaration.x,
|
||||
this.position.y + this.accelaration.y
|
||||
)
|
||||
circle(this.position.x, this.position.y, 20)
|
||||
}
|
||||
}
|
||||
|
||||
let walker
|
||||
|
||||
function setup() {
|
||||
createCanvas(640, 240)
|
||||
background(255)
|
||||
walker = new Walker(width/2, height/2)
|
||||
}
|
||||
|
||||
function draw() {
|
||||
background(255)
|
||||
walker.step()
|
||||
walker.draw()
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="https://cdn.jsdelivr.net/npm/p5@1.9.0/lib/p5.js"></script>
|
||||
<script src="sketch.js"></script>
|
||||
<style>
|
||||
body {
|
||||
background: #212121;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
@ -1,52 +0,0 @@
|
||||
class Walker {
|
||||
constructor(x = 0, y = 0) {
|
||||
this.position = createVector(x, y)
|
||||
this.velocity = createVector(0, 0)
|
||||
this.accelaration = createVector(0, 0)
|
||||
}
|
||||
|
||||
step() {
|
||||
let target = createVector(mouseX, mouseY)
|
||||
let difference = p5.Vector.sub(target, this.position)
|
||||
this.accelaration = difference.copy()
|
||||
this.accelaration.setMag(1000/difference.mag())
|
||||
|
||||
const dt = deltaTime/1000
|
||||
this.velocity.add(p5.Vector.mult(this.accelaration, dt))
|
||||
this.position.add(p5.Vector.mult(this.velocity, dt))
|
||||
|
||||
|
||||
if (this.position.x < 0) {
|
||||
this.position.x += width
|
||||
}
|
||||
if (this.position.x > width) {
|
||||
this.position.x -= width
|
||||
}
|
||||
|
||||
if (this.position.y < 0) {
|
||||
this.position.y += height
|
||||
}
|
||||
if (this.position.y > height) {
|
||||
this.position.y -= height
|
||||
}
|
||||
}
|
||||
|
||||
draw() {
|
||||
stroke(0)
|
||||
circle(this.position.x, this.position.y, 20)
|
||||
}
|
||||
}
|
||||
|
||||
let walker
|
||||
|
||||
function setup() {
|
||||
createCanvas(640, 240)
|
||||
background(255)
|
||||
walker = new Walker(width/2, height/2)
|
||||
}
|
||||
|
||||
function draw() {
|
||||
background(255)
|
||||
walker.step()
|
||||
walker.draw()
|
||||
}
|
Loading…
Reference in New Issue
Block a user