极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 20011|回复: 0

新人求助!processing绘制函数图像

[复制链接]
发表于 2016-8-28 10:36:32 | 显示全部楼层 |阅读模式
float[] a=new float[200];  
float y=0;
float x=-15;
float b=1;
int k;
int n=100;
int i=1;
int j;
float c=random(0,255);
float d=random(0,255);
float e=random(0,255);
float f=random(50,255);

void setup(){
  size(600,600);
  smooth();
  background(0);
  for(n=100;n>=0;n--){
    a[n]=random(-2,2);
  }                      //用数组存储系数
  frameRate(62500);
}

void draw(){
  b=1;
  y=0;
  strokeWeight(3);
  translate(300,300);    //初始化
  if(i%2==1){
    for(j=i;j>=0;j-=2){
      for(k=1;k<=j;k++){
        b=b*(x+a[i-1]/(i*a[i]));
      }
      y=y+a[j]*b;
    }
  }
  else{
    for(j=i;j>=0;j-=2){
      for(k=1;k<=j;k++){
        b=b*(x+a[i-1]/(i*a[i]));
      }
      y=y+a[j]*b;
    }
  }                        //求值
  stroke(c,d,e,f);
  point(20*x,-5*y);        //绘制点
  x+=0.005;
  if(x>15){
    x=-15;
    i++;
    background(0);
    c=random(0,255);
    d=random(0,255);
    e=random(0,255);
    f=random(50,255);     //调整颜色、透明度
  }                       //归零
}
  
  

结果三次函数图像画出来是四次的。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-20 00:58 , Processed in 0.040139 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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