Skip to content

Instantly share code, notes, and snippets.

@sixhat
Created March 26, 2026 16:32
Show Gist options
  • Select an option

  • Save sixhat/fc2bc292e2e3c15a63b22cbf3fef28e4 to your computer and use it in GitHub Desktop.

Select an option

Save sixhat/fc2bc292e2e3c15a63b22cbf3fef28e4 to your computer and use it in GitHub Desktop.
Cats in P5js
function setup() {
createCanvas(500, 500);
rectMode(CENTER);
noLoop();
}
function draw() {
background(255);
let y = -80;
let numero_linha =0;
while (y<height+100) {
numero_linha++;
let x = numero_linha % 2 == 0? 50 : 0;
while (x < width+100) {
gato( x, y);
x += 100;
}
y += 45;
}
x = 50;
}
function eixos() {
push();
noFill();
strokeWeight(1);
stroke("grey");
circle(0, 0, 20);
strokeWeight(4);
stroke("red");
line(0, 0, width, 0);
stroke("green");
line(0, 0, 0, height);
stroke("blue");
line(0, 0, 0, 0, 0, height);
fill(0);
noStroke();
pop();
}
function olhos_abertos() {
// nose
fill(0);
circle(0, -10, 6);
// lines
push();
strokeWeight(2);
line(0, -10, -5, 0);
line(0, -10, 5, 0);
pop();
// eyes
noFill();
circle(-15, -15, 10);
circle(15, -15, 10);
fill(0);
circle(-15, -15, 3);
circle(15, -15, 3);
}
function olhos_fechados() {
// nose
fill(0);
circle(0, -10, 6);
// lines
push();
strokeWeight(2);
line(0, -10, -5, 0);
line(0, -10, 5, 0);
pop();
// eyes
fill(0);
circle(-15, -15, 3);
circle(-16, -16, 3);
circle(15, -15, 3);
circle(16, -16, 3);
}
function olhos_dormir() {
// nose
fill(0);
circle(0, -10, 6);
ellipse(0, 0, 3, 6);
// lines
push();
strokeWeight(2);
line(0, -10, 0, 0);
// eyes
noFill();
arc(-15, -15, 8, 4, 0, PI);
arc(15, -15, 8, 4, 0, PI);
pop();
}
function gato(x, y) {
push();
translate(x, y);
// Body
fill(random(200,255));
beginShape();
vertex(-50, 50);
bezierVertex(-35, -60, -35, -60, -20, -40);
vertex(20, -40);
bezierVertex(35, -60, 35, -60, 50, 50);
endShape();
let n = random([0, 1, 2]);
switch (n) {
case 0:
olhos_abertos();
break;
case 1:
olhos_fechados();
break;
case 2:
olhos_dormir();
break
}
pop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment