その文字座標データから単純に文字を表示するだけのコードを自分で書いてみませんか?
Like!
猫がマウス(魚)に3回ついたときに一文字ずつ背景に表示させ、4回目で文字をすべて消す。
この繰り返しをするプログラムを書きたいです。
それに伴い、一番下に記載しました名前を追加したいです。
プログラム初心者なものでやり方が分かりません。
どなたかご教示ください。よろしくお願い致します。
#name(hiragana)
ka_x1 = [60, 180, 70]
ka_x2 = [220, 220, 130]
ka_y1 = [240, 450, 450]
ka_y2 = [240, 240, 150] #か
zu_x1 = [290, 280, 380, 470, 510]
zu_x2 = [430, 430, 440, 470, 510]
zu_y1 = [210, 450, 290, 200, 200]
zu_y2 = [210, 210, 450, 150, 150] #ず
ki_x1 = [570, 550, 620]
ki_x2 = [720, 740, 690]
ki_y1 = [230, 320, 150]
ki_y2 = [230, 320, 450] #き
def setup():
size(800, 600)
fill
def draw():
background(255)
chase()
draw_fish()
def draw_cat(x, y):
for j in range(3):
stroke(255, 0, 0)
line(ka_x1[j], ka_y1[j], ka_x2[j], ka_y2[j])
for k in range(5):
stroke(0, 255, 0)
line(zu_x1[k], zu_y1[k], zu_x2[k], zu_y2[k])
for l in range(3):
stroke(0, 0, 255)
line(ki_x1[l], ki_y1[l], ki_x2[l], ki_y2[l])
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])
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)
その文字座標データから単純に文字を表示するだけのコードを自分で書いてみませんか?
@psuke92
Questioner@psuke92
Questioner@psuke92
Questioner%
)を使って求めるといたことをするといいですよ。
#name(katakana)
ka_x1 = [60, 180, 70]
ka_x2 = [220, 220, 130]
ka_y1 = [240, 450, 450]
ka_y2 = [240, 240, 150]
zu_x1 = [290, 280, 380, 470, 510]
zu_x2 = [430, 430, 440, 470, 510]
zu_y1 = [210, 450, 290, 200, 200]
zu_y2 = [210, 210, 450, 150, 150]
ki_x1 = [570, 550, 620]
ki_x2 = [720, 740, 690]
ki_y1 = [230, 320, 150]
ki_y2 = [230, 320, 450]
def setup():
size(800, 600)
def draw():
background(255)
chase()
draw_fish()
def draw_ka():
stroke(255, 0, 0)
for x1, y1, x2, y2 in zip(ka_x1, ka_y1, ka_x2, ka_y2):
line(x1, y1, x2, y2)
def draw_zu():
stroke(0, 255, 0)
for x1, y1, x2, y2 in zip(zu_x1, zu_y1, zu_x2, zu_y2):
line(x1, y1, x2, y2)
def draw_ki():
stroke(0, 0, 255)
for x1, y1, x2, y2 in zip(ki_x1, ki_y1, ki_x2, ki_y2):
line(x1, y1, x2, y2)
def draw_name(count):
name = [draw_ka, draw_zu, draw_ki]
for draw_func in name[:count % (len(name) + 1)]:
draw_func()
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])
class cat:
x = 400
y = 300
speed = 1
class eat:
x = -1
y = -1
count = 0
def chase():
cat.x += max(min(mouseX - cat.x, cat.speed), -cat.speed)
cat.y += max(min(mouseY - cat.y, cat.speed), -cat.speed)
if cat.x == mouseX and cat.y == mouseY:
if eat.x != mouseX or eat.y != mouseY:
eat.count += 1
eat.x = mouseX
eat.y = mouseY
draw_name(eat.count)
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)
@psuke92
Questioner