import json
import time
import turtle
from math import pi, sin, cos
chart = json.loads(open("chart3.txt").read())
#chart = json.loads(open("Chart_IN #2970").read())
judgeLineList = chart["judgeLineList"]
turtle.tracer(False)
ZOOM = 1
MAX_X = 880 // ZOOM
MAX_Y = 520 // ZOOM
UNIT_X = 0.05625 * MAX_X
UNIT_Y = 0.6 * MAX_Y
turtle.setup(880, 520)
turtle.Screen().bgcolor("black")
turtle.hideturtle()
def enlarge(l, r, lt, rt, t):
t1 = rt - t
t2 = t - lt
return (l * t1 + r * t2) / (rt - lt)
LENGTH = 1000
turtle.colormode(255)
turtle.pendown()
turtle.goto(114, 514)
def drawline(x1, y1, x2, y2):
if not (((-880 <= x1 <= 880) and (-520 <= y1 <= 520)) or ((-880 <= x2 <= 880) and (-520 <= y2 <= MAX_Y))):
xA, xB = min(x1, x2), max(x1, x2)
yA, yB = min(y1, y2), max(y1, y2)
if max(-880, xA) > min(880, xB) or max(-520, yA) > min(520, yB):
return
turtle.penup()
turtle.goto(x1, y1)
turtle.pendown()
turtle.goto(x2, y2)
note_color = [[], [0, 162, 232], [255, 242, 0], [0, 162, 232], [237, 28, 36]]
class Vector:
def __init__(self, x = 0, y = 0):
self.x = x
self.y = y
def __add__(self, other):
return Vector(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Vector(self.x - other.x, self.y - other.y)
def __mul__(self, other):
return Vector(self.x * other, self.y * other)
def perp_vec(self):
return Vector(-self.y, self.x)
def __lt__(self, other):
if self.x != other.x:
return self.x < other.x
else:
return self.y < other.y
start = time.time()
while True:
now = time.time() - start
lines = []
notes = []
for judgeLine_id in range(len(judgeLineList)):
cur = judgeLineList[judgeLine_id]
k = 1.875 / cur["bpm"]
T = now / k
now_X = 0
now_Y = 0
now_angle = 0
now_opacity = 0
floorPosition = 0
for moveEvent_id in range(len(cur["judgeLineMoveEvents"])):
moveEvent = cur["judgeLineMoveEvents"][moveEvent_id]
if moveEvent["startTime"] <= T <= moveEvent["endTime"]:
now_X = enlarge(moveEvent["start"], moveEvent["end"], moveEvent["startTime"], moveEvent["endTime"], T)
now_Y = enlarge(moveEvent["start2"], moveEvent["end2"], moveEvent["startTime"], moveEvent["endTime"], T)
for rotateEvent_id in range(len(cur["judgeLineRotateEvents"])):
rotateEvent = cur["judgeLineRotateEvents"][rotateEvent_id]
if rotateEvent["startTime"] <= T <= rotateEvent["endTime"]:
now_angle = enlarge(rotateEvent["start"], rotateEvent["end"], rotateEvent["startTime"], rotateEvent["endTime"], T)
for disappearEvent_id in range(len(cur["judgeLineDisappearEvents"])):
disappearEvent = cur["judgeLineDisappearEvents"][disappearEvent_id]
if disappearEvent["startTime"] <= T <= disappearEvent["endTime"]:
now_opacity = enlarge(disappearEvent["start"], disappearEvent["end"], disappearEvent["startTime"], disappearEvent["endTime"], T)
for speedEvent_id in range(len(cur["speedEvents"])):
speedEvent = cur["speedEvents"][speedEvent_id]
if speedEvent["endTime"] < T:
floorPosition += speedEvent["value"] * (speedEvent["endTime"] - speedEvent["startTime"])
elif speedEvent["startTime"] <= T <= speedEvent["endTime"]:
floorPosition += speedEvent["value"] * (T - speedEvent["startTime"])
#now_opacity = 1
floorPosition *= k # speedEvent["value"] 用秒做单位.
now_X -= 0.5
now_Y -= 0.5
now_angle *= 0.017453292519943
judgeLine_O = Vector(now_X * MAX_X, now_Y * MAX_Y)
judgeLine_X = Vector(cos(now_angle), sin(now_angle)) * UNIT_X
judgeLine_Y = Vector(-sin(now_angle), cos(now_angle)) * UNIT_Y
lines.append((now_opacity, judgeLine_O - judgeLine_X * LENGTH, judgeLine_O + judgeLine_X * LENGTH))
for note_id in range(len(cur["notesAbove"])):
note = cur["notesAbove"][note_id]
if note["type"] != 3:
if T <= note["time"]:
realFloorPosition = note["speed"] * (note["floorPosition"] - floorPosition)
notes.append((note["type"], judgeLine_O + judgeLine_X * (note["positionX"] - 1) + judgeLine_Y * realFloorPosition, judgeLine_O + judgeLine_X * (note["positionX"] + 1) + judgeLine_Y * realFloorPosition))
else:
if T <= note["time"] + note["holdTime"]:
Phead1 = Phead2 = Ptail1 = Ptail2 = Vector()
if T <= note["time"]:
realFloorPosition = note["floorPosition"] - floorPosition
realFloorPositionT = realFloorPosition + note["speed"] * note["holdTime"] * k
Phead1 = judgeLine_O + judgeLine_X * (note["positionX"] - 1) + judgeLine_Y * realFloorPosition
Phead2 = judgeLine_O + judgeLine_X * (note["positionX"] + 1) + judgeLine_Y * realFloorPosition
Ptail1 = judgeLine_O + judgeLine_X * (note["positionX"] - 1) + judgeLine_Y * realFloorPositionT
Ptail2 = judgeLine_O + judgeLine_X * (note["positionX"] + 1) + judgeLine_Y * realFloorPositionT
else:
realFloorPositionT = note["speed"] * (note["time"] + note["holdTime"] - T) * k
Phead1 = judgeLine_O + judgeLine_X * (note["positionX"] - 1)
Phead2 = judgeLine_O + judgeLine_X * (note["positionX"] + 1)
Ptail1 = judgeLine_O + judgeLine_X * (note["positionX"] - 1) + judgeLine_Y * realFloorPositionT
Ptail2 = judgeLine_O + judgeLine_X * (note["positionX"] + 1) + judgeLine_Y * realFloorPositionT
notes.append((note["type"], Phead1, Phead2))
notes.append((note["type"], Phead2, Ptail2))
notes.append((note["type"], Ptail2, Ptail1))
notes.append((note["type"], Ptail1, Phead1))
for note_id in range(len(cur["notesBelow"])):
note = cur["notesBelow"][note_id]
if note["type"] != 3:
if T <= note["time"]:
realFloorPosition = note["speed"] * (note["floorPosition"] - floorPosition)
notes.append((note["type"], judgeLine_O + judgeLine_X * (note["positionX"] - 1) - judgeLine_Y * realFloorPosition, judgeLine_O + judgeLine_X * (note["positionX"] + 1) - judgeLine_Y * realFloorPosition))
else:
if T <= note["time"] + note["holdTime"]:
Phead1 = Phead2 = Ptail1 = Ptail2 = Vector()
if T <= note["time"]:
realFloorPosition = note["floorPosition"] - floorPosition
realFloorPositionT = realFloorPosition + note["speed"] * note["holdTime"] * k
Phead1 = judgeLine_O + judgeLine_X * (note["positionX"] - 1) - judgeLine_Y * realFloorPosition
Phead2 = judgeLine_O + judgeLine_X * (note["positionX"] + 1) - judgeLine_Y * realFloorPosition
Ptail1 = judgeLine_O + judgeLine_X * (note["positionX"] - 1) - judgeLine_Y * realFloorPositionT
Ptail2 = judgeLine_O + judgeLine_X * (note["positionX"] + 1) - judgeLine_Y * realFloorPositionT
else:
realFloorPositionT = note["speed"] * (note["time"] + note["holdTime"] - T) * k
Phead1 = judgeLine_O + judgeLine_X * (note["positionX"] - 1)
Phead2 = judgeLine_O + judgeLine_X * (note["positionX"] + 1)
Ptail1 = judgeLine_O + judgeLine_X * (note["positionX"] - 1) - judgeLine_Y * realFloorPositionT
Ptail2 = judgeLine_O + judgeLine_X * (note["positionX"] + 1) - judgeLine_Y * realFloorPositionT
notes.append((note["type"], Phead1, Phead2))
notes.append((note["type"], Phead2, Ptail2))
notes.append((note["type"], Ptail2, Ptail1))
notes.append((note["type"], Ptail1, Phead1))
lines.sort()
for t in lines:
turtle.pencolor(int(0xfe * t[0]), int(0xff * t[0]), int(0xa9 * t[0]))
drawline(t[1].x, t[1].y, t[2].x, t[2].y)
for t in notes:
turtle.pencolor(note_color[t[0]][0], note_color[t[0]][1], note_color[t[0]][2])
drawline(t[1].x, t[1].y, t[2].x, t[2].y)
if ZOOM != 1:
turtle.pencolor(255, 255, 0)
drawline(MAX_X / 2, -520, MAX_X / 2, 520)
drawline(-MAX_X / 2, -520, -MAX_X / 2, 520)
drawline(880, MAX_Y / 2, -880, MAX_Y / 2)
drawline(880, -MAX_Y / 2, -880, -MAX_Y / 2)
turtle.update()
turtle.clear()
time.sleep(0.01)剪贴板
剪贴板 h8waa4h6
剪贴板信息
剪贴板信息
- 收录
- 更新