def prepare_scoreboard(scale, settings): """ :param scale: float :return: [PIL.Image] """ img = YImage(scoreboard, settings, scale).img img = img.crop((int(img.size[0] * 2/3), 0, img.size[0], img.size[1])) img = img.resize((int(140 * scale), int(64 * scale))) imageproc.changealpha(img, 0.3) playerimg = imageproc.add_color(img, [80, 80, 80]) img = imageproc.add_color(img, [60, 70, 120]) return [img, playerimg]
def prepare_scoreentry(scale, color, settings): """ :param settings: :param path: string of path, without filename :param scale: float :param color: tuple(R, G, B) :return: [PIL.Image] """ numbers_animation = [] for x in range(10): number = YImage(scoreentry + str(x), settings, scale) img = number.img tmp = imageproc.add_color(img, color) numbers_animation.append(shrink(tmp, 0.9, 0.3, 0.05 * 60/settings.fps)) return numbers_animation
def prepare_slider(diff, scale, settings): cs = (54.4 - 4.48 * diff["CircleSize"]) * scale radius_scale = cs * 2 / default_size interval = settings.timeframe / settings.fps follow_fadein = 160 # need 160ms to fadein arrow_frames, sliderb_frames, sliderfollow_frames, slider_tick = load( radius_scale, settings) bframes = [] for c in range(1, settings.skin_ini.colours["ComboNumber"] + 1): bframes.append([]) color = settings.skin_ini.colours["Combo" + str(c)] for x in range(len(sliderb_frames)): if settings.skin_ini.general["AllowSliderBallTint"]: color_sb = imageproc.add_color(sliderb_frames[x], color) else: color_sb = sliderb_frames[x].copy() bframes[-1].append(color_sb) startsize, endsize = 0.7, 1 scale_interval = (endsize - startsize) * interval / follow_fadein startalpha, endalpha = 0.4, 1 alpha_interval = (endalpha - startalpha) * interval / follow_fadein sframes = fadein(sliderfollow_frames[0], startalpha, endalpha, alpha_interval) sframes = grow(sframes, startsize, endsize, scale_interval) sframes = sframes[::-1] startsize, endsize = endsize * 0.95, endsize * 0.75 scale_interval = (endsize - startsize) * interval / follow_fadein startalpha, endalpha = 1, 0 alpha_interval = (endalpha - startalpha) * interval / follow_fadein sliderfollow_fadeout = fadein(sliderfollow_frames[0], startalpha, endalpha, alpha_interval) sliderfollow_fadeout = grow(sliderfollow_fadeout, startsize, endsize, scale_interval) return arrow_frames, sframes, sliderfollow_fadeout, slider_tick, bframes
def overlayhitcircle(overlay, circle, color, scale): color_circle = imageproc.add_color(circle, color) maxwidth = max(color_circle.size[0], overlay.size[0]) maxheight = max(color_circle.size[1], overlay.size[1]) background = Image.new("RGBA", (maxwidth, maxheight)) background.paste(color_circle, (maxwidth // 2 - color_circle.size[0] // 2, maxheight // 2 - color_circle.size[1] // 2)) color_circle = background overlay_img = overlay.copy() x1 = color_circle.size[0] // 2 y1 = color_circle.size[1] // 2 imageproc.add(overlay_img, color_circle, x1, y1, channel=4) return imageproc.change_size(color_circle, scale, scale)
def prepare_inputoverlay(scale, color, index_c, settings): """ :param settings: :param scale: float :param color: tuple(R, G, B) :param index_c: index of the color that changes (fadeout fadein) :return: [PIL.Image] """ yimg = YImage(inputoverlay, settings, scale) color = np.array(color) color[index_c] += 200 color[color > 255] = 255 start, end, step = 1, 0.77, 0.05 * 60/settings.fps c_step = int(200*step/(start - end - step)) button_frames = shrink(yimg.img, start, end, step) for i, img in enumerate(button_frames): imgc = imageproc.add_color(img, color) button_frames[i] = imgc color[index_c] = max(0, color[index_c] - c_step) button_frames.insert(0, yimg.img) return button_frames
def prepare_background(backgroundname, settings): """ :param backgroundname: string :return: PIL.Image """ try: img = Image.open(backgroundname).convert("RGBA") except Exception as e: logger.error(repr(e)) img = Image.open(os.path.join(settings.path, "res/bg.png")).convert("RGBA") width = settings.width height = settings.height ratiow = width / height ratioh = height / width w = min(img.size[0], int(img.size[1] * ratiow)) h = min(img.size[1], int(img.size[0] * ratioh)) x, y = (img.size[0] - w) // 2, (img.size[1] - h) // 2 img = img.crop((x, y, x + w, y + h)) scale = width / w img = imageproc.change_size(img, scale, scale) imgs = [Image.new("RGBA", (1, 1))] dim = max(0, min(100, (100 - settings.settings["Background dim"]))) * 2.55 color = np.array([dim, dim, dim]) interval = int(1000 / 45) c_interval = max(0, (settings.settings["Background dim"] - 50) * 2.55 / interval) color[:] = color[:] - c_interval for x in range(interval): color[:] = color[:] + c_interval a = imageproc.add_color(img, color) imgs.append(a) return imgs
def prepare_circle(diff, scale, settings, hd): # prepare every single frame before entering the big loop, this will save us a ton of time since we don't need # to overlap number, circle overlay and approach circle every single time. opacity_interval, time_preempt, fade_in = calculate_ar( diff["ApproachRate"], settings) cs = (54.4 - 4.48 * diff["CircleSize"]) * scale radius_scale = cs * overlay_scale * 2 / default_size circle, c_overlay, slider, s_overlay = load(settings) if not hd: approach_frames = prepare_approach(radius_scale, time_preempt, settings) fadeout = [[], []] # circle, slider circle_frames = [] # [color][number][alpha] slidercircle_frames = [] # [color][number][alpha] alphas = [] for c in range(1, settings.skin_ini.colours["ComboNumber"] + 1): color = settings.skin_ini.colours["Combo" + str(c)] orig_circle = overlayhitcircle(c_overlay, circle, color, radius_scale) if not hd: fadeout[0].append(prepare_fadeout(orig_circle, settings)) else: fadeout[0].append([Image.new("RGBA", (1, 1))]) orig_slider = overlayhitcircle(s_overlay, slider, color, radius_scale) if not hd: fadeout[1].append(prepare_fadeout(orig_slider, settings)) else: fadeout[1].append([Image.new("RGBA", (1, 1))]) alpha = 0 # alpha for fadein circle_frames.append([]) slidercircle_frames.append([]) if not hd: # we also overlay approach circle to circle to avoid multiple add_to_frame call for i in range(len(approach_frames)): approach_circle = imageproc.add_color(approach_frames[i], color) approach_slider = approach_circle.copy() circle_frames[-1].append( overlayapproach(orig_circle, approach_circle, alpha)) slidercircle_frames[-1].append( overlayapproach(orig_slider, approach_slider, alpha)) alphas.append(alpha) alpha = min(100, alpha + opacity_interval) # for late tapping slidercircle_frames[-1].append(orig_slider) circle_frames[-1].append(orig_circle) alphas.append(alpha) else: # source: https://github.com/ppy/osu/blob/4cb57f8205edf5ed7b7da076325ba76ec9cc3039/osu.Game.Rulesets.Osu/Mods/OsuModHidden.cs#L23 interval = settings.timeframe / settings.fps fade_in = time_preempt * 0.4 fade_in_interval = 100 * interval / fade_in ii = fade_in_interval fade_out = time_preempt * 0.3 fade_out_interval = 100 * interval / fade_out #interval = 1 if not interval else interval for i in np.arange(time_preempt, 0, -interval): if alpha != 0: circle_frames[-1].append(newalpha(orig_circle, alpha / 100)) slidercircle_frames[-1].append( newalpha(orig_slider, alpha / 100)) else: circle_frames[-1].append(Image.new("RGBA", (1, 1))) slidercircle_frames[-1].append(Image.new("RGBA", (1, 1))) if alpha == 100: ii = -fade_out_interval alphas.append(alpha) alpha = max(0, min(100, alpha + ii)) logger.debug("done") return slidercircle_frames, circle_frames, fadeout, alphas