xxxxxxxxxx
89
function setup() {
createCanvas(400, 400)
noLoop()
colorMode(HSB, 1, 1, 1, 1)
}
function draw() {
background(0.55, 0.8, 1, 0.8)
bodyColor = color(1, 0.5, 1, 0.98)
legColor = color(1, 0.5, 1, 0.8)
tentacleColor = color(0.5, 1, 0.8, 0.4)
drawJelly(width/2, height/2, 100, bodyColor, legColor, tentacleColor)
}
function drawJelly(x, y, size, bodyColor, legColor, tentacleColor) {
noStroke()
let leftx = x - size/2,
rightx = x + size/2
// draw some "legs"
let x1 = leftx
let numLegs = 8
fill(legColor)
for (let i = 0; i < numLegs; i++) {
let div = (rightx - leftx) / (numLegs * 2)
let x2 = x1 + div
let x3 = x2 + div
let bottomy = y + size * random(0.55, 0.7)
bezier(x1, y + size * 0.06, x2, bottomy, x2, bottomy, x3, y + size * 0.06)
x1 = x3
}
// draw some tentacles
x1 = leftx
let numTentacles = 11
fill(tentacleColor)
for (let i = 0; i < numTentacles; i++) {
beginShape()
let div = (rightx - leftx) / (numTentacles * 2)
let x2 = x1 + div
let x3 = x2 + div
let x4 = (x1 + x2) / 2
let x5 = (x2 + x3) / 2
let bottomy = y + size * random(1, 1.2)
let midy = (y + bottomy) / 2
// print(x1, x4, x2)
// print(x2, x5, x3)
// print(y, midy, bottomy)
// bezier(x1, y, x4, midy, x4, midy, x2, bottomy)
// bezier(x2, bottomy, x5, midy, x5, midy, x3, y)
vertex(x1, y)
vertex(x4, midy)
vertex(x2, bottomy)
vertex(x5, midy)
vertex(x3, y)
endShape()
x1 = x3
}
// draw main body
fill(bodyColor)
ellipse(x, y, size, size*0.7)
}
class Jelly {
constructor(x, y, size) {
this.x = x
this.y = y
this.size = size
this.numTentacles = random(6, 14)
this.leftx = this.x - this.size/2
this.rightx = this.x + this.size/2
this.x1 = this.leftx
this.div = (this.rightx - this.leftx) / (this.numTentacles * 2)
this.x2 = this.x1 + this.div
this.x3 = this.x2 + this.div
this.x4 = (this.x1 + this.x2) / 2
this.x5 = (this.x2 + this.x3) / 2
this.bottomy = this.y + this.size * random(1, 1.2)
this.midy = (this.y + this.bottomy) / 2
}
drawTentacles() {
}
}