Cistercian numerals: Difference between revisions
Content added Content deleted
m (→{{header|Rust}}: remove unneeded decorations) |
|||
Line 5,029: | Line 5,029: | ||
/// initialize CANVAS |
/// initialize CANVAS |
||
fn init_n() { |
|||
for i in 0..GRID_SIZE { |
for i in 0..GRID_SIZE { |
||
for j in 0..GRID_SIZE { |
for j in 0..GRID_SIZE { |
||
CANVAS[i][j] = ' '; |
unsafe { CANVAS[i][j] = ' '; } |
||
} |
} |
||
CANVAS[i][5] = '#'; |
unsafe { CANVAS[i][5] = '#'; } |
||
} |
} |
||
} |
} |
||
/// draw horizontal |
/// draw horizontal |
||
fn horizontal(c1: usize, c2: usize, r: usize) { |
|||
for c in c1..=c2 { |
for c in c1..=c2 { |
||
CANVAS[r][c] = '#'; |
unsafe { CANVAS[r][c] = '#'; } |
||
} |
} |
||
} |
} |
||
/// draw vertical |
/// draw vertical |
||
fn vertical(r1: usize, r2: usize, c: usize) { |
|||
for r in r1..=r2 { |
for r in r1..=r2 { |
||
CANVAS[r][c] = '#'; |
unsafe { CANVAS[r][c] = '#'; } |
||
} |
} |
||
} |
} |
||
/// draw diagonal NE to SW |
/// draw diagonal NE to SW |
||
fn diag_d(c1 : usize, c2: usize, r: usize) { |
|||
for c in c1..=c2 { |
for c in c1..=c2 { |
||
CANVAS[r + c - c1][c] = '#'; |
unsafe { CANVAS[r + c - c1][c] = '#'; } |
||
} |
} |
||
} |
} |
||
/// draw diagonal SE to NW |
/// draw diagonal SE to NW |
||
fn diag_u(c1: usize, c2: usize, r: usize) { |
|||
for c in c1..=c2 { |
for c in c1..=c2 { |
||
CANVAS[r + c1 - c][c] = '#'; |
unsafe { CANVAS[r + c1 - c][c] = '#'; } |
||
} |
} |
||
} |
} |
||
/// Mark the portions of the ones place. |
/// Mark the portions of the ones place. |
||
fn draw_ones(v: i32) { |
|||
match v { |
match v { |
||
1 => horizontal(6, 10, 0), |
1 => horizontal(6, 10, 0), |
||
Line 5,083: | Line 5,083: | ||
/// Mark the portions of the tens place. |
/// Mark the portions of the tens place. |
||
fn draw_tens(v: i32) { |
|||
match v { |
match v { |
||
1 => horizontal(0, 4, 0), |
1 => horizontal(0, 4, 0), |
||
Line 5,099: | Line 5,099: | ||
/// Mark the portions of the hundreds place. |
/// Mark the portions of the hundreds place. |
||
fn draw_hundreds(hundreds: i32) { |
|||
match hundreds { |
match hundreds { |
||
1 => horizontal(6, 10, 14), |
1 => horizontal(6, 10, 14), |
||
Line 5,115: | Line 5,115: | ||
/// Mark the portions of the thousands place. |
/// Mark the portions of the thousands place. |
||
fn draw_thousands(thousands: i32) { |
|||
match thousands { |
match thousands { |
||
1 => horizontal(0, 4, 14), |
1 => horizontal(0, 4, 14), |
||
Line 5,131: | Line 5,131: | ||
/// Mark the char matrix for the numeral drawing. |
/// Mark the char matrix for the numeral drawing. |
||
fn draw(mut v: i32) { |
|||
let thousands: i32 = v / 1000; |
let thousands: i32 = v / 1000; |
||
v %= 1000; |
v %= 1000; |
||
Line 5,152: | Line 5,152: | ||
} |
} |
||
/// Test the drawings as |
/// Test the drawings as outout to stdout. |
||
fn test_output(n: i32) { |
fn test_output(n: i32) { |
||
println!("{n}"); |
println!("{n}"); |
||
⚫ | |||
⚫ | |||
unsafe { |
unsafe { |
||
⚫ | |||
⚫ | |||
for line in CANVAS.iter() { |
for line in CANVAS.iter() { |
||
for c in line.iter() { |
for c in line.iter() { |