Commit 7600656a authored by shockrah's avatar shockrah 🥐
Browse files

Showing the intensity of vectors at their sampled points/regions

parent ea790215
......@@ -7,8 +7,8 @@ const ORIGIN_Y = HEIGHT / 2
let vectors = []
function y_prime(x, y) {
const base = Math.sin(x) * Math.sin(y)
return base
const base = Math.cos(x) + Math.sin(y)
return base * base
}
class Vector {
......@@ -19,12 +19,13 @@ class Vector {
}
static _interpolate_color(m_angle) {
// how "hot" is that vector point so we can color it appropriately
const heat_index = (Math.abs(m_angle) % PI) / PI // basically the percentage that we're looking for
const heat = Math.floor(heat_index * 0xff)
const cold = Math.floor(0xff - heat)
const red = Math.floor(heat_index * 0xff)
const blue = Math.floor(0xff - red)
return [heat, 0, cold, heat_index * 0xff]
return [red, 0, blue, heat_index * 0xff]
}
draw() {
......@@ -83,34 +84,35 @@ function setup() {
createCanvas(WIDTH, HEIGHT)
const lb = -10
const up = 10
for(var i = 0; i<500; i++) {
const x = (Math.random() * WIDTH)
const y = (Math.random() * HEIGHT)
const vel = new Velocity()
//for(var i = 0; i<500; i++) {
// const x = (Math.random() * WIDTH)
// const y = (Math.random() * HEIGHT)
// const vel = new Velocity()
ballpit.push(new Ball(x, y, vel))
}
//for(var x = lb;x < up;x++) {
// for(var y = lb; y < up; y++) {
// //let p = new Vector(x, y, y_prime(x,y), 10)
// //vectors.push(p)
// }
// ballpit.push(new Ball(x, y, vel))
//}
for(var x = lb;x < up;x++) {
for(var y = lb; y < up; y++) {
let p = new Vector(x, y, y_prime(x,y), 15)
vectors.push(p)
}
}
noFill()
}
function draw() {
background(210, 180, 140) // tan background
strokeWeight(2) // light stroke for now
//for(const sample of vectors) {
// sample.draw()
//}
textSize(40)
text(getFrameRate(), 100, 100)
for(const ball of ballpit) {
ball.draw()
ball.move()
strokeWeight(10)
for(const sample of vectors) {
sample.draw()
}
// ballpit things
//textSize(40)
//text(getFrameRate(), 100, 100)
//for(const ball of ballpit) {
// ball.draw()
// ball.move()
//}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment