Schets met zeven  zevenhoeken die een zevenhoek vormen.                terug naar de inleiding
toets "s" stopt de rotaties de overige toetsen starten de rotaties
 

                                                                   zeven zevenhoeken die een zevenhoek vormen in fullscreen

 

zeven zevenhoeken vormen een zevenhoek in p5.js
 

De schets maakt gebruik van de p5.js class "Vhoek_n7" en de superclass "Vormen"

 
 let vorm = []; let n; let sliderAan = true;
function setup() {
  buttonR = createButton('reset');
  buttonR.position(20,40);buttonR.style('width','70px');
  buttonR.mouseClicked(buttonRAction);
  buttonH1 = createButton('h=180');
  buttonH1.position(100,40);buttonH1.style('width','70px');
  buttonH1.mouseClicked(buttonH1Action);
  button0 = createButton('dp 0');
  button0.position(20,80);button0.style('width','70px');
  button0.mouseClicked(button0Action);
  button1 = createButton('dp 1');
  button1.position(20,120);button1.style('width','70px');
  button1.mouseClicked(button1Action);
  button2 = createButton('dp 2');
  button2.position(20,160);button2.style('width','70px');
  button2.mouseClicked(button2Action);
  button3 = createButton('dp 3');
  button3.position(20,200);button3.style('width','70px');
  button3.mouseClicked(button3Action);
  button4 = createButton('n=0.7');
  button4.position(20,240);button4.style('width','70px');
  button4.mouseClicked(button4Action);
  button5 = createButton('n=1.5');
  button5.position(20,280);button5.style('width','70px');
  button5.mouseClicked(button5Action);
  button6 = createButton('sw=0');
  button6.position(20,320);button6.style('width','70px');
  button6.mouseClicked(button6Action);
 
if (sliderAan)
  {slider = createSlider(0, 200, 100, 2);
  slider.position(20, 360); sliderAan = false;}
 
  buttonD = createButton('downloaden');
  buttonD.position(20,400);buttonD.style('width','140px');
  buttonD.mouseClicked(buttonDAction);
 createCanvas(windowWidth, windowHeight);;
 const x = width/2; const y = height/2; n = height/8;
 let sw = n/65; const sc = 0; let hoek = 0;
 const ri = n/(2*tan(PI/7));      //straal van de binnencirkel
 const ro = n/(2*sin(PI/7));      //straal van de buitencirkel
 const sd = 2*n*cos(PI/7);        //sd (short diagonal) lijn met een tussenhoek
 const ld = n/(2*sin(HALF_PI/7)); //ld = lange diagonaal lijn met twee tussenhoeken
 const sdt = sqrt(n*n-(sd*sd)/4); //sdt is de lijn van de sd lijn naar de top
 const ldb = sqrt((3*n*n-ld*ld)/4+ld*n/2);  //ldb is de lijn van de ld lijn naar de basis
 vorm[0] = new Vhoek_n7(n,0,x-n/2, y+ri,      hoek,color(255,255,0,alfa), sw,sc);
 vorm[1] = new Vhoek_n7(n,0,x-ld/2,y+(ri-ldb),hoek,color(255,100,0,alfa), sw,sc);
 vorm[2] = new Vhoek_n7(n,0,x-sd/2,y-(ro-sdt),hoek,color(0,0,255,alfa),   sw,sc);
 vorm[3] = new Vhoek_n7(n,0,x,     y-ro,      hoek,color(194,216,60,alfa),sw,sc);
 vorm[4] = new Vhoek_n7(n,0,x+sd/2,y-(ro-sdt),hoek,color(29,240,153,alfa),sw,sc);
 vorm[5] = new Vhoek_n7(n,0,x+ld/2,y+(ri-ldb),hoek,color(255,0, 200,alfa),sw,sc);
 vorm[6] = new Vhoek_n7(n,0,x+n/2, y+ri,      hoek,color(240,191,29,alfa),sw,sc);
}
 
 function draw() {
  clear();
  background('rgba(255,255,255, 0)');
  alfa();
   for (let i = 0; i < 7; i++){vorm[i].display();}
 
   if (key == 's') { }
   else
 {
  vorm[0].dpRotRe(vorm[0]); vorm[1].dpRotRe(vorm[1]);
  vorm[2].dpRotRe(vorm[2]); vorm[3].dpRotRe(vorm[3]);
  vorm[4].dpRotRe(vorm[4]); vorm[5].dpRotRe(vorm[5]);
  vorm[6].dpRotRe(vorm[6]);
  }
}
 
function windowResize() {
 resizeCanvas(windowWidth, windowHeight);
}
 
function buttonRAction(){setup();}
function button0Action(){for(let i=0; i<7; i++){vorm[i].d=0;}}
function buttonH1Action(){for(let i=0; i<5; i++){vorm[i].hoek=180;}}
function button1Action() {vorm[0].d=1;vorm[1].d=2;
   vorm[2].d=3;vorm[3].d=4;vorm[4].d=5;vorm[5].d=6;vorm[6].d=7;}
function button2Action(){vorm[0].d=1;vorm[1].d=2;
   vorm[2].d=3;vorm[3].d=3;vorm[4].d=3;vorm[5].d=2;vorm[6].d=1;}
function button3Action(){vorm[0].d=1;vorm[1].d=1;
   vorm[2].d=1;vorm[3].d=0;vorm[4].d=7;vorm[5].d=7;vorm[6].d=7;}
function button4Action(){for(let i=0; i<7; i++){vorm[i].n= n*0.7;}}
function button5Action(){for(let i=0; i<7; i++){vorm[i].n= n*1.5;}}
function button6Action(){for(let i=0; i<7; i++){vorm[i].sw = 0;}}
function alfa(){let sliderAlfa = slider.value();
   vorm[0].c = color(255,255,0, sliderAlfa);
   vorm[1].c = color(255,100,0, sliderAlfa);
   vorm[2].c = color(0,  0, 255,sliderAlfa);
   vorm[3].c = color(194,216,60,sliderAlfa);
   vorm[4].c = color(29,240,153,sliderAlfa);
   vorm[5].c = color(255,0, 200,sliderAlfa);
   vorm[6].c = color(240,191,29,sliderAlfa);}
function buttonDAction(){save('zevenhoeken.png');}