第一范文网 - 专业文章范例文档资料分享平台

详细的processing学习笔记

来源:用户分享 时间:2025/5/24 23:52:42 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

想要关闭淡出效果,我们要用到keyPressed()这个方法,它会在每次键盘有按键动作时被调用。如果用户按了**f** 键,系统就切换一次fade的真假值。

void keyPressed(){

if (key == 'f') { fade = !fade; }

}

运行程序后你就能看到之前的线条都慢慢淡出背景,试一下f键关闭或启用淡出效果。 源码:

折叠Java 代码复制内容到剪贴板

1. float radius = 40; 2. float x,y; 3. float prevX,prevY; 4. Boolean fade = true; 5. Boolean saveOne = false; 6. void setup(){ 7. size(450,400); 8. background(0); 9. stroke(255); 10. x = width/2; 11. y = height/2; 12. prevX = x; 13. prevY = y; 14. stroke(255); 15. strokeWeight(2); 16. point(x,y); 17. 18. }

19. void draw(){ 20.

21. if(fade){ 22. noStroke(); 23. fill(0,4);

24. // fill(random(204),random(100),random(20),4); 25. rect(0,0,width,height); 26. }

27. float angle = (TWO_PI/6) * floor(random(6)); 28. x += cos(angle) * radius; 29. y += sin(angle) * radius; 30.

31. if(x<0||x>width){ 32. x= prevX; 33. y= prevY; 34. } 35.

36. if(y<0||y>height){ 37. x = prevX; 38. y = prevY; 39. }

40. // stroke(255,64); 41. stroke(255,0,0,100); 42. strokeWeight(1); 43. line(x,y,prevX,prevY); 44. strokeWeight(3); 45. point(x,y); 46. prevX = x; 47. prevY = y; 48. if(saveOne){

49. saveFrame(\+ second() + \ 50. saveOne = false; 51. }

52. delay(50); 53. }

54. void keyPressed(){ 55. if(key=='f'){

56. fade =!fade;

57. } 58.

59. if(key=='s'){ 60. saveOne = true; 61. } 62. }

效果显示

floor(x)函数:计算最接近的小于或等于X的整数值 Namefloor() Examples

float x = 2.88;

int a = floor(x); // Sets 'a' to 2

DescriptionCalculates the closest int value that is less than or equal to the value of the parameter. Syntax floor(n)

Parameters n float: number to round down Returns int

ceil(x)函数:计算最接近的大于或等于X的整数值 Name ceil() Examples

float x = 8.22;

int a = floor(x); // Sets 'a' to 9

DescriptionCalculates the closest int value that is greater than or equal to the value of the parameter. For example, ceil(9.03)returns the value 10. Syntax floor(n)

搜索更多关于: 详细的processing学习笔记 的文档
详细的processing学习笔记.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c5sfab3kjb87b3ef97wu606i7k4ff8500zft_4.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top