电子工程师技术服务社区
- 社区首页
- 下载
- fract.zip
资料描述
stm32f746disc开发板上有一个很大的液晶屏,可以显示各种图像。下面展示了用开发板显示奇妙的分形图形。
这里不介绍分形的理论了,大家可以网上搜索看看,它的计算公式是 z = z*z + c,反复迭代计算,根据发散速度标明各点的颜色。
先看看实际效果,手机拍出来有些条纹,实际是没有的,液晶屏上显示的效果其实还不错。
下面是的程序代码。目前只做了基本的显示,下一步将增加放大、缩小、改变颜色等功能。
#include "mbed.h"
#include "lcd_disco_f746ng.h"
#include "ts_disco_f746ng.h"
#define iteration 150
#define bailout 4
lcd_disco_f746ng lcd;
ts_disco_f746ng ts;
uint16_t screen_width, screen_height;
uint16_t calcmandelbrot(double x, double y)
{
uint16_t i;
double xx, yy, tx, ty;
xx = yy = 0;
i = 0;
while((i < iteration) && ((xx*xx + yy*yy) < bailout))
{
tx = xx*xx - yy*yy + x;
ty = 2*xx*yy + y;
xx = tx;
yy = ty;
i++;
}
return i;
}
void rectmandelbrot(double x1, double y1, double x2, double y2)
{
double dx, dy;
uint16_t i, j;
uint32_t color;
dx = (x2 - x1)/screen_width;
dy = (y2 - y1)/screen_height;
for(i = 0; i < screen_width; i++)
{