极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14631|回复: 3

Processing之旅-----【13课,2D绘图之曲线】

[复制链接]
发表于 2013-5-14 19:22:15 | 显示全部楼层 |阅读模式
好了同学们我们上课,如果讲到了2D绘图就不得不讲一讲曲线这个高深的问题。我记得我上图形学的时候老师讲了很久关于曲线的算法。但是现在一想基本忘光了。哈哈哈。献丑了。闲话少叙,我们看例子。
  1. //好了,同学们,我们今天这节课主要讲述,Processing中的2D绘制函数的
  2. //高级部分什么算高级部分呢?
  3. //当然是曲线了
  4. //
  5. //
  6. //
  7. //
  8. //
  9. //
  10. void setup(){
  11.         size(512, 512);
  12.         noFill();
  13.         stroke(255, 102, 0);
  14.         line(85, 20, 10, 10);
  15.         line(90, 90, 15, 80);
  16.         stroke(0, 0, 0);
  17.         bezier(85, 20, 10, 10, 90, 90, 15, 80);

  18.         // bezier(x1, y1, x2, y2, x3, y3, x4, y4)
  19.         // bezier(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)
  20.                
  21.         // x1         float: coordinates for the first anchor point 第一个支撑点x坐标
  22.         // y1         float: coordinates for the first anchor point 第一个支撑点y坐标
  23.         // z1         float: coordinates for the first anchor point 第一个支撑点z坐标
  24.         // x2         float: coordinates for the first control point 第一个控制点x坐标
  25.         // y2         float: coordinates for the first control point 第一个控制点y坐标
  26.         // z2         float: coordinates for the first control point 第一个控制点z坐标
  27.         // x3         float: coordinates for the second control point 第二个控制点x坐标
  28.         // y3         float: coordinates for the second control point 第二个控制点y坐标
  29.         // z3         float: coordinates for the second control point 第二个控制点z坐标
  30.         // x4         float: coordinates for the second anchor point 第二个支撑点x坐标
  31.         // y4         float: coordinates for the second anchor point 第二个支撑点y坐标
  32.         // z4         float: coordinates for the second anchor point 第二个支撑点z坐标
  33.         bezierDetail(100);
  34.     bezier(85, 20, 10, 10, 90, 90, 15, 80);
  35.         // bezierDetail(detail)
  36.                
  37.         // detail         int: resolution of the curves
  38.         bezier(85, 20, 10, 10, 90, 90, 15, 80);
  39.         fill(255);
  40.         int steps = 10;
  41.         for (int i = 0; i <= steps; i++)
  42.         {
  43.                 float t = i / float(steps);
  44.                 float x = bezierPoint(85, 10, 90, 15, t);
  45.                 float y = bezierPoint(20, 10, 90, 80, t);
  46.                 ellipse(x, y, 5, 5);
  47.         }

  48.         // bezierPoint(a, b, c, d, t)
  49.         // a         float: coordinate of first point on the curve
  50.         // b         float: coordinate of first control point
  51.         // c         float: coordinate of second control point
  52.         // d         float: coordinate of second point on the curve
  53.         // t         float: value between 0 and 1
  54.        
  55. }

  56. void draw(){
  57.                
  58. }
复制代码


效果如图,就是简单的对曲线入一个门,对于曲线,如果用得好,那就是一门艺术了。
好吧,同学们我们这节课下课。{:soso__13766225770624999893_6:}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2013-6-3 00:14:14 | 显示全部楼层
t的含义是什么?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-6-3 18:36:13 | 显示全部楼层
382619728 发表于 2013-6-3 00:14
t的含义是什么?

// bezierPoint(a, b, c, d, t)
        // a         float: coordinate of first point on the curve
        // b         float: coordinate of first control point
        // c         float: coordinate of second control point
        // d         float: coordinate of second point on the curve
        // t         float: value between 0 and 1

有详细的说明哦。
回复 支持 反对

使用道具 举报

发表于 2014-10-31 10:51:08 | 显示全部楼层
//好了,同学们,我们今天这节课主要讲述,Processing中的2D绘制函数的
//高级部分什么算高级部分呢?
//当然是曲线了
//
//
//
//
//
//
void setup(){
        size(512, 512);
        noFill();
        stroke(255, 102, 0);
        line(85, 20, 10, 10);
        line(90, 90, 15, 80);
        stroke(0, 0, 0);
        bezier(85, 20, 10, 10, 90, 90, 15, 80);

        // bezier(x1, y1, x2, y2, x3, y3, x4, y4)
        // bezier(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)

        // x1         float: coordinates for the first anchor point 第一个支撑点x坐标
        // y1         float: coordinates for the first anchor point 第一个支撑点y坐标
        // z1         float: coordinates for the first anchor point 第一个支撑点z坐标
        // x2         float: coordinates for the first control point 第一个控制点x坐标
        // y2         float: coordinates for the first control point 第一个控制点y坐标
        // z2         float: coordinates for the first control point 第一个控制点z坐标
        // x3         float: coordinates for the second control point 第二个控制点x坐标
        // y3         float: coordinates for the second control point 第二个控制点y坐标
        // z3         float: coordinates for the second control point 第二个控制点z坐标
        // x4         float: coordinates for the second anchor point 第二个支撑点x坐标
        // y4         float: coordinates for the second anchor point 第二个支撑点y坐标
        // z4         float: coordinates for the second anchor point 第二个支撑点z坐标
        bezierDetail(100);
    bezier(85, 20, 10, 10, 90, 90, 15, 80);
        // bezierDetail(detail)

        // detail         int: resolution of the curves
        bezier(85, 20, 10, 10, 90, 90, 15, 80);
        fill(255);
        /*
        int steps = 10;
        for (int i = 0; i <= steps; i++)
        {
                float t = i / float(steps);
                float x = bezierPoint(85, 10, 90, 15, t);
                float y = bezierPoint(20, 10, 90, 80, t);
                ellipse(x, y, 5, 5);
        }
        */

        // bezierPoint(a, b, c, d, t)
        // a         float: coordinate of first point on the curve
        // b         float: coordinate of first control point
        // c         float: coordinate of second control point
        // d         float: coordinate of second point on the curve
        // t         float: value between 0 and 1

}

void draw(){

}
交作业了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-25 16:34 , Processed in 0.060444 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表