diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..874c63c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c8d9935 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +.PHONY: all clean test + +ALL= swirl naruto slant + +%: %.o + $(CC) $< $(LDFLAGS) -o $@ + +all: $(ALL) + +swirl: swirl.o +naruto: naruto.o +slant: slant.o + +clean: + rm -f *.o $(ALL) + +test: $(ALL) + @echo "-------swirl--------" + @echo "* 20 20" | ./swirl + @echo "-------naruto-------" + @echo "* 20 20" | ./naruto + @echo "-------slant--------" + @echo "* 20 20" | ./slant + +LDFLAGS=-lm diff --git a/naruto.c b/naruto.c new file mode 100644 index 0000000..38338d4 --- /dev/null +++ b/naruto.c @@ -0,0 +1,89 @@ +// drawing NARUTO +// Usage: +// $ echo "* 30 15" | ./naruto +// * ************ +// * * * +// * * ******** * +// * * * * * +// * * * **** * * +// * * * * * * * +// * * * ** * * * +// * * * ** * * * +// * * * ** * * * +// * * * * * * +// * * ****** * * +// * * * * +// * ********** * +// * * +// ************** + +#include +#include + +int main() +{ + int w, h, wh, hh, x, y; + int w_even=0, h_even=0, side=0; + char s, t; + char c; + + scanf("%c%c %d %d", &s, &t, &w, &h); + +/* + + stragegy for NARUTO + + + *^********* + * ^ * + * *^***** * + * * ^ * * + * * *^* * * + * * * * * * + * * *** * * + * * * * + * ******* * + * * + *********** + + (1) draw squares + (2) xor '^' (NARUTO point) +*/ + + if ((w & 1) == 0) w_even = 1; // Is width even? + if ((h & 1) == 0) h_even = 1; // Is height even? + if ((w & 2) != 0) side = 1; // Is width 4n + a(a=0,1)? + + wh = w/2; hh = h/2; // center point + + for (y = 0; y< h; y++) { + for (x = 0; x< w; x++) { + int x2 = x-wh, y2 = y - hh; // set center to origin + + if (x2 >= 0) { x2 += w_even; } // if width or height is even + if (y2 >= 0) { y2 += h_even; } // trancate x/y axis by 1. + + if (x2 < -hh || y2 < -wh || + x2 > hh || y2 > wh) { // out of canvas + c = t; + } else if (labs(x2) < labs(y2)) {// RULE for horizontal line of square + if ((labs(y2) % 2) == side) + c = s; + else + c = t; + } else { // RULE for vertical line of square + if ((labs(x2) % 2) == side) + c = s; + else + c = t; + } + + if (x2 <= 0 && y2 <= 0 && + (x2 - 1) == y2) { // xor NARUTO point + c = (s+t) - c; + } + + putchar(c); + } + putchar('\n'); + } + return 0; +} diff --git a/slant.c b/slant.c new file mode 100644 index 0000000..70d7156 --- /dev/null +++ b/slant.c @@ -0,0 +1,55 @@ +// drawing slanted NARUTO +// +// Usage: +// $ echo "* 30 15" | ./slant +// * * * * * * * * * * +// * * * * * * * * * * +// * * * * * * * * * * +// * * * * * * * * * * +// * * * * * * * * * * +// * * * * * * * * * * +// * * * * * * * * * * +// * * * * * * * * * * +// * * * * * * * * * * +// * * * * * * * * * * +// * * * * ** * * * * +// * * * * * * * * * * +// * * * * * * * * * * +// * * * * ** * * * * +// * * * * * * * * * * + + +#include +#include + +main() +{ + int w, h, wh, hh, x, y; + char s, t; + int max; + + scanf("%c%c %d %d", &s, &t, &w, &h); + + wh = w/2; hh = h/2; // center point + + for (y = -hh; y< hh; y++) { + for (x = -wh; x< wh; x++) { + int r, gap = 0; + + // if the point is on the right half area + // displace holizontally by 1 + if (x > 0) gap = 1; + + // calc Manhattan dist. + r= labs(x) + labs(y+gap); + + if (r % 3 == 0) // period 3 + putchar(s); + else + putchar(t); + } + putchar('\n'); + } + return 0; +} + diff --git a/swirl.c b/swirl.c new file mode 100644 index 0000000..3c6a2ab --- /dev/null +++ b/swirl.c @@ -0,0 +1,56 @@ +// drawing swirl +// Usage: +// $ echo "* 30 15" | ./swirl +// ** ** ** +// ** * ** +// * *** ** * *** +// ** *** ** ******** +// ** ***** *** ** +// *** ******* ** +// * ************ * +// * ************* +// * ************ +// ** ******* *** +// ** *** ***** ** +// ******** ** *** ** +// *** * ** *** * +// ** * ** +// ** ** ** + +#include +#include // for labs +#include // for sin, cos + +int main() +{ + int w, h, wh, hh, x, y; + char s, t; + int max; + + scanf("%c%c %d %d", &s, &t, &w, &h); + max = (w*w+ h*h)/4; // normalization coeff. + wh = w/2; hh = h/2; // center point + + for (y = -hh; y< hh; y++) { + for (x = -wh; x< wh; x++) { + int r = x*x + y*y; // dist. from origin + int tx, ty; + + double sn = sin((double)r/max), // for the + cs = cos((double)r/max); // rotation matrix + + tx = (int)(x * cs - y * sn); // rotate + ty = (int)(x * sn + y * cs); // rotate + + // if the transformed point is on the x/y axis or + // 45/135 degree line(in +-1 because error) + if (tx == 0 || ty == 0 || + labs(tx - ty) < 2 || labs(tx + ty) < 2) + putchar(s); + else + putchar(t); + } + putchar('\n'); + } + return 0; +}