Skip to content

Instantly share code, notes, and snippets.

@zeke
Created December 1, 2019 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeke/c55b956e9c308c0e71696535a4d2837b to your computer and use it in GitHub Desktop.
Save zeke/c55b956e9c308c0e71696535a4d2837b to your computer and use it in GitHub Desktop.
playing around with Processing JS
let e1, e2
let h = 0
let s = 0
let b = 0
let hue = 0
let minHue = 0
let maxHue = 360
let direction = +1
function setup() {
createCanvas(820, 600)
noStroke()
colorMode(HSB);
// HSB colormode stands for hue, saturation, brightness
// hue goes from 0 (red) - 360 (also red) 180 is cyan
// saturation goes from 0 - 100 (black and white to color)
// brightness goes from 0 - 100 (black to white)
e1 = new Eye(164, 185, 80);
e2 = new Eye(284, 185, 80);
}
function draw() {
background(h, s, b)
h++;
if( h >= 360){
h = 0;
}
e1.update(mouseX, mouseY);
e2.update(mouseX, mouseY);
e1.display();
e2.display();
}
function Eye(tx, ty, ts) {
this.x = tx;
this.y = ty;
this.size = ts;
this.angle = 0;
this.update = function(mx, my) {
this.angle = atan2(my - this.y, mx - this.x);
};
this.display = function() {
hue = hue + direction
if (hue >= maxHue || hue < minHue) {
direction = direction * -1
}
push();
translate(this.x, this.y);
fill(0, 0, 100);
ellipse(0, 0, this.size, this.size);
rotate(this.angle);
// fill(random(0, 50), 100, 100);
fill(hue, 100, 100);
ellipse(this.size / 4, 0, this.size / 2, this.size / 2);
fill(0, 0, 0);
ellipse(this.size / 4 + (this.size / 32) , 0, this.size / 4, this.size / 4);
pop();
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment