Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- masato
- Date:
- 2013-06-16
- Revision:
- 0:b06afbefd350
- Child:
- 1:84b2d36d57f0
File content as of revision 0:b06afbefd350:
#include "mbed.h"
#include "c128x64spi.h"
c128x64spi fstn(PTD2, PTD3, PTD1, PTD0, PTD5, PTA13); // mosi, miso, sclk, cs, rs, reset
Serial pc(USBTX, USBRX);
#define COLOR 1
#define BG_COLOR 0
void Dragon(int x1,int y1,int x2,int y2,int lv)
{
// pc.printf("Enter Dragon(%d,%d,%d,%d,%d)\r\n", x1, y1, x2, y2, lv);
int h,x3,y3;
if (x1 == x2) {
h = abs(y1 - y2) / 2;
if (h * lv == 0) {
fstn.line(x1, y1, x2, y2, COLOR); //ここで(x1,y1)から(x2,y2)まで線を描く
} else {
if (y1 < y2) {
x3 = x1 + h;
y3 = y1 + h;
} else {
x3 = x1 - h;
y3 = y1 - h;
}
Dragon(x1, y1, x3, y3, lv - 1);
Dragon(x2, y2, x3, y3, lv - 1);
}
} else if (y1 == y2) {
h = abs(x1 - x2) / 2;
if (h * lv == 0) {
fstn.line(x1, y1, x2, y2, COLOR);//ここで(x1,y1)から(x2,y2)まで線を描く
} else {
if (x1 < x2) {
x3 = x1 + h;
y3 = y1 - h;
} else {
x3 = x1 - h;
y3 = y1 + h;
}
Dragon(x1,y1,x3,y3,lv - 1);
Dragon(x2,y2,x3,y3,lv - 1);
}
} else {
if (lv == 0) {
fstn.line(x1, y1, x2, y2, COLOR);//ここで(x1,y1)から(x2,y2)まで線を描く
} else if (x1 < x2) {
if (y1 < y2) {
Dragon(x1,y1,x2,y1,lv - 1);
Dragon(x2,y2,x2,y1,lv - 1);
} else {
Dragon(x1,y1,x1,y2,lv - 1);
Dragon(x2,y2,x1,y2,lv - 1);
}
} else {
if (y1 < y2) {
Dragon(x1,y1,x1,y2,lv - 1);
Dragon(x2,y2,x1,y2,lv - 1);
} else {
Dragon(x1,y1,x2,y1,lv - 1);
Dragon(x2,y2,x2,y1,lv - 1);
}
}
}
// pc.printf("Leave Dragon(%d,%d,%d,%d,%d)\r\n", x1, y1, x2, y2, lv);
}
int main() {
int i, x, y;
pc.baud(9600);
pc.printf("start\r\n");
#if 0
for (y = 0; y < 64; y++)
for (x = 0; x < 128; x++)
fstn.pixel(x, y, 1);
wait(1);
for (y = 0; y < 64; y++)
for (x = 0; x < 128; x++)
fstn.pixel(x, y, 0);
wait(1);
fstn.clr(0);
for (x = 0; x < 64; x++)
fstn.pixel(x, x, 1);
wait(1);
fstn.clr(0);
fstn.hline(0, 127, 32, 1);
wait(1);
fstn.clr(0);
fstn.vline(63, 0, 63, 1);
wait(1);
fstn.clr(0);
fstn.line(0, 0, 127, 63, 1);
fstn.line(127, 0, 0, 63, 1);
wait(1);
#endif
// Dragon
while (1) {
for (i = 0; i < 12; i++) {
pc.printf("dragon %d\r\n", i);
fstn.clr(BG_COLOR);
Dragon(32, 42, 96, 42, i);
wait(0.5);
}
wait(20);
}
}