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

  • 相关阅读:
    jQuery基础开发详解 重要
    Jquery插件form和cookie
    javascript keycode大全
    用户体验一些链接
    SQL导入Excel数据时,数字中混有字符将导致数据丢失的解决办法
    列出本机所有固定驱动器和可移动驱动器
    ADOQUERY,CLIENTDATASET,ADOSTOREPROC执行存储过程【多种方法】
    如何发布 JSON 项目?[转橙子]
    ADOQUERY,CLIENTDATASET,ADOSTOREPROC执行存储过程【多种方法】
    ADOQUERY,CLIENTDATASET,ADOSTOREPROC执行存储过程【多种方法】
  • 原文地址:https://www.cnblogs.com/qilinzi/p/3081000.html
Copyright © 2011-2022 走看看