wrights-deck/cards.asy

116 lines
3.5 KiB
Plaintext

import "scaling.asy" as scaling;
import "suits.asy" as suits;
import "numerals.asy" as numerals_paths;
import "nobles.asy" as nobles;
import "faces.asy" as general_faces;
import "cards-faces.asy" as cards_faces;
real corner_radius = width/12;
path corner = arc(((width/2 - corner_radius), (height/2 - corner_radius)), corner_radius, 0, 90);
path card = corner--reverse(reflect((0,0), (0,1))*corner)--rotate(180)*corner--reverse(reflect((0,0), (1,0))*corner)--cycle;
real scpx = 0.2;
real scpy = 0.325;
transform placements[][] = {
// 0
{},
// 1
{ identity },
// 2
{ shift(0,height*scpy), shift(0,-height*scpy)*rotate(180) },
// 3
{ identity, shift(0,height*scpy), shift(0,-height*scpy)*rotate(180) },
// 4
{ shift(width*scpx,height*scpy), shift(width*scpx,-height*scpy)*rotate(180), shift(-width*scpx,height*scpy), shift(-width*scpx,-height*scpy)*rotate(180) },
// 5
{ identity, shift(width*scpx,height*scpy), shift(width*scpx,-height*scpy)*rotate(180), shift(-width*scpx,height*scpy), shift(-width*scpx,-height*scpy)*rotate(180) },
// 6
{ shift(width*scpx,0), shift(-width*scpx,0), shift(width*scpx,height*scpy), shift(width*scpx,-height*scpy)*rotate(180), shift(-width*scpx,height*scpy), shift(-width*scpx,-height*scpy)*rotate(180) },
// The four face cards
{}, {}, {}, {},
};
real scale_factor = 0.175;
real one_scale_factor = 0.4;
real numeral_scale_factor = 0.125;
pair numeral_pos = (-width*0.4, height*0.4);
real indicator_scale_factor = 0.085;
pair indicator_pos = (-width*0.4, height*0.275);
// note: if you bump this depth value to 4, you'll need to set
// buf_size=5000000 so latex doesn't choke
path[] recursive_card(int value, int suit, int depth=4, bool outermost=true) {
path result[];
if (!outermost) {
result.push(card);
}
path[] suit_icon;
if (suit == CARDS) {
if (depth == 0) { return result; }
suit_icon = recursive_card(value, suit, depth - 1, false);
} else {
suit_icon = icons[suit];
}
path[] indicator = shift(indicator_pos)*scale(indicator_scale_factor)*suit_icon;
path[] numeral = numerals[value];
numeral = shift(numeral_pos)*scale(numeral_scale_factor)*numeral;
result = result^^indicator^^(rotate(180)*indicator)^^numeral^^(rotate(180)*numeral);
real current_scale_factor = scale_factor;
if (value == 1) {
current_scale_factor = one_scale_factor;
}
for(int i = 0; i < placements[value].length; ++i) {
result = result^^(placements[value][i]*scale(current_scale_factor)*suit_icon);
}
return result;
}
picture recursive_face_card(int value, int suit, int depth=4, bool invertcolor=false) {
pen fg;
if (invertcolor) {
fg = white+evenodd;
} else {
fg = suit_colors[suit]+evenodd;
}
picture p = new picture;
picture suit_icon = new picture;
if (suit == CARDS) {
if (depth == 0) {
return p;
}
fill(p, cards_face_placements[value]*card, fg);
picture subcard = recursive_face_card(value, suit, depth-1, !invertcolor);
add(p, cards_face_placements[value]*subcard);
cards_faces[value](p, fg);
suit_icon = new picture;
fill(suit_icon, card, fg);
add(suit_icon, subcard);
} else {
add(p, faces[suit][value]);
fill(suit_icon, icons[suit], fg);
}
picture indicator = shift(indicator_pos)*scale(indicator_scale_factor)*suit_icon;
path[] numeral = numerals[value];
numeral = shift(numeral_pos)*scale(numeral_scale_factor)*numeral;
fill(p, numeral^^(rotate(180)*numeral), fg);
add(p, indicator);
add(p, rotate(180)*indicator);
return p;
}