首页 > 教程 > 献给Processing爱好者的教程【6】—基础知识【卡卡】
2017
10-22

献给Processing爱好者的教程【6】—基础知识【卡卡】

献给Processing爱好者的教程【6】—基础知识【卡卡】 - 第1张  | Processing编程艺术

线

献给Processing爱好者的教程【6】—基础知识【卡卡】 - 第2张  | Processing编程艺术

 

void setup() {
  size(640, 360); 
  stroke(255);
  noFill();
   background(0);
  line(10, 80, 30, 40);  // Left line   
  line(20, 80, 40, 40); 
  line(30, 80, 50, 40);  // Middle line   
  line(40, 80, 60, 40); 
  line(50, 80, 70, 40);  // Right line
  saveFrame();
}

void draw() {
 
}

后面我们会学到设置变量,这个会很方便操作,将相同的用变量表示,然后带入

void setup() {
  size(640, 360); 
  stroke(255);
  background(0);
  int x = 5;   // Set the horizontal position  
  int y = 60;  // Set the vertical position 
  line(x, y, x+20, y-40);    // Line from [5,60] to [25,20]  
  line(x+10, y, x+30, y-40); // Line from [15,60] to [35,20] 
  line(x+20, y, x+40, y-40); // Line from [25,60] to [45,20] 
  line(x+30, y, x+50, y-40); // Line from [35,60] to [55,20]
  line(x+40, y, x+60, y-40); // Line from [45,60] to [65,20]

  saveFrame("line-#.png");
}

void draw() {
}

接下来,我们做一个简单的例子,我们绘制3条线段,线会一点一点像右移动,如果移动到最右端,线就重新从最左端开始继续向右移动

献给Processing爱好者的教程【6】—基础知识【卡卡】 - 第3张  | Processing编程艺术

int x = 0;   // Set the horizontal position  
int y = 55;  // Set the vertical position


void setup() { 
  size(100, 100);  // Set the window to 100 x 100 pixels
}
void draw() {  
  background(204);  
  line(x, y, x+20, y-40);     // Left line    
  line(x+10, y, x+30, y-40);  // Middle line   
  line(x+20, y, x+40, y-40);  // Right line   
  x = x + 1;      // Add 1 to x   
  if (x > 100) {  // If x is greater than 100,  
    x = -40;      // assign -40 to x
  }
}

 

接下来我们来看下线段随鼠标移动的案例

献给Processing爱好者的教程【6】—基础知识【卡卡】 - 第4张  | Processing编程艺术

void setup(){
       size(100, 100);   //插入你的初始化程序
//setup_();
}
 
void draw(){
  background(204);    // Assign the horizontal value of the cursor to x    
  float x = mouseX;      // Assign the vertical value of the cursor to y   
  float y = mouseY;    
 line(x, y, x+20, y-40);  
 line(x+10, y, x+30, y-40);  
 line(x+20, y, x+40, y-40); 

         //插入你的draw代码
//draw_();
}

 代码要素

//注释

/*   */多行注释

ctrl+/  批量添加注释符

;语句终结符,每一句程序之后必须要有

processing中大小写敏感

size();不能写成Size();

background();不要写成Background();

ctrl+T 代码自动快速对齐

print()和println(),控制台输出,方便我们理解

Tweak模式简介

函数用法查找简介

显示和输入中文注释符介绍

 



最后编辑:
作者:卡萨布兰卡
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。