Processing介绍PPT学习课件_第1页
Processing介绍PPT学习课件_第2页
Processing介绍PPT学习课件_第3页
Processing介绍PPT学习课件_第4页
Processing介绍PPT学习课件_第5页
已阅读5页,还剩46页未读 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Processing介绍,一种快捷的图形表达工具,介绍,Processing是由BenFry和CaseyReas开发的开源软件.它由Java发展而来,为艺术家和设计师所设计.简单。它使得我们可以直接专注于图形和交互的程序,而不需要考虑很多麻烦的任务,比如建立类的路径和编译参数,或者建立窗口和图形环境这样辅助性的图形环境。友好。有非常活跃的社区和用户,非常容易得到支持。,使用环境,坐标系统左上角为原点。,三种模式,基础型(Basic)画静态图像。活动型(Continuous)setup()初始设置。draw()不断的运行,直到停止。Java型。最复杂,最灵活,写java程序。,注释,/*或者/*结束*/./*多行注释可以说明程序结构,使得更为清晰可读,调试(debugging),print()println()此两个函数在调试窗口输出参数,变量variables,变量是程序的核心通过指定名称来读写内存中的数据变量包括name和type.接收外部输入创造通用解决方案输入的细小变化引起输出巨大改变,命名,name/identifier名字/识别符有限长度的字母或数字不能java的保留词以字母或_开头Validnames有效foo,foo_bar,f00,_foo,xpositionInvalidnames无效35foo,$bar,245,(,true,int,驼峰命名camelCasing小写开头易读,数据类型type,变量存储的类别。取值的范围。int:非负自然数.InProcessing,范围-2147483648,2147483647操作符operators:+,-,*,DIV,MOD浮点数floatInProcessing,范围-3.40282347E+38,3.40282347E+38操作符:+,-,*,/,squareroot,.boolean:两个值:trueandfalse操作符:AND,OR,NOT,.,usingvariables使用变量,变量首先要声明(declared)表示让程序为它保留一些内存空间,好的编程习惯初始化变量后立即赋值赋值运算符=,变量只能初始化一次但值可以多次赋予,变量可以读出,variablesformodularity变量的模块性,画一个点,另一种方式,每隔二十个像素画一个点丑陋,hardcoding,漂亮,内建变量built-invariables,只读,不能赋值mouseX/mouseY:当前鼠标值width/height:当前窗口的长宽frameCount:当前帧的数量,从程序开始.,/setthesizeofthedisplaysize(200,200);/setthebackgroundcolortowhitebackground(255);/drawthreepointsalongthehorizontalaxisintspacing=20;intxPos=width/2;intyPos=height/2;point(xPos-spacing,yPos);point(xPos,yPos);point(xPos+spacing,yPos);,functions函数,函数是特定名称的一系列代码,在一个更大的程序里面执行某种任务在面向对象编程中,也被称为方法method黑箱模型,函数的作用,定义一次,多次使用。Theyallowaprogramtoemployasequenceofcodemultipletimesfromasingledefinition.把大段程序重构为有意义的子单元。Theyprovideameansofdeconstructingaprogramintomeaningfulsub-units.代码易读,易维护和易再用Theyhelpinwritingcodethatisreadable,maintainableandreusable,使用函数usingfunctions,TodeclareordefineafunctioninProcessing,youusethefollowingformat:,例子,call调用,调用变量类型相同数量相同,调用的例子,variablescope变量范围,global全局变量local局部变量应该把大段代码编程小段的函数,从而易于理解全局变量尽量少用,/globalvariables,accessiblethroughouttheprogramintcircleSize=25;voidsetup()size(400,400);smooth();background(255);stroke(0);/xPosandyPosarelocalvariablesintxPos=200;intyPos=100;circle(xPos,yPos);,fill(255,0,0);ellipse(width/2,height/2,circleSize,circleSize);voiddraw()/mouseXandmouseYareglobalbuilt-invariablescircle(mouseX,mouseY);/xandyarelocalvariablespassedasparametersvoidcircle(intx,inty)/fillColorisalocalvariableintfillColor=255;fill(fillColor);ellipse(x,y,circleSize,circleSize);,built-infunctions内在函数,很多内在函数,参考Reference,shapes,/drawalinefrom(200,10)to(210,380)line(200,10,210,380);/usefill()tospecifywhatcolorshouldbeinsidetheshapefill(100,100,200);/blue/drawarectanglewiththeupperleft-handcornerat(25,50)/anditswidthandheightbothequalto100rect(25,50,100,100);/usefill()tospecifywhatcolorshouldbeinsidetheshapefill(255,100,0);/orange/usestroke()tospecifythecoloroftheoutlinestroke(100,100,255);/blue,/drawanellipsecenteredat(280,150),with/itswidthequalto100,anditsheightequalto75ellipse(280,150,100,75);/usestrokeWeight()tospecifythewidthoftheoutlinestrokeWeight(3);/drawatrianglewithpointsat(30,275),(58,225),and(186,350)triangle(30,275,58,225,186,350);/usenoStroke()tonotdrawanoutlinenoStroke();/usefill()tospecifywhatcolorshouldbeinsidetheshapefill(185,17,39);/red/drawaquadwithpointsat(240,240),(390,320),/(360,380),and(220,350)quad(240,240,390,320,360,380,220,350);,customshapes自定义形状,vertex()放在beginShape()和endShape()中间,voidsetup()size(400,400);smooth();noStroke();voiddraw()background(0);/drawastaratthecurrentmousepositionfill(216,61,4);drawStar(mouseX,mouseY,100);,voiddrawStar(intxPos,intyPos,intstarSize)beginShape();vertex(xPos,yPos-starSize/2);vertex(xPos-starSize/3,yPos+starSize/2);vertex(xPos+starSize/2,yPos-starSize/8);vertex(xPos-starSize/2,yPos-starSize/8);vertex(xPos+starSize/3,yPos+starSize/2);vertex(xPos,yPos-starSize/2);endShape();,compositeexpressions复合表达式,数字运算numericaloperators10+500变量variablesa+width-10函数functionsrandom()+myAngle()数学运算mathematicaloperators(whicharealsofunctions)log(500)+b,常用函数round()abs()ceil()floor()random()sqrt(),intminSize=50;intmaxSize=100;voidsetup()size(400,400);smooth();rectMode(CENTER);strokeWeight(2);voiddraw()drawSquares(random(width),random(height),random(minSize,maxSize);,voiddrawSquares(floatxPos,floatyPos,floatsqSize)/drawtheoutersquarefirstfill(254,255,0);stroke(255,166,0);drawSquare(xPos,yPos,sqSize);/drawtheinnersquarenextfill(252,233,8);stroke(216,61,4);drawSquare(xPos,yPos,sqSize/2);voiddrawSquare(floatxPos,floatyPos,floatsqSize)rect(xPos,yPos,sqSize,sqSize);,一些短的操作符a+=b;isequivalenttoa=a+b;a-=b;isequivalenttoa=a-b;a*=b;isequivalenttoa=a*b;a/=b;isequivalenttoa=a/b;a+;isequivalenttoa=a+1;a-;isequivalenttoa=a-1;,实际x=x+1;x+;x+=1;:adds1tothevalueofxandmakestheresultthenewvalueofxx=x+25;x+=25;:adds25tothevalueofxandmakestheresultthenewvalueofxx=x-1;x-;x-=1;:subtracts1fromthevalueofxandmakestheresultthenewvalueofx,operatorprecedence操作符的优先级,inta=10;intb=5;intc=12;intd=2;andevaluatethefollowingexpressions:a+b*c/d10+5*12/210+60/210+3040,(a+b)*c/d(10+5)*12/215*12/2180/290(a+(b*c)/d(10+(5*12)/2(10+60)/270/235,datatypeconversion数据类型转换,有时候会出错加int运算符,原来程序加入abs()跟踪鼠标速度,voidsetup()size(400,400);smooth();noStroke();voiddraw()background(0);/drawastaratthecurrentmousepositionwithsizerelativetothemousemovementfill(216,61,4);intavgMove=int(abs(pmouseX-mouseX)+abs(pmouseY-mouseY)/2);drawStar(mouseX,mouseY,avgMove*5);,voiddrawStar(intxPos,intyPos,intstarSize)beginShape();vertex(xPos,yPos-starSize/2);vertex(xPos-starSize/3,yPos+starSize/2);vertex(xPos+starSize/2,yPos-starSize/8);vertex(xPos-starSize/2,yPos-starSize/8);vertex(xPos+starSize/3,yPos+starSize/2);vertex(xPos,yPos-starSize/2);endShape();,color色彩,默认的色彩空间是RGB/255。RGB三通道0-255的值color(red,green,blue)函数color(val)函数灰度值0-255大于255,作为RGB值也可以用16进制hexadecimal,色彩模式转化,colorMode(mode)(RGBorHSB)colorMode(mode,range)指定色彩范围,transparency透明度,色彩带透明度属性,Alpha通道color(),fill(),andstroke(),butNOTbackground()./drawaredcirclefill(1.0,0,0,0.5);ellipse(125,125,100,100);/drawagreencirclefill(0,1.0,0,0.5);ellipse(150,175,100,100);/drawabluecirclefill(0,0,1.0,0.5);ellipse(175,125,100,100);,运动模糊效果motionblureffect.把background()用半透明的rect()覆盖整个画面,练习一个脸,脸必须要有眼,鼻子和嘴巴Thefacem

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论