找回密码
 注册
搜索
查看: 14922|回复: 7

[心得体会] Compare coding with function or not.

[复制链接]
发表于 2010-10-15 18:00:24 | 显示全部楼层 |阅读模式
本帖最后由 weiwei 于 2010-10-15 18:14 编辑 Because it takes 6 lines to draw each shape, we now have 12 lines. Drawing our desired pattern that uses 6 shapes will require 36 lines of code. Imagine if we wanted to draw 30 eyes—the code inside draw() would bloat to 180 lines. 在此提及到如果每個圖形都單圖控制,會造成程式的冗長。並且不好修改。 ProcessingHandbook1842.jpg Because the shapes are identical, a function can be written for drawing them. The function introduced in the next example has two inputs that set the x-coordinate and y-coordinate. The lines of code inside the function render the elements for one shape. function 的功能是拿來控制主體的框架,細部參數修改的部份就從draw()裡面自訂的function呼叫。 ProcessingHandbook1863.jpg Now that the function is working, it can be used each time we want to draw that shape. If we want to use the shape in another program, we can copy and paste the function. We no longer need to think about how the shape is being drawn or what each line of code inside the function does. We only need to remember how to control its position with the two parameters. 資料來源 processing handbook p-193

评分

参与人数 1强度 +3 照度 +30 收起 理由
skywoolf + 3 + 30 感谢分享

查看全部评分

 楼主| 发表于 2010-10-15 18:12:55 | 显示全部楼层
Multiple functions can have the same name, as long as they have different parameters.Creating different functions with the same name is called function overloading, and it’s what allows Processing to have more than one version of functions like fill(),image(), and text(), each with different parameters. A program can also have two functions with the same number of parameters, but only if the data type for one of the parameters is different. 需要注意的是,function可以同樣命名處理不同的功能,但裡面的參數必須不一樣。 ProcessingHandbook193.jpg 重複命名的特性就像processing 內建好的fill(),image(),text().一樣。這種功能稱做 Function overloading
回复

使用道具 举报

发表于 2010-10-15 19:12:30 | 显示全部楼层
可以处理value,需要定义function的返回值的种类,最后结束时return需要返回的值 void就是没有返回值
回复

使用道具 举报

 楼主| 发表于 2010-10-15 19:31:57 | 显示全部楼层
嗯嗯 多謝claudemit 的補充!! 如果要value 的就必須加上return 還有資料型態data type
回复

使用道具 举报

发表于 2010-10-16 00:36:05 | 显示全部楼层
楼主能给个邮箱么(注册用户,没法发站内信的= =),目前和我的设计老师在做arduino相关,可以交流下么~~多谢了~~
回复

使用道具 举报

发表于 2010-10-16 11:48:39 | 显示全部楼层
很精彩, 努力学习,看懂理解,
回复

使用道具 举报

 楼主| 发表于 2010-10-16 19:02:51 | 显示全部楼层
5# wyj900817 我已經發郵箱 給你了,你去站內收短消息巴。
回复

使用道具 举报

发表于 2010-12-24 15:43:20 | 显示全部楼层
nice thanks
回复

使用道具 举报

NCFZ微信公众号

手机版|小黑屋|NCF参数化建筑论坛 ( 浙ICP备2020044100号-2 ) 辽公网安备21021102000973号

GMT+8, 2026-11-23 20:10 , Processed in 0.050679 second(s), 25 queries , Gzip On.

Powered by Discuz! X5.0 Licensed

© 2001-2026 Discuz! Team.

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