极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 15207|回复: 2

Processing之旅-----【12课,2D绘画基础】

[复制链接]
发表于 2013-5-13 19:23:31 | 显示全部楼层 |阅读模式
本帖最后由 yangfanconan 于 2013-5-13 19:27 编辑

同学们我们上课,今天我们继续学习Processing的输出功能
//今天我们主要讲述Processing的2D绘画基础
//下面我会用一个小程序来详细说明每一个画图函数的用法。


  1. //同学们我们上课,今天我们继续学习Processing的输出功能
  2. //今天我们主要讲述Processing的2D绘画基础
  3. //下面我会用一个小程序来详细说明每一个画图函数的用法。
  4. //
  5. //
  6. //
  7. //
  8. //
  9. //
  10. void setup()
  11. {
  12.         size(512, 512);
  13.         //既然讲到2D绘画,那么颜色当然也得说一说
  14.         //颜色函数基本函数
  15.         colorMode(RGB);//一下是colorMode的使用方法        

  16.         // colorMode(mode)    mode         int: Either RGB or HSB, corresponding to Red/Green/Blue and Hue/Saturation/Brightness
  17.         // colorMode(mode, max) max 参数是对颜色变量的范围        
  18.         // colorMode(mode, max1, max2, max3) max1         
  19.         // colorMode(mode, max1, max2, max3, maxA)
  20.         
  21.         background(0, 0, 0, 0);//背景色设置函数(R,G,B,A)
  22.         //clear();//清除用的
  23.         fill(255, 0, 0, 100);//填充颜色
  24.         // noFill();//不进行填充
  25.          noStroke();//不绘画边界
  26.         //stroke(0, 255, 0, 0);//绘画边界,并设置边界颜色

  27.         arc(50, 55, 50, 50, 0, HALF_PI);//花一段弧线
  28.         ellipseMode(CENTER);//椭圆的模式 参数分别可以填RADIUS;CENTER CORNER CORNERS

  29.         //        ellipse(a, b, c, d)
  30.         // a         float: x-coordinate of the ellipse
  31.         // b         float: y-coordinate of the ellipse
  32.         // c         float: width of the ellipse by default
  33.         // d         float: height of the ellipse by default
  34.         ellipse(100, 100, 50, 50);//画一个椭圆的特例圆

  35.         // 画现函数的详情
  36.         // line(x1, y1, x2, y2)
  37.         // line(x1, y1, z1, x2, y2, z2)
  38.                
  39.         // x1         float: x-coordinate of the first point第一个点的x坐标
  40.         // y1         float: y-coordinate of the first point第一个点的y坐标
  41.         // x2         float: x-coordinate of the second point第二个点的x坐标
  42.         // y2         float: y-coordinate of the second point第二个点的y坐标
  43.         // z1         float: z-coordinate of the first point第一个点的z轴坐标
  44.         // z2         float: z-coordinate of the second point第二个点的z轴坐标
  45.         line(0, 0, width,height);//画一条线



  46.         // point(x, y)
  47.         // point(x, y, z)
  48.                
  49.         // x         float: x-coordinate of the point
  50.         // y         float: y-coordinate of the point
  51.         // z         float: z-coordinate of the point

  52.         point(width,height, 0);//画一个点

  53.                

  54.         // quad(x1, y1, x2, y2, x3, y3, x4, y4)
  55.                
  56.         // x1         float: x-coordinate of the first corner
  57.         // y1         float: y-coordinate of the first corner
  58.         // x2         float: x-coordinate of the second corner
  59.         // y2         float: y-coordinate of the second corner
  60.         // x3         float: x-coordinate of the third corner
  61.         // y3         float: y-coordinate of the third corner
  62.         // x4         float: x-coordinate of the fourth corner
  63.         // y4         float: y-coordinate of the fourth corner
  64.         quad(38, 31, 86, 20, 69, 63, 30, 76);//画一个四边形
  65.                         

  66.         // rect(a, b, c, d)
  67.         // rect(a, b, c, d, r)
  68.         // rect(a, b, c, d, tl, tr, br, bl)
  69.                
  70.         // a         float: x-coordinate of the rectangle by default
  71.         // b         float: y-coordinate of the rectangle by default
  72.         // c         float: width of the rectangle by default
  73.         // d         float: height of the rectangle by default
  74.         // r         float: radii for all four corners
  75.         // tl         float: radius for top-left corner
  76.         // tr         float: radius for top-right corner
  77.         // br         float: radius for bottom-right corner
  78.         // bl         float: radius for bottom-left corner
  79.         rect(30, 20, 55, 55);//画一个矩形
  80.                

  81.         // rectMode(mode)
  82.         // mode         int: either CORNER, CORNERS, CENTER, or RADIUS
  83.         rectMode(CENTER);

  84.         rect(30, 120, 55, 55, 7);//画一个圆角矩形
  85.         

  86.         // triangle(x1, y1, x2, y2, x3, y3)
  87.                
  88.         // x1         float: x-coordinate of the first point
  89.         // y1         float: y-coordinate of the first point
  90.         // x2         float: x-coordinate of the second point
  91.         // y2         float: y-coordinate of the second point
  92.         // x3         float: x-coordinate of the third point
  93.         // y3         float: y-coordinate of the third point
  94.         triangle(30, 75, 58, 20, 86, 75);//画一个三角
  95. }

  96. void draw()
  97. {
  98.         fill((int)random(0, 255), (int)random(0, 255), (int)random(0, 255), (int)random(0, 255));
  99.         switch (key)
  100.         {
  101.                 case 'a' :
  102.                 {
  103.                         arc(mouseX, mouseY, (int)random(0,255), (int)random(0, 255), (int)random(0, 180),(int)random(180,360));
  104.                         break;
  105.                 }
  106.                 case 'e' :
  107.                 {
  108.                         ellipse(mouseX, mouseY, (int)random(0, 500),(int)random(0, 500));
  109.                         break ;
  110.                 }  
  111.                 case 'l' :
  112.                 {
  113.                         stroke((int)random(0,255), (int)random(0,255), (int)random(0,255), (int)random(0,255));
  114.                         line((int)random(0, 500), (int)random(0, 500), mouseX, mouseY);
  115.                         break;
  116.                 }
  117.                 case 'p':
  118.                 {
  119.                         stroke((int)random(0,255), (int)random(0,255), (int)random(0,255), (int)random(0,255));
  120.                         point(mouseX, mouseY, 0);
  121.                         break ;
  122.                 }
  123.                 case 'r':
  124.                 {
  125.                         rect(mouseX, mouseY, (int)random(0, 500), (int)random(0, 500));
  126.                         break ;
  127.                 }
  128.                 case 't' :
  129.                 {
  130.                         triangle((int)random(0, 500), (int)random(0, 500), (int)random(0, 500), (int)random(0, 500), mouseX, mouseY);
  131.                         break;        
  132.                 }
  133.                 case 'q' :
  134.                 {
  135.                         quad((int)random(0, 500), (int)random(0, 500), (int)random(0, 500), (int)random(0, 500), (int)random(0, 500), (int)random(0, 500), (int)random(0, 500), (int)random(0, 500));
  136.                         break;        
  137.                                 
  138.                 }
  139.                 case 'c':
  140.                 {
  141.                         clear();
  142.                         break ;
  143.                 }        
  144.                
  145.                 default :
  146.                         
  147.                 break;        
  148.                
  149.                         
  150.         }        
  151. }
复制代码

效果怎么样呢。


好了同学们,多按按键盘,多移动鼠标,创造出属于自己的png吧。
这节课就上到这里。我们下课。
{:soso__13766225770624999893_7:}

本帖子中包含更多资源

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

x
回复

使用道具 举报

发表于 2013-5-13 23:31:45 | 显示全部楼层
lz辛苦啊,刚开始玩这个,正好跟着学一下哩
回复 支持 反对

使用道具 举报

发表于 2014-10-31 09:00:54 | 显示全部楼层
//同学们我们上课,今天我们继续学习Processing的输出功能
//今天我们主要讲述Processing的2D绘画基础
//下面我会用一个小程序来详细说明每一个画图函数的用法。

void setup()
{
  size(512, 512);
  //既然讲到2D绘画,那么颜色当然也得说一说
  //颜色函数基本函数
  colorMode(RGB);//一下是colorMode的使用方法        

  // colorMode(mode)    mode         int: Either RGB or HSB, corresponding to Red/Green/Blue and Hue/Saturation/Brightness
  // colorMode(mode, max) max 参数是对颜色变量的范围        
  // colorMode(mode, max1, max2, max3) max1         
  // colorMode(mode, max1, max2, max3, maxA)

  background(0, 0, 0, 0);//背景色设置函数(R,G,B,A)
  //clear();//清除用的
  fill(255, 0, 0, 100);//填充颜色  255是完全不透明
  // noFill();//不进行填充
  noStroke();//不绘画边界
  //stroke(0, 255, 0, 0);//绘画边界,并设置边界颜色

  arc(50, 55, 50, 50, 0, HALF_PI);//花一段弧线
  ellipseMode(CENTER);//椭圆的模式 参数分别可以填RADIUS;CENTER CORNER CORNERS

  //        ellipse(a, b, c, d)
  // a         float: x-coordinate of the ellipse
  // b         float: y-coordinate of the ellipse
  // c         float: width of the ellipse by default
  // d         float: height of the ellipse by default
  ellipse(100, 100, 50, 50);//画一个椭圆的特例圆

  // 画现函数的详情
  // line(x1, y1, x2, y2)
  // line(x1, y1, z1, x2, y2, z2)

  // x1         float: x-coordinate of the first point第一个点的x坐标
  // y1         float: y-coordinate of the first point第一个点的y坐标
  // x2         float: x-coordinate of the second point第二个点的x坐标
  // y2         float: y-coordinate of the second point第二个点的y坐标
  // z1         float: z-coordinate of the first point第一个点的z轴坐标
  // z2         float: z-coordinate of the second point第二个点的z轴坐标
  line(0, 0, width, height);//画一条线



  // point(x, y)
  // point(x, y, z)

  // x         float: x-coordinate of the point
  // y         float: y-coordinate of the point
  // z         float: z-coordinate of the point

    point(width, height, 0);//画一个点



  // quad(x1, y1, x2, y2, x3, y3, x4, y4)

  // x1         float: x-coordinate of the first corner
  // y1         float: y-coordinate of the first corner
  // x2         float: x-coordinate of the second corner
  // y2         float: y-coordinate of the second corner
  // x3         float: x-coordinate of the third corner
  // y3         float: y-coordinate of the third corner
  // x4         float: x-coordinate of the fourth corner
  // y4         float: y-coordinate of the fourth corner
  quad(38, 31, 86, 20, 69, 63, 30, 76);//画一个四边形


  // rect(a, b, c, d)
  // rect(a, b, c, d, r)
  // rect(a, b, c, d, tl, tr, br, bl)

  // a         float: x-coordinate of the rectangle by default
  // b         float: y-coordinate of the rectangle by default
  // c         float: width of the rectangle by default
  // d         float: height of the rectangle by default
  // r         float: radii for all four corners
  // tl         float: radius for top-left corner
  // tr         float: radius for top-right corner
  // br         float: radius for bottom-right corner
  // bl         float: radius for bottom-left corner
  rect(30, 20, 55, 55);//画一个矩形


  // rectMode(mode)
  // mode         int: either CORNER, CORNERS, CENTER, or RADIUS
  rectMode(CENTER);

  rect(30, 120, 55, 55, 7);//画一个圆角矩形


  // triangle(x1, y1, x2, y2, x3, y3)

  // x1         float: x-coordinate of the first point
  // y1         float: y-coordinate of the first point
  // x2         float: x-coordinate of the second point
  // y2         float: y-coordinate of the second point
  // x3         float: x-coordinate of the third point
  // y3         float: y-coordinate of the third point
  triangle(30, 75, 58, 20, 86, 75);//画一个三角
}

void draw()
{
  fill((int)random(0, 255), (int)random(0, 255), (int)random(0, 255), (int)random(0, 255));
  switch (key)
  {
  case 'a' :
    {
      arc(mouseX, mouseY, (int)random(0, 255), (int)random(0, 255), (int)random(0, 180), (int)random(180, 360));
      break;
    }
  case 'e' :
    {
      ellipse(mouseX, mouseY, (int)random(0, 500), (int)random(0, 500));
      break ;
    }  
  case 'l' :
    {
      stroke((int)random(0, 255), (int)random(0, 255), (int)random(0, 255), (int)random(0, 255));
      line((int)random(0, 500), (int)random(0, 500), mouseX, mouseY);
      break;
    }
  case 'p':
    {
      stroke((int)random(0, 255), (int)random(0, 255), (int)random(0, 255), (int)random(0, 255));
      point(mouseX, mouseY, 0);
      break ;
    }
  case 'r':
    {
      rect(mouseX, mouseY, (int)random(0, 500), (int)random(0, 500));
      break ;
    }
  case 't' :
    {
      triangle((int)random(0, 500), (int)random(0, 500), (int)random(0, 500), (int)random(0, 500), mouseX, mouseY);
      break;
    }
  case 'q' :
    {
      quad((int)random(0, 500), (int)random(0, 500), (int)random(0, 500), (int)random(0, 500), (int)random(0, 500), (int)random(0, 500), (int)random(0, 500), (int)random(0, 500));
      break;
    }
  case 'c':
    {
      clear();
      break ;
    }        

  default :

    break;
  }
}
交作业了
回复 支持 反对

使用道具 举报

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

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

Archiver|联系我们|极客工坊

GMT+8, 2024-4-19 18:41 , Processed in 0.039247 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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