元胞自动机 C实现 + OpenCV界面
来源:互联网 发布:windows ftp登录命令 编辑:程序博客网 时间:2024/05/19 15:24
前面
元胞自动机
建模的时候一直听到但是不知道干啥的
然后找了点代码还是不知道他干嘛的
反正蛮好看就是了orz
https://zh.wikipedia.org/zh-hans/%E7%B4%B0%E8%83%9E%E8%87%AA%E5%8B%95%E6%A9%9F
https://zh.wikipedia.org/wiki/%E5%BA%B7%E5%A8%81%E7%94%9F%E5%91%BD%E6%B8%B8%E6%88%8F
类似这种的自然演变的模型都一副(我就笑笑不说话)的样子
或许有着某些规律把
http://www.cnblogs.com/Firefly727/articles/1856328.html
这是一个很详细(但是排版很糟糕)的介绍
http://www.cnblogs.com/Firefly727/articles/1856328.html
这是一个比较成形的proj。
代码
C++(?)的代码
OpenCV(3.3.1)的界面,顺便取随机数用的也是OpenCV的RNG模块。
main.cpp
//Birdy 2017/12/7#include "opencv2/core.hpp"#include "opencv2/imgproc.hpp"#include "opencv2/highgui.hpp"#include "app.h"#include <stdio.h>using namespace cv;int main(){ char wndname[] = "Demo - Birdy"; int i, width = 1000, height = 800; RNG rng(0xFFFFFFFF); Mat image = Mat::zeros(height, width, CV_8UC3); class ca rand(rng); rand.nextstep(); for (int t = 0; t < 200; t++) { image = Mat(height, width, CV_8UC3, Scalar(0, 0, 0)); for (int i = 0; i < 60; i++) { for (int j = 0; j < 60; j++) { if (rand.a[i][j] == 1) { circle(image, Point(200 + 10 * i, 100 + 10 * j), 5, Scalar(200 + rng.uniform(0, 50), 100, 0), 1, LINE_AA); } } } imshow(wndname, image); waitKey(50); rand.nextstep(); } waitKey(); return 0;}
ca.h
#pragma once#include "opencv2/core.hpp"#include "opencv2/imgproc.hpp"#include <stdio.h>using namespace cv;class ca{public: bool a[60][60]; ca(RNG &rng); void nextstep();};
ca.cpp
#include "app.h"#include <math.h>ca::ca(RNG & rng){ for (int i = 1; i < 59; i++) { for (int j = 1; j < 59; j++) { if (rng.uniform(0, 20) < 2) { a[i][j] = 1; } else { a[i][j] = 0; } } }}void ca::nextstep(){ bool c[60][60]; for (int i = 1; i < 59; i++) { for (int j = 1; j < 59; j++) { int count = a[i - 1][j - 1] + a[i - 1][j] + a[i - 1][j + 1] + a[i][j - 1] + a[i][j + 1] + a[i + 1][j - 1] + a[i + 1][j] + a[i + 1][j + 1]; if (count == 2) { c[i][j] = a[i][j]; } else if (count == 3) { c[i][j] = 1; } else { c[i][j] = 0; } } } memcpy(*a, *c, sizeof(bool) * 3600);}
后面
效果
加一幅图(我找不到出处了反正不是我画的orz)、或许是找资料过程中印象最深的东西了
肯定有一天能画小绿小蓝的
阅读全文
0 0
- 元胞自动机 C实现 + OpenCV界面
- 分享C/C++ 行车元胞自动机
- 元胞自动机 Matlab实现表面张力
- 元胞自动机
- 元胞自动机
- 元胞自动机
- 元胞自动机
- 什么是元胞自动机
- 元胞自动机
- 元胞自动机简介
- 元胞自动机 生命游戏 Matlab实现 GUI
- 用javascript实现元胞自动机的生命游戏
- 元胞自动机简介(CA自动机)
- 二维元胞自动机扩展
- C#绘图实现元胞自动机之生命的游戏(分形之美)
- 元胞自动机(Cellular Automata)
- 元胞自动机与生命游戏
- 元胞自动机的Java模型代码
- Gym
- deepmind_lab 运行ASSETS 需要下面的东西
- Multiples of 3 and 5
- HDU2680 Choose the best route(最短路)
- 什么是事件分发线程
- 元胞自动机 C实现 + OpenCV界面
- d3.js-选择集与数据
- python3—3一些常见的细节处理
- IntelliJ IDEA启动Tomcat后,无法访问Tomcat主页
- django入门一(整体流程)
- AOP使用方法
- 第5章 目录配置规范
- 【bzoj 1004】 Cards 【HNOI2008】
- 《陋室铭》《陋妻铭》《微信铭》《交友铭》《老人铭》