Skip to content

Commit

Permalink
added numbers to strokes
Browse files Browse the repository at this point in the history
  • Loading branch information
MyK00L committed Jun 21, 2024
1 parent ddfe535 commit a478a20
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
13 changes: 11 additions & 2 deletions src/anim_cjk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@ pub struct GraphicsEntry {
pub character: char,
pub strokes: Vec<String>,
#[allow(unused)]
medians: Vec<Vec<(f32, f32)>>, // TODO: use this for automatic checking if character was drawn correctly?
medians: Vec<Vec<(i32, i32)>>, // TODO: use this for automatic checking if character was drawn correctly?
}
impl From<GraphicsEntry> for WordEntry {
fn from(o: GraphicsEntry) -> Self {
let mut w = WordEntry::from_id(o.character.into());
w.writing = vec![CharWriting::Strokes(o.strokes)];
w.writing = vec![CharWriting::Strokes(
o.strokes
.into_iter()
.zip(o.medians.into_iter())
.map(|(s, m)| Stroke {
path: s,
start: m[0],
})
.collect(),
)];
w
}
}
Expand Down
33 changes: 25 additions & 8 deletions src/anki.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,31 @@ fn anki_canvas_contrast(idx: usize) -> String {
let (r, g, b) = rgb(h, s, v);
format!("#{:02x}{:02x}{:02x}", r, g, b)
}
fn svg_from_strokes(strokes: Vec<String>, i0: usize) -> String {
fn svg_from_strokes(strokes: Vec<Stroke>, i0: usize) -> String {
format!(
r#"<svg class="charvg" viewbox="0 0 1024 1024"><g transform="scale(1, -1) translate(0, -900)">{}</g></svg>"#,
r#"<svg class="charvg" viewbox="0 0 1024 1024"><g transform="scale(1, -1) translate(0, -900)">{}</g>{}</svg>"#,
strokes
.iter()
.enumerate()
.map(|(i, stroke)| format!(
r#"<path d="{}" fill="{}"></path>"#,
stroke,
anki_canvas_contrast(i0 + i)
))
.map(|(i, stroke)| {
format!(
r#"<path d="{}" fill="{}"></path>"#,
stroke.path,
anki_canvas_contrast(i0 + i),
)
})
.fold(String::new(), |acc, e| acc + &e),
strokes
.iter()
.enumerate()
.map(|(i, stroke)| {
format!(
r#"<text x="{}" y="{}" stroke="white" fill="black">{}</text>"#,
stroke.start.0,
900 - stroke.start.1,
i0 + i + 1
)
})
.fold(String::new(), |acc, e| acc + &e)
)
}
Expand All @@ -225,10 +239,13 @@ fn html_from_writing(w: Vec<CharWriting>) -> String {
for c in w.into_iter() {
let ns = match &c {
CharWriting::Strokes(strokes) => strokes.len(),
CharWriting::Char(_c) => 1,
CharWriting::Char(_c) => 0,
};
cw.push(html_from_char_writing(c, i0));
i0 += ns;
if ns == 0 {
i0 = 0;
}
}
format!(r#"<p class="tc">{}</p>"#, cw.join(""))
}
Expand Down
7 changes: 6 additions & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,14 @@ pub struct Priority {
pub max: NotNan<f32>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Stroke {
pub path: String,
pub start: (i32, i32),
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum CharWriting {
Strokes(Vec<String>),
Strokes(Vec<Stroke>),
Char(char),
}

Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ fn debug_entries(entries: Vec<CommonEntry>) {
}
}

//TODO: make it clear where the strokes begin
fn main() {
//cache_entries();return;
let entries = get_cached_entries();
Expand Down

0 comments on commit a478a20

Please sign in to comment.