|
本帖最后由 yangfanconan 于 2013-5-13 19:27 编辑
同学们我们上课,今天我们继续学习Processing的输出功能
//今天我们主要讲述Processing的2D绘画基础
//下面我会用一个小程序来详细说明每一个画图函数的用法。
- //同学们我们上课,今天我们继续学习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);//填充颜色
- // 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;
-
-
- }
- }
复制代码
效果怎么样呢。
好了同学们,多按按键盘,多移动鼠标,创造出属于自己的png吧。
这节课就上到这里。我们下课。{:soso__13766225770624999893_7:} |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|