diff options
author | San Jacobs | 2025-07-05 14:28:16 +0200 |
---|---|---|
committer | San Jacobs | 2025-07-05 14:28:16 +0200 |
commit | 2d564ef05ec79e2f82a0a692739de54120b1c16a (patch) | |
tree | 52313f256c5a3c179828ab6c13a581f51d0eeeba /src/main.odin | |
parent | e165bd649441f448217f1c07d5cafbfa7e72ba1b (diff) | |
download | dtw-demo-2d564ef05ec79e2f82a0a692739de54120b1c16a.tar.gz dtw-demo-2d564ef05ec79e2f82a0a692739de54120b1c16a.tar.bz2 dtw-demo-2d564ef05ec79e2f82a0a692739de54120b1c16a.zip |
Might be done now
Diffstat (limited to 'src/main.odin')
-rw-r--r-- | src/main.odin | 508 |
1 files changed, 432 insertions, 76 deletions
diff --git a/src/main.odin b/src/main.odin index 11cea8e..d50715f 100644 --- a/src/main.odin +++ b/src/main.odin @@ -8,7 +8,7 @@ import "core:strconv" import "core:reflect" import "core:strings" -MONO_FONT :: #load("../res/RedHatMono.ttf") +MONO_FONT :: #load("../res/Exo2.ttf") font : rl.Font BLACK : rl.Color = {16, 16, 16, 255} @@ -28,6 +28,16 @@ layout :: struct { wave_b_end : rl.Vector2, wave_b_amp : f32, + wave_warp_start : rl.Vector2, + wave_warp_end : rl.Vector2, + wave_warp_amp : f32, + + wave_path_start : rl.Vector2, + wave_path_end : rl.Vector2, + wave_path_amp : f32, + + centerline_thickness : f32, + grid_opacity : f32, grid_data_opacity : f32, highlight_opacity : f32, @@ -43,12 +53,20 @@ layout :: struct { camera_position : rl.Vector2, camera_zoom : f32, - grid_start : rl.Vector2 - grid_end : rl.Vector2 + grid_start : rl.Vector2, + grid_end : rl.Vector2, } -waveform_a := [?]f32{0.0, 0.1, 0.5, 0.3, 0.1, -0.1, 0.0, 0.0, 0.0, 0.1, 0.3, 0.0} -waveform_b := [?]f32{0.0, 0.0, 0.0, 0.2, 0.4, 0.2, -0.1, 0.0, 0.1, 0.3, 0.1, 0.0} +waveform_a := [?]f32{0.0, 0.1, 0.5, 0.3, 0.1, -0.1, 0.0, 0.0, 0.0, 0.1, 0.4, 0.0} +waveform_b := [?]f32{0.0, 0.0, 0.0, 0.2, 0.4, 0.2, -0.2, 0.0, 0.1, 0.3, 0.1, 0.0} + +waveform_warped : [len(waveform_a)]f32 +waveform_warped_target : [len(waveform_a)]f32 +waveform_warped_frames : [dynamic][len(waveform_a)]f32 + +waveform_path : [len(waveform_a)]f32 +waveform_path_target : [len(waveform_a)]f32 +waveform_path_frames : [dynamic][len(waveform_a)]f32 data_frames : [dynamic][len(waveform_a)*len(waveform_b)]cell @@ -62,10 +80,8 @@ data_target : [len(waveform_a)*len(waveform_b)]cell delta : f32 - - init_slides :: proc() { - // ---------------------------- Waveforms + // ############################### Waveforms c : layout = { wave_a_start = {-600, -200}, wave_a_end = {600, -200}, @@ -82,42 +98,61 @@ init_slides :: proc() { arrow_thickness = 3, arrow_chopping = 0.3, - heatmap_opacity = 0.5, + heatmap_opacity = 0, billing = f32(len(waveform_a)), - grid_start = {-400, 350}, - grid_end = { 400, -450}, + grid_start = {-600, 350}, + grid_end = { 200, -450}, } - d : [12*12]cell + wave_warp : [len(waveform_a)]f32 + wave_path : [len(waveform_a)]f32 + d : [len(waveform_a)*len(waveform_b)]cell highlight_rect := rect_from_index(0, HIGHLIGHT_THICKNESS) c.highlight_dimensions = {highlight_rect.width, highlight_rect.height} c.highlight_position = {highlight_rect.x, highlight_rect.y} + c.wave_warp_start = c.grid_start + {0, 300} + c.wave_warp_end = {c.grid_end.x, c.grid_start.y} + {0, 300} + c.wave_warp_amp = 0 + + c.wave_path_start = c.grid_start + {0, 300} + c.wave_path_end = {c.grid_end.x, c.grid_start.y} + {0, 300} + c.wave_path_amp = 0 + append(&slides, c) append(&data_frames, d) - - // ---------------------------- Move waveforms into place - c.wave_a_start = {grid_start.x, grid_start.y+120} - c.wave_a_end = {grid_end.x , grid_start.y+120} - c.wave_b_start = {grid_start.x-120, grid_start.y} - c.wave_b_end = {grid_start.x-120, grid_end.y} + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + + // ############################### Move waveforms into place + c.wave_a_start = {c.grid_start.x, c.grid_start.y+120} + c.wave_a_end = {c.grid_end.x , c.grid_start.y+120} + c.wave_b_start = {c.grid_start.x-120, c.grid_start.y} + c.wave_b_end = {c.grid_start.x-120, c.grid_end.y} c.wave_a_amp = 120 c.wave_b_amp = 130 + append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- Show grid + // ############################### Show grid c.grid_opacity = 1 append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- Show data numbers + // ############################### Show data numbers c.grid_data_opacity = 1 append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- Infinity coating + // ############################### Infinity coating for _, i in waveform_a { if i==0 do continue d[i_from_xy(i, 0)].cost = math.INF_F32 @@ -125,62 +160,128 @@ init_slides :: proc() { } append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + // ############################### FIRST CELL + + d[i_from_xy(1,1)].stepped_in = 1 + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + + d[i_from_xy(1,1)].stepped_in = 0 + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- FIRST CELL d[i_from_xy(1,1)].cost = distance(waveform_a[1], waveform_b[1]) + c.heatmap_opacity = 0.7 + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + + // ############################### Look to the three preceding cells + d[i_from_xy(0,1)].stepped_in = 1 + d[i_from_xy(0,0)].stepped_in = 1 + d[i_from_xy(1,0)].stepped_in = 1 + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + + d[i_from_xy(0,1)].stepped_in = 0 + d[i_from_xy(0,0)].stepped_in = 0 + d[i_from_xy(1,0)].stepped_in = 0 append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- Detecting minimum direction for first cost calculation + // ############################### Detecting minimum direction for first cost calculation d[i_from_xy(1,1)].direction = .DIAGONAL append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- SECOND CELL + // ############################### SECOND CELL + d[i_from_xy(2,1)].stepped_in = 1 + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + d[i_from_xy(2,1)].stepped_in = 0 + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) d[i_from_xy(2,1)].cost = distance(waveform_a[2], waveform_b[1]) append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- Detecting minimum direction for second cost calculation + // ############################### Detecting minimum direction for second cost calculation d[i_from_xy(2,1)].direction = .LEFT append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- Adding previous minimum to second cost calculation + // ############################### Adding previous minimum to second cost calculation d[i_from_xy(2,1)].cost += d[i_from_xy(1,1)].cost append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- THIRD CELL + // ############################### THIRD CELL + d[i_from_xy(1,2)].stepped_in = 1 + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + d[i_from_xy(1,2)].stepped_in = 0 d[i_from_xy(1,2)].cost += distance(waveform_a[1], waveform_b[2]) append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- Detect minimum + // ############################### Detect minimum d[i_from_xy(1,2)].direction = .DOWN append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- Add minimum + // ############################### Add minimum d[i_from_xy(1,2)].cost += d[i_from_xy(1,1)].cost append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- FOURTH CELL + // ############################### FOURTH CELL d[i_from_xy(2,2)].cost += distance(waveform_a[2], waveform_b[2]) append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- Detect minimum + // ############################### Detect minimum a_cost, a_direction := three_min(d[i_from_xy(1,2)], d[i_from_xy(1,1)], d[i_from_xy(2,1)]) @@ -188,20 +289,26 @@ init_slides :: proc() { d[i_from_xy(2,2)].direction = a_direction append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- FIFTH CELL + // ############################### FIFTH CELL full_calc(d[:], 1, 3) append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- SIXTH CELL + // ############################### SIXTH CELL full_calc(d[:], 3, 1) append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- WAVEFRONT first half + // ############################### WAVEFRONT first half for i in 4..<len(waveform_a) { coord : [2]int = {i, 1} for { @@ -211,8 +318,10 @@ init_slides :: proc() { } append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) } - // ---------------------------- WAVEFRONT second half + // ############################### WAVEFRONT second half for i in 2..<len(waveform_a) { coord : [2]int = {len(waveform_a)-1, i} for { @@ -222,20 +331,26 @@ init_slides :: proc() { } append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) } - // ---------------------------- Disregard the numbers + // ############################### Disregard the numbers c.grid_data_opacity = 0 append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- Follow the arrows + // ############################### Focus on the arrows c.arrow_thickness = 6 c.arrow_chopping = 0.25 append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- Pathfollowing + // ############################### Pathfollowing coord : [2]int = {len(waveform_a)-1, len(waveform_b)-1} for { d[i_from_xy(coord.x, coord.y)].stepped_in = 1 @@ -249,45 +364,196 @@ init_slides :: proc() { } append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) if coord == {0,0} do break } - // ---------------------------- Final step - d[0].stepped_in = 1 + // ############################### Look at the pattern + c.arrow_thickness = 0 + c.arrow_chopping = 0.49 + c.heatmap_opacity = 1 + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + + // ############################### Walk through the dark channel + for &c in d { + c.stepped_in = 0 + } append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + + // ############################### Squish away grid + + c.grid_start -= {0, 200} + + c.wave_a_start = {c.grid_start.x, c.grid_start.y+120} + c.wave_a_end = {c.grid_end.x , c.grid_start.y+120} + c.wave_b_start = {c.grid_start.x-120, c.grid_start.y} + c.wave_b_end = {c.grid_start.x-120, c.grid_end.y} + c.wave_a_amp = 150 + c.wave_b_amp = 130 + + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + + // ############################### Bring up output waveform + + c.wave_warp_start = {c.wave_a_start.x, c.wave_a_start.y + 140} + c.wave_warp_end = {c.wave_a_end.x, c.wave_a_end.y +140} + c.wave_warp_amp = 150 + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + + + // ############################### Focus on the arrows + c.arrow_thickness = 4 + c.arrow_chopping = 0.3 + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + + // ############################### Pathfollow and output warped waveform + coord = {len(waveform_a)-1, len(waveform_b)-1} + sample_next : bool = true + for { + d[i_from_xy(coord.x, coord.y)].stepped_in = 0.3 + if sample_next { + d[i_from_xy(coord.x, coord.y)].stepped_in = 1 + wave_warp[coord.x] = waveform_b[coord.y] + sample_next = false + } + #partial switch d[i_from_xy(coord.x, coord.y)].direction { + case .LEFT: + coord -= {1, 0} + sample_next = true + case .DIAGONAL: + coord -= {1, 1} + sample_next = true + case .DOWN: + coord -= {0, 1} + } + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + if coord == {0,0} do break + } + + // ############################### Zoom back in + c.grid_start = slides[1].grid_start + c.grid_end = slides[1].grid_end + + c.wave_a_start = {c.grid_start.x, c.grid_start.y+120} + c.wave_a_end = {c.grid_end.x , c.grid_start.y+120} + c.wave_b_start = {c.grid_start.x-120, c.grid_start.y} + c.wave_b_end = {c.grid_start.x-120, c.grid_end.y} + + c.wave_warp_start = slides[1].wave_warp_start + c.wave_warp_end = slides[1].wave_warp_end + c.wave_warp_amp = 0 - // ---------------------------- Look at the pattern c.arrow_thickness = 0 c.arrow_chopping = 0.49 - c.heatmap_opacity = 1 + + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + + // ############################### Looking at only matches and inserts... + for &cell in d { + if cell.stepped_in<0.999 do cell.stepped_in = 0 + } + // turning this into an offset series + for &p, x in wave_path { + if x==0 do continue + for y in 1..<len(waveform_b) { + p += 1 + if d[i_from_xy(x,y)].stepped_in > 0.0001 do break + } + p -= f32(x) + } + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + + // ############################### ...as deviations from the middle line ... + c.centerline_thickness = 5 + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + + // ############################### ... resulting in this offset series. + + // squishing down grid + c.grid_start -= {0, 300} + c.wave_a_start = {c.grid_start.x, c.grid_start.y+120} + c.wave_a_end = {c.grid_end.x , c.grid_start.y+120} + c.wave_b_start = {c.grid_start.x-120, c.grid_start.y} + c.wave_b_end = {c.grid_start.x-120, c.grid_end.y} + c.wave_a_amp = 150 + c.wave_b_amp = 130 + // bringing up offset series + c.wave_path_start = {c.wave_a_start.x, c.wave_a_start.y + 220} + c.wave_path_end = {c.wave_a_end.x, c.wave_a_end.y + 220} + c.wave_path_amp = 30 + + append(&slides, c) + append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) + + // ############################### Which is ripe for smoothing + smooth_waveform(wave_path[:]) append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- + // ############################### append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- + // ############################### append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- + // ############################### append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) - // ---------------------------- + // ############################### append(&slides, c) append(&data_frames, d) + append(&waveform_path_frames, wave_path) + append(&waveform_warped_frames, wave_warp) } rect_from_index :: proc(i : int, thickness : f32 = 0) -> rl.Rectangle { // rect is top left corener and dimensions - width := abs(grid_end.x - grid_start.x) - height := abs(grid_end.y - grid_start.y) + width := abs(state.grid_end.x - state.grid_start.x) + height := abs(state.grid_end.y - state.grid_start.y) intergrid_dimensions : rl.Vector2 = {width, height} cell_dimensions := intergrid_dimensions/f32(len(waveform_a)-1) - position_zero := grid_start-(cell_dimensions/2) + position_zero := state.grid_start-(cell_dimensions/2) output := position_zero + cell_dimensions * {f32(i%len(waveform_a)), -f32(i/len(waveform_b))} thickness_offset := thickness/2 return {output.x-thickness_offset, output.y-thickness_offset, cell_dimensions.x+thickness_offset, cell_dimensions.y+thickness_offset} @@ -335,7 +601,7 @@ lerp :: proc() { from_val := data_state[i].cost to_val := data_target[i].cost - if data_target[i].cost != math.INF_F32 && data_state[i].cost != math.nan_f32() { + if data_target[i].cost != math.INF_F32 && !math.is_nan(data_state[i].cost) { data_state[i].cost = from_val + (to_val - from_val) * (1.0 - math.pow(LERP_SPEED, delta)*0.9) } else { data_state[i].cost = data_target[i].cost @@ -347,17 +613,51 @@ lerp :: proc() { data_state[i].direction = data_target[i].direction } + for &x, i in waveform_path { + x = x + (waveform_path_target[i] - x) * (1.0 - math.pow(LERP_SPEED, delta)) + } + for &x, i in waveform_warped { + x = x + (waveform_warped_target[i] - x) * (1.0 - math.pow(LERP_SPEED, delta)) + } } normalize :: proc(v : rl.Vector2) -> rl.Vector2 { return v / math.sqrt((v.x*v.x) + (v.y*v.y)) } +smooth_waveform :: proc(wave : []f32) { + output_waveform := make_slice([]f32, len(wave)) + for i in 1..<len(wave)-1 { + output_waveform[i] = average(wave[i-1:i+2]) + } + for _, i in wave { + wave[i] = output_waveform[i] + } + delete(output_waveform) +} +average :: proc(numbers : []f32) -> f32 { + sum : f32 = 0 + for i in numbers { + sum += i + } + return sum/f32(len(numbers)) +} -draw_waveform :: proc(wave : []f32, start : rl.Vector2, end : rl.Vector2, amp : f32, name : cstring) { +draw_waveform :: proc(wave : []f32, start : rl.Vector2, end : rl.Vector2, amp : f32, name : cstring, alt_color := false) { + if amp<0.01 do return + samples := len(wave) + line_color := ORANGE + dot_color := YELLOW + if alt_color { + line_color = rl.BLUE + dot_color = rl.BLUE + dot_color.g += 80 + } + lines := samples-1 rl.DrawLineEx(start, end, 2, rl.DARKGRAY) + rl.DrawCircleV(start, 5, rl.DARKGRAY) total_direction := end - start step := total_direction / f32(lines) perpendicular : rl.Vector2 = normalize({total_direction.y, -total_direction.x}) @@ -366,21 +666,39 @@ draw_waveform :: proc(wave : []f32, start : rl.Vector2, end : rl.Vector2, amp : for value, i in wave[:lines] { start_base := start + (step*f32(i)) end_base := start + (step*f32(i+1)) - start_pos : rl.Vector2 = start_base + (perpendicular*wave[i]*amp) - end_pos = end_base + (perpendicular*wave[i+1]*amp) - rl.DrawLineEx(start_pos, end_pos, 4, ORANGE) - rl.DrawCircleV(start_pos, 5, YELLOW) + if i != 0 { + start_pos : rl.Vector2 = start_base + (perpendicular*wave[i]*amp) + end_pos = end_base + (perpendicular*wave[i+1]*amp) + rl.DrawLineEx(start_pos, end_pos, 4, line_color) + rl.DrawCircleV(start_pos, 5, dot_color) + } // Text on each point point_font_size :: 24 end_value := wave[i+1] - end_text := fmt.caprintf("%.1f", end_value, allocator = context.temp_allocator) + end_text : cstring + end_text = fmt.caprintf("%.1f", end_value, allocator = context.temp_allocator) value_pos := (end_base + (perpendicular*(wave[i+1]*amp-25))) - (rl.MeasureTextEx(font, end_text, point_font_size, 0)*0.5) rl.DrawTextEx(font, end_text, value_pos, point_font_size, 0, rl.GRAY) } - rl.DrawCircleV(end_pos, 5, YELLOW) + rl.DrawCircleV(end_pos, 5, dot_color) + + name_font_size :: 34 + name_pos := (start - (rl.MeasureTextEx(font, name, name_font_size, 0)*{1,0})) + rl.DrawTextEx(font, name, name_pos, name_font_size, 0, rl.LIGHTGRAY) +} + +draw_centerline :: proc() { + if state.centerline_thickness < 0.5 do return + line_direction := state.grid_end - state.grid_start + centerline_start := state.grid_start + ( line_direction * (1.0/(f32(len(waveform_a))-1)) ) - rl.DrawTextEx(font, name, start, 32, 0, rl.LIGHTGRAY) + color := rl.WHITE + color.a = u8(math.min(state.centerline_thickness*0.3, 1)*255) + + rl.DrawCircleV(centerline_start, state.centerline_thickness, color) + rl.DrawLineEx( centerline_start, state.grid_end, state.centerline_thickness, color) + rl.DrawCircleV(state.grid_end, state.centerline_thickness, color) } draw_grid :: proc(first : rl.Vector2, last : rl.Vector2, data : []cell) { @@ -394,7 +712,7 @@ draw_grid :: proc(first : rl.Vector2, last : rl.Vector2, data : []cell) { color.a = u8(255.0*state.grid_opacity) text_color := rl.WHITE text_color.a = u8(255.0*state.grid_data_opacity) - cost_font_size :: 28 + cost_font_size :: 30 for cell, i in data { // Cell bg color @@ -433,7 +751,7 @@ draw_grid :: proc(first : rl.Vector2, last : rl.Vector2, data : []cell) { diff := arrow_end - arrow_start arrow_start += diff*state.arrow_chopping arrow_end -= diff*state.arrow_chopping - draw_arrow(arrow_start, arrow_end) + draw_arrow(arrow_start, arrow_end, cell.stepped_in) } } } @@ -442,9 +760,20 @@ middle_of_rect :: proc(rect : rl.Rectangle) -> rl.Vector2 { return {rect.x+(rect.width*0.5), rect.y+(rect.height*0.5)} } -draw_arrow :: proc(start, end : rl.Vector2) { +draw_arrow :: proc(start, end : rl.Vector2, whitening : f32=0) { thickness := state.arrow_thickness + if thickness < 0.1 do return + opacity : u8 = u8(255*min(thickness/2, 1)) + + core_color := ORANGE + core_color.a = opacity + outline := thickness*0.8 + outline_color := BLACK + outline_color.a = opacity + + white := rl.WHITE + white.a = u8(255*whitening*min(thickness/2, 1)) total_direction := end - start perpendicular : rl.Vector2 = normalize({total_direction.y, -total_direction.x}) @@ -453,24 +782,35 @@ draw_arrow :: proc(start, end : rl.Vector2) { right_hand : rl.Vector2 = end + (reverse*10) + (perpendicular*-10) left_hand : rl.Vector2 = end + (reverse*10) + (perpendicular*10) - rl.DrawLineEx(start, end, thickness+outline, BLACK) - rl.DrawLineEx(end, right_hand, thickness+outline, BLACK) - rl.DrawLineEx(end, left_hand, thickness+outline, BLACK) + rl.DrawLineEx(start, end, thickness+outline, outline_color) + rl.DrawLineEx(end, right_hand, thickness+outline, outline_color) + rl.DrawLineEx(end, left_hand, thickness+outline, outline_color) - rl.DrawCircleV(start, (thickness+outline)*0.5, BLACK) - rl.DrawCircleV(end, (thickness+outline)*0.5, BLACK) - rl.DrawCircleV(right_hand, (thickness+outline)*0.5, BLACK) - rl.DrawCircleV(left_hand, (thickness+outline)*0.5, BLACK) + rl.DrawCircleV(start, (thickness+outline)*0.5, outline_color) + rl.DrawCircleV(end, (thickness+outline)*0.5, outline_color) + rl.DrawCircleV(right_hand, (thickness+outline)*0.5, outline_color) + rl.DrawCircleV(left_hand, (thickness+outline)*0.5, outline_color) - rl.DrawLineEx(start, end, thickness, ORANGE) - rl.DrawLineEx(end, right_hand, thickness, ORANGE) - rl.DrawLineEx(end, left_hand, thickness, ORANGE) + rl.DrawLineEx(start, end, thickness, core_color) + rl.DrawLineEx(end, right_hand, thickness, core_color) + rl.DrawLineEx(end, left_hand, thickness, core_color) - rl.DrawCircleV(start, thickness*0.5, ORANGE) - rl.DrawCircleV(end, thickness*0.5, ORANGE) - rl.DrawCircleV(right_hand, thickness*0.5, ORANGE) - rl.DrawCircleV(left_hand, thickness*0.5, ORANGE) + rl.DrawCircleV(start, thickness*0.5, core_color) + rl.DrawCircleV(end, thickness*0.5, core_color) + rl.DrawCircleV(right_hand, thickness*0.5, core_color) + rl.DrawCircleV(left_hand, thickness*0.5, core_color) + + if whitening > 0 { + rl.DrawLineEx(start, end, thickness, white) + rl.DrawLineEx(end, right_hand, thickness, white) + rl.DrawLineEx(end, left_hand, thickness, white) + + rl.DrawCircleV(start, thickness*0.5, white) + rl.DrawCircleV(end, thickness*0.5, white) + rl.DrawCircleV(right_hand, thickness*0.5, white) + rl.DrawCircleV(left_hand, thickness*0.5, white) + } } @@ -524,6 +864,17 @@ main :: proc() { go_forward = left_clicked || rl.IsKeyReleased(.RIGHT) || rl.IsKeyReleased(.PAGE_DOWN) go_back = right_clicked || rl.IsKeyReleased(.LEFT) || rl.IsKeyReleased(.PAGE_UP) + if rl.IsKeyReleased(.HOME) do slide = 0 + if rl.IsKeyReleased(.END) do slide = len(slides)-1 + + if rl.IsKeyReleased(.ENTER) { + rl.ToggleBorderlessWindowed() + height := f32(rl.GetScreenHeight()) + width := f32(rl.GetScreenWidth()) + camera.offset = {width / 2, height / 2} + camera.zoom = height/1080 + } + // Process //---------------------------------------------------------------------------------- @@ -538,6 +889,8 @@ main :: proc() { target = slides[slide] data_target = data_frames[slide] + waveform_warped_target = waveform_warped_frames[slide] + waveform_path_target = waveform_path_frames[slide] lerp() // Draw @@ -552,13 +905,16 @@ main :: proc() { draw_waveform(waveform_a[:], state.wave_a_start, state.wave_a_end, state.wave_a_amp, "Boom") draw_waveform(waveform_b[:], state.wave_b_start, state.wave_b_end, state.wave_b_amp, "Lav") - draw_grid(grid_start, grid_end, data_state[:]) + draw_waveform(waveform_warped[:], state.wave_warp_start, state.wave_warp_end, state.wave_warp_amp, "Lav Warped") + draw_waveform(waveform_path[:], state.wave_path_start, state.wave_path_end, state.wave_path_amp, "Offset", true) + draw_grid(state.grid_start, state.grid_end, data_state[:]) highlight_color := YELLOW highlight_color.a = u8(255*state.highlight_opacity) rl.DrawRectangleLinesEx({state.highlight_position.x, state.highlight_position.y, state.highlight_dimensions.x, state.highlight_dimensions.y}, HIGHLIGHT_THICKNESS, highlight_color) + draw_centerline() rl.EndMode2D() |