ソースコードをコピー&ペーストして動作確認できるように、マークダウンのコードブロックを使って ソースコードを貼り付けてください。
追いかける猫を追加してみました。
あとは、猫の描画を変えるとかしてみてください。
class cat:
x = 400
y = 300
speed = 3
def chase():
cat.x += max(min(mouseX - cat.x, cat.speed), -cat.speed)
cat.y += max(min(mouseY - cat.y, cat.speed), -cat.speed)
draw_cat(cat.x, cat.y)
def setup():
size(800, 600)
def draw():
background(255)
for i in range(5):
for j in range(3):
x = 100 + i * 150
y = 150 + j * 150
draw_cat(x, y)
chase()
draw_fish()
def draw_cat(x, y):
diff_x = [[0, 0, -20, 0, -10],
[0, 0, 0, 20, 10]]
diff_y = [[50, 0, -10, -10, 0],
[50, 0, 0, 0, 10]]
size_w = [40, 100, 5, 5, 10]
size_h = [60, 80, 5, 5, 5]
ear_lx = [[35, 40, 5],
[30, 40, -20]]
ear_rx = [[-30, -40, 20],
[-35, -40, -5]]
ear_y = [-50, -20, -20]
tail_x = [[0, 40], [0, -40]]
tail_y = [75, 40]
if x > mouseX and y > mouseY:
mode = 0
elif x <= mouseX and y > mouseY:
mode = 1
elif x > mouseX and y <= mouseY:
mode = 2
else:
mode = 3
noStroke()
for i in range(5):
if i < 2:
fill(239, 228, 176)
else:
fill(0)
ellipse(x+diff_x[mode % 2][i], y+diff_y[mode // 2][i],
size_w[i], size_h[i])
fill(239, 228, 176)
triangle(x+ear_lx[mode % 2][0], y+ear_y[0],
x+ear_lx[mode % 2][1], y+ear_y[1],
x+ear_lx[mode % 2][2], y+ear_y[2])
triangle(x+ear_rx[mode % 2][0], y+ear_y[0],
x+ear_rx[mode % 2][1], y+ear_y[1],
x+ear_rx[mode % 2][2], y+ear_y[2])
stroke(239, 228, 176)
strokeWeight(10)
line(x+tail_x[mode % 2][0], y+tail_y[0],
x+tail_x[mode % 2][1], y+tail_y[1])
def draw_fish():
noStroke()
fill(150, 200, 250)
ellipse(mouseX, mouseY, 50, 20)
triangle(mouseX+10, mouseY, mouseX+30, mouseY-30, mouseX+30, mouseY+10)
Like!