四足歩行の猫を書きたいです。
processingのpythonモードで四足歩行の猫を書きたいです。
そしてその猫(1匹)をマウスについてくる(動く)ように書きたいです。
プログラミング初心者なもので、どなたか教えていただけると幸いです。
今このような感じです。変更すべき点をご教示ください。
def setup():
size(800, 600)
def draw():
background(255)
chase()
draw_fish()
def draw_cat(x, y):
diff_x = [[40, 0, -20, 0, -10],
[-40, 0, 0, 20, 10]]
diff_y = [[22, 0, -10, -10, 0],
[22, 0, 0, 0, 10]]
size_w = [80, 100, 5, 5, 10]
size_h = [40, 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 = [[75, 90], [-75, -90]]
tail_y = [20, -5]
leg1_x = [[20, 20], [-20, -20]]
leg1_y = [50, 15]
leg2_x = [[33, 33], [-33, -33]]
leg2_y = [50, 15]
leg3_x = [[50, 50], [-50, -50]]
leg3_y = [50, 15]
leg4_x = [[63, 63], [-63, -63]]
leg4_y = [50, 15]
mouth_x = [[-5, -5], [10, 10]]
mouth_y = [25, 25]
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])
stroke(239, 228, 176)
strokeWeight(12)
line(x+leg1_x[mode % 2][0], y+leg1_y[0],
x+leg1_x[mode % 2][1], y+leg1_y[1])
stroke(239, 228, 176)
strokeWeight(12)
line(x+leg2_x[mode % 2][0], y+leg2_y[0],
x+leg2_x[mode % 2][1], y+leg2_y[1])
stroke(239, 228, 176)
strokeWeight(12)
line(x+leg3_x[mode % 2][0], y+leg3_y[0],
x+leg3_x[mode % 2][1], y+leg3_y[1])
stroke(239, 228, 176)
strokeWeight(12)
line(x+leg4_x[mode % 2][0], y+leg4_y[0],
x+leg4_x[mode % 2][1], y+leg4_y[1])
fill(255, 0, 0)
ellipse(x+mouth_x[mode % 2][0], y+mouth_y[0], 20, 20)
class cat:
x = 400
y = 300
speed = 1
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-25, cat.y-25)
def draw_fish():
noStroke()
fill(150, 200, 250)
ellipse(mouseX, mouseY, 50, 20)
triangle(mouseX+10, mouseY, mouseX+30, mouseY-10, mouseX+30, mouseY+10)
0 likes