zoukankan      html  css  js  c++  java
  • FlasCC例子研究之Drawing

    这个例子主要是向大家展示 voronoi 图的绘制方法。

    Voronoi图,又叫泰森多边形Dirichlet图,其具体介绍可以参见这里http://baike.baidu.com/view/501103.htm,这不是本例子的重点。

    这个例子并没有向大家展示太多的东西,AS3相关的调用和C API的使用,也和先前没有太多区别。 唯 一不同的是,这个例子的voronoi图的生成,使用了C++ class. 也就是说,这个例子,让大家看到FlasCC对C++的支持。

    下面的代码,是例子原生代码,中间并没有注释。 这是因为,已经不需要注释了。所用到的,都是前面 Interop中已经介绍了的内容。

    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>
    #include "VoronoiDiagramGenerator.h"
    #include "AS3/AS3.h"

    int main(int argc,char **argv)
    {
        int stagewidth, stageheight;
        inline_as3(
            "import flash.display.Stage;\n"
            "import flash.display.Graphics;\n"
            "import com.adobe.flascc.CModule;\n"
            "var gfx = CModule.rootSprite.graphics;\n"
            "gfx.lineStyle(1, 0);\n"
            "gfx.beginFill(0, 0.0);\n"
            "%0 = CModule.rootSprite.stage.stageWidth;\n"
            "%1 = CModule.rootSprite.stage.stageHeight;\n"
            : "=r"(stagewidth),"=r"(stageheight) :
        );
        const int cellcount = 512;
        float xvals[cellcount], yvals[cellcount];
        for(int i=0; i<cellcount; i++) {
            xvals[i] = stagewidth * ((float)rand()/(float)RAND_MAX);
            yvals[i] = stageheight * ((float)rand()/(float)RAND_MAX);
        }

        VoronoiDiagramGenerator vdg;
        vdg.generateVoronoi(xvals, yvals, cellcount, 0, stagewidth, 0, stageheight, 3);
        vdg.resetIterator();

        float x1,y1,x2,y2;
        while(vdg.getNext(x1,y1,x2,y2))
        {
            inline_as3("gfx.moveTo(%0,%1);\n" : : "r"(x1), "r"(y1));
            inline_as3("gfx.lineTo(%0,%1);\n" : : "r"(x2), "r"(y2));
        }
        inline_as3("gfx.endFill();\n");
    }

    来个图!

    image

  • 相关阅读:
    Shell高级编程学习笔记(基础篇)
    基于Python的机器学习实战:Apriori
    基于Python的机器学习实战:AadBoost
    Theano教程:Python的内存管理
    基于theano的降噪自动编码器(Denoising Autoencoders--DA)
    基于theano的深度卷积神经网络
    推荐系统之矩阵分解及C++实现
    推荐系统之协同过滤的原理及C++实现
    一步一步详解ID3和C4.5的C++实现
    Principal components analysis(PCA):主元分析
  • 原文地址:https://www.cnblogs.com/qilinzi/p/3081000.html
Copyright © 2011-2022 走看看