一. Processing介绍

Processing 是一门开源编程语言和与之配套的集成开发环境(IDE)的名称。Processing 在电子艺术和视觉设计社区被用来教授编程基础,并运用于大量的新媒体和互动艺术作品中。

Processing 最开始的时候只是一门编程语言,因为发展势头好,在2012年的时候成立了Processing 基金会,开始横向拓展其他项目,比如p5.js, Processing的 R 模式等等。

Processing 可以用三个标签来总结:编程,视觉,易学。

简单来说,就是通过写代码来生成图案,用几行简单的代码就可以写出炫酷的视觉效果。

可以免费下载使用,官网:https://processing.org/。单击 Download Processing 并选择您的操作系统,下载安装即可。

Processing 在 2001 年诞生于麻省理工学院(MIT)的媒体实验室,主创者为 Ben Fry 和 Casey Reas,项目发起的初衷,本是为了满足他们自身的教学和学习需要。后来,当Casey在意大利的伊夫雷亚交互设计学院(Interaction Design Institute Ivrea)进行教学的时候,基于Processing,衍生出了Wiring和Arduino项目。随着时间的推移,又诞生了多个语言的版本,比如基于JavaScript的Processing.js,还有基于Python、Ruby、ActionScript以及Scala等版本。

Processing项目是Java开发的,所以Processing天生就具有跨平台的特点,同时支持Linux、Windows以及Mac OSX三大平台,并且支持将图像导出成各种格式。

Processing 是一种具有革命前瞻性的新兴计算机语言,为图像处理提供开源编程语言和环境,动画和互动。这是使用的学生,艺术家,设计师,研究人员和爱好者学习,原型及生产。这是建立基础教育计算机编程在视觉方面,并作为软件写生簿和专业的生产工具。Processing 开发的艺术家和设计师以替代专有软件工具在同一域中。

二. 基于Python案例

2.1 绘制正方形

ellipse(50, 50, 80, 80)

执行结果如下:

2.2 背景和颜色

background 功能被用来设置显示窗口的颜色。此函数可以使用各种不同的参数(来定义一个灰度值或 Red-Green-Blue [RGB] 颜色)。

size(100, 100)
background( 0, 128, 0 )

执行结果如下图:

2.3 鼠标控制箭头

#arrow.pydedef setup():size(600,600)cols = 20 #number of columns
#scale factors:
xscl = 600/cols
yscl = 600/cols
sz = 6def draw():global cols, xscl, ysclbackground(255)for x in range(cols):for y in range(cols):arrow(10+x*xscl,10+y*yscl,sz)def arrow(x,y,sz):pushMatrix()translate(x,y)angle = atan2(mouseY-y,mouseX-x)rotate(angle)beginShape()vertex(0,-sz/2.0)vertex(2*sz,-sz/2.0)vertex(2*sz,-3*sz/2.0)vertex(4*sz,0)vertex(2*sz,3*sz/2.0)vertex(2*sz,sz/2.0)vertex(0,sz/2.0)endShape(CLOSE)popMatrix()

2.4 正方向四周扩散

GRID_W = 41
GRID_H = 41generation = 0class Cell:def __init__(self,r,c,on=0):self.c = cself.r = rself.on = ondef display(self):if self.on == 1:fill(0) #blackelse:fill(255) #whiterect(SZ*self.r, SZ*self.c, SZ, SZ)def checkNeighbors(self):neighbs = 0  #check the neighborsif self.on == 1: return 1for dr,dc in [[-1,0], [1,0], [0,-1],[0,1]]:try:if cellList[self.r + dr][self.c + dc].on == 1:neighbs += 1except IndexError:continueif neighbs in [1,4]:return 1else:return 0def setup():global SZ, cellListnoStroke()size(600,600)SZ = width // GRID_W + 1cellList = createCellList()def draw():global generation,cellListframeRate(10)cellList = update(cellList)for row in cellList:for cell in row:cell.display()generation += 1if generation == 30:generation = 1cellList = createCellList()loop()def update(cellList):newList = []for r,row in enumerate(cellList):newList.append([])for c,cell in enumerate(row):newList[r].append(Cell(r,c,cell.checkNeighbors()))return newList[::]def createCellList():'''Creates a big list of off cells withone on Cell in the center '''newList=[]#empty list for cells #populate the initial cell listfor j in range(GRID_H): newList.append([]) #add empty row for i in range(GRID_W):newList [j].append(Cell(i,j,0)) #add off Cells or zeroes #center cell is set to onnewList [GRID_H//2][GRID_W//2].on = 1 return newList

执行结果如下:

2.5 红色圆圈


def setup():size(600,600)def draw():background(255)translate(width/2,height/2)points = []num = 24for i in range(num):x = 250*cos(radians(360.0*i/num))y = 250*sin(radians(360.0*i/num))#put point in a listpoints.append([x,y])for p in points: #from every pointfor other in points: #to every "other" pointstroke(255,0,0) #redline(p[0],p[1],other[0],other[1])

执行结果如下图:

2.6 绘制正弦曲线

#CircleSineWave.pyde
r1 = 100 #radius of big circle
r2 = 10  #radius of small circle
t = 0 #time variable
circleList = []def setup():size(600,600)def draw():global t, circleListbackground(200)#move to left-center of screentranslate(width/4,height/2)noFill() #don't color in the circlestroke(0) #black outlineellipse(0,0,2*r1,2*r1)#circling ellipse:fill(255,0,0) #redy = r1*sin(t)x = r1*cos(t)#add point to list:circleList.insert(0,y)ellipse(x,y,r2,r2)stroke(0,255,0) #green for the lineline(x,y,200,y)fill(0,255,0) #green for the ellipseellipse(200,y,10,10)if len(circleList)>300:circleList.remove(circleList[-1])#loop over circleList to leave a trail:for i,c in enumerate(circleList):#small circle for trail:ellipse(200+i,c,5,5)t += 0.05

执行结果如下图:

2.7 生成各种颜色

def setup():size(600,600)#rectMode(CENTER)colorMode(HSB)def draw():#set background blackbackground(0)#translate(5,5)for x in range(20):for y in range(20):d = dist(30*x,30*y,mouseX,mouseY)fill(0.5*d,360,360)rect(30*x,30*y,25,25)'''def draw():#set background whitebackground(255)translate(20,20)textSize(12)for i in range(10):fill(20*i,255,255)rect(31*i,0,25,25)fill(0)text(str(20*i),31*i+5,50)'''

执行结果如下:

2.8 绘制滚动的圆

t = 0.0 #time
dt = 0.01 #change in time
r = 50 #radius of circle
ground = 250 # y-val of line circle rolls on
x,Y = 0,ground-r #initial location of circle
v = 2.0 #horizontal velocity factor of circle
points = [] #list to store pointsdef setup():size(942,300)def draw():global t,dt,r,ground,x,y,pointsbackground(255) #whitestrokeWeight(2)stroke(150)line(0,ground,width,ground) #line for the "ground"noFill()ellipse(x,Y,2*r,2*r)#calculate position of drawing "dot"dot = PVector(x+r*cos(v*TWO_PI*t+PI/2),Y+r*sin(TWO_PI*v*t+PI/2))#save that position to the points list, to be drawn laterpoints.append(dot)line(dot.x,dot.y,x,Y) #radial segmentfill(255,0,0) #red dotellipse(dot.x,dot.y,10,10)#loop through the points list to draw the curvefor i,pt in enumerate(points):if i < len(points) - 2:stroke(255,0,0)line(pt.x,pt.y,points[i+1].x,points[i+1].y)x += TWO_PI*r*dt*v #update x-value by velocityif x > width: #when the wheel gets all the way to the right#noLoop() # uncomment this out to only run it oncex = 0.0 # reset position all the way to the leftpoints = [] # erase the trail#println(x) #just for testing#println(dot.x)t += dt #increment the time variable

执行结果如下

2.9 黑色背景白点圆

def setup():size(600,600)def draw():background(0)translate(width/2, height/2)for i in range(12):ellipse(200,20,15,15)rotate(radians(360/12))

执行结果如下:

2. 10 无限圆圈放大

'''Web/Vortex of Circles
June 14, 2018'''factor = 1.3def setup():size(600,600)noFill()stroke(255) #white linesdef draw():global factorbackground(0)#Uncomment to display the value of factor'''fill(255,0,0)textSize(18)text(factor,20,20)'''factor -= 0.005#move the mouse to vary the factor#factor = map(mouseX,0,255,1,1.5)translate(width/2,height/2)vortex(500,100)#uncomment these lines to save screenshots:'''saveFrame('####.png')'''if factor <= 1.07:factor = 1.3 #noLoop() #will stop the loopdef vortex(r,level):num = 30 #number of circles in one ringif level > 0:r2 = r/4.0for i in range(num):pushMatrix()rotate(radians(360*i/float(num)))translate(r,0)st = map(r2,0,100,0,3) #make strokeWeight varystrokeWeight(st)noFill()ellipse(0,0,r2,r2)popMatrix()rotate(TWO_PI/(2*num))vortex(r/factor,level-1)#1.065,level-1)

Processing介绍及几个python模式下的案例相关推荐

  1. xrandr 只有一个显示屏_给大家介绍一种命令行模式下的多屏分屏工具xrandr

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 archlinux WIKI上的介绍是这样的: "xrandr" 是一款官方的 RandR Wikipedia:X Window Sy ...

  2. 在DataWorks标准模式下统计个人账号使用资源情况

    背景 在使用MaxCompute的时候通常情况下,用户会通过Information Schema的task_history视图表来分析具体某个账号执行的SQL任务情况,来做到SQL成本分摊或SQL的时 ...

  3. Oracle设置和修改system和scott的口令,并且如何连接到system和scott模式下

    1.在Oracle数据库中,有个示例模式scott和系统模式system. 2.在安装数据库时只是设置了system的口令,即密码,如果忘记的话可以使用如下办法,首先打开sqlplus工具或者cmd命 ...

  4. 服务器ahci模式安装系统,ahci模式下安装win7系统的方法

    如今市面上很多主板都是支持AHCI模式,那么有些用户就想要在ahci模式下,这样就可以有效发挥SATA硬盘的性能,尤其是固态硬盘,那么ahci模式下如何安装win7系统呢?接下来给大家讲解一下具体的操 ...

  5. 痞子衡嵌入式:i.MXRT连接特殊Octal Flash时(OPI DTR模式下反转字节序)下载与启动注意事项(以MX25UM51245为例)...

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是OPI DTR模式下反转字节序的Octal Flash在i.MXRT下载与启动注意事项. 在恩智浦官方参考设计板 MIMXRT595-E ...

  6. 第17周翻译:SQL Server中的事务日志管理的阶梯:第5级:在完全恢复模式下管理日志...

    来源:http://www.sqlservercentral.com/articles/Stairway+Series/73785/ 作者:Tony Davis, 2012/01/27 翻译:刘琼滨. ...

  7. vim介绍,vim颜色显示,vim一般模式下移动光标,vim一般模式下的复制、剪切和粘贴...

    2019独角兽企业重金招聘Python工程师标准>>> vim介绍 vim是vi的升级版,相较于vi,会显示颜色. 如果系统没有vim工具,需要安装:# yum install -y ...

  8. python怎么输入两行_python交互模式下输入换行/输入多行命令的方法

    先给大家介绍下python交互模式下输入换行/输入多行命令的方法 换行方法 \ 如: >>> print 'aaa'; \ ... print 'bbb'; \ ... print ...

  9. Python多线程下实现单例模式,以及limit实例模式

    多线程环境下实现单例模式 下面介绍了两种Python实现单例模式的方法 1.重写__new__方法实现多线程情况下的单例模式 用new方法实现单例模式 import time, threadingcl ...

  10. 5.1 vim介绍 5.2-5.3 vim颜色显示和移动光标、vim一般模式下移动光标 5.4 vim 一般模式下复制剪切粘贴...

    2019独角兽企业重金招聘Python工程师标准>>> 5.1 vim介绍 vim 是 vi 的升级版 vim 是带有颜色显示的 mini安装的系统,一般都不带有vim yum in ...

最新文章

  1. R语言dplyr包combine()函数实现数据拼接(concatenate)实战
  2. 394. Decode String
  3. C语言链表存储数据并排序,c语言求助:怎么根据链表中的某个数据对链表进行排序?...
  4. java图形界面关键字_怎样用Java编写一个图形界面,要求可以利用关键词查询txt中的内容...
  5. 设计师中国风作品必备汉字毛笔字偏旁部首大集合
  6. Abp 代码生成器使用说明
  7. 被单位开除后,以前的工龄还算吗?
  8. Youki的C++命名规则
  9. KindleDrip:从邮件地址到信用卡盗刷的严重漏洞,值$1.8万奖金
  10. 如何安装Exchange2010上安装更新汇总(Update Rollup)
  11. 把语言环境变量改为英文
  12. Windows:文件系统FAT32、NTFS和exFAT
  13. cefsharp 添加html,winform+cefSharp实现窗体加载浏览器
  14. ASP常用服务器获取各类信息汇总
  15. Android 视频直播的流程总览
  16. 假如你有超能力,会复活哪部经典美剧?
  17. 计算器算贝塞尔公式_买车贷款怎么算利息?
  18. 支持javascript的ppt软件_Reveal.js是在浏览器中播放创建在线PPT幻灯片的开源库包...
  19. linux smit工具,Aix操作系统SMIT工具
  20. FZU Problem 2238 Daxia Wzc's problem(Lucas定理求组合数)

热门文章

  1. javascript英语单词音节拆分_英语单词音节的划分法
  2. 小白最需要了解的计算机基础知识
  3. 零基础学FPGA(四):IP是什么东西(什么是软核,硬核)
  4. Nature:细菌增长和扩张的平衡机制
  5. 题8 数据库系统的核心是什么?
  6. OSG智能指针---Referenced类
  7. Qt5.3.1环境变量配置-----gyy
  8. 戴口罩写代码,程序员干脆穿越到了古代
  9. 用一报还一报(TIT FOR TAT)策略的胜利指导我们的生活和人际交往
  10. layui模态框不居中的几种解决方法