《Processing 番外編》 描画/円

描画 円など

円や半円(arc)の基本的描画については《Processing 番外編》 円/基礎を参照ください。

三角関数を使って円の描画 b-7 三角関数

size(500,500);
background(250,220,225);
strokeWeight(5);
smooth();

float radius=100;
int Ax=250;
int Ay=250;

stroke(250,223,98);
noFill();
ellipse(Ax,Ay,radius*2,radius*2);

stroke(249,124,122);
float x,y;
float Bx=-999;
float By=-999;
for(float ang =0;ang<=360;ang+=10){
  float rad =radians(ang);
  x=Ax+(radius*cos(rad));
  y=Ay+(radius*sin(rad));
  point(x,y);
}

螺旋(らせん)の描画

size(500,500);
background(250,220,225);
strokeWeight(5);
smooth();

float radius=100;
int Ax=250;
int Ay=250;

stroke(249,124,122);
noFill();
ellipse(Ax,Ay,radius*2,radius*2);

radius=10;
float x,y;
float Bx=-999;
float By=-999;
for(float ang =0;ang<=1800;ang+=5){
  radius+=0.2;
  float rad =radians(ang);
  x=Ax+(radius*cos(rad));
  y=Ay+(radius*sin(rad));
  if(Bx>-999){
    line(x,y,Bx,By);
  }
  Bx=x;
  By=y;
  By=y;
}

螺旋(らせん)の描画/ノイズ

size(500,500);
background(250,220,225);
strokeWeight(5);
smooth();

float radius=100;
int Ax=250;
int Ay=250;

stroke(249,124,122);
noFill();
ellipse(Ax,Ay,radius*2,radius*2);

radius=10;
float x,y;
float Bx=-999;
float By=-999;
float Noise=random(10);
for(float ang =0;ang<=1800;ang+=5){
  Noise+=0.05;
  radius+=0.5;
  float thisRadius=radius+(noise(Noise)*200)-100;
  float rad =radians(ang);
  x=Ax+(thisRadius*cos(rad));
  y=Ay+(thisRadius*sin(rad));
  if(Bx>-999){
    line(x,y,Bx,By);
  }
  Bx=x;
  By=y;
 }

螺旋(らせん)の描画/ノイズver.2

size(500,500);
background(250,220,225);
strokeWeight(0.5);
smooth();

int Ax=250;
int Ay=250;

float x,y;
for(int i =0;i<100;i++){
float Bx=-999;
float By=-999;
float Noise=random(10);
float radius= 10;
stroke(random(20),random(50),random(70),80);
stroke(249,124,122);

int start=int(random(360));
int end=1800+int(random(1800));
int step=5+int(random(3));
for(float ang =start;ang<=end;ang+=step){
  Noise+=0.05;
  radius+=0.5;
  float thisRadius=radius+(noise(Noise)*200)-100;
  float rad =radians(ang);
  x=Ax+(thisRadius*cos(rad));
  y=Ay+(thisRadius*sin(rad));
  if(Bx>-999){
    line(x,y,Bx,By);
  }
  Bx=x;
  By=y;
}
}