sinewave.pde

来自「This is processing for java examples.」· PDE 代码 · 共 56 行

PDE
56
字号
/** * Sine Wave * by Daniel Shiffman.   *  * Render a simple sine wave.  */ int xspacing = 8;   // How far apart should each horizontal location be spacedint w;              // Width of entire wavefloat theta = 0.0;  // Start angle at 0float amplitude = 75.0;  // Height of wavefloat period = 500.0;  // How many pixels before the wave repeatsfloat dx;  // Value for incrementing X, a function of period and xspacingfloat[] yvalues;  // Using an array to store height values for the wavevoid setup() {  size(200,200);  frameRate(30);  colorMode(RGB,255,255,255,100);  smooth();  w = width+16;  dx = (TWO_PI / period) * xspacing;  yvalues = new float[w/xspacing];}void draw() {  background(0);  calcWave();  renderWave();}void calcWave() {  // Increment theta (try different values for 'angular velocity' here  theta += 0.02;  // For every x value, calculate a y value with sine function  float x = theta;  for (int i = 0; i < yvalues.length; i++) {    yvalues[i] = sin(x)*amplitude;    x+=dx;  }}void renderWave() {  // A simple way to draw the wave with an ellipse at each location  for (int x = 0; x < yvalues.length; x++) {    noStroke();    fill(255,50);    ellipseMode(CENTER);    ellipse(x*xspacing,width/2+yvalues[x],16,16);  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?