Programming art [Tori]

in #creativity6 years ago (edited)


Tori in p5js
Hello, today I want to show you one of my animations. I'm using p5.js.


You can try the code and modify it here (better quality): https://alpha.editor.p5js.org/

Code:

function setup() {
   createCanvas(700, 700, WEBGL);
}

let angle = 0;
let surtax = 0;

function draw() {

   //set lights
   pointLight(155,210,255,50,50,50);
   ambientLight(255);

   background(0);

   //set perspective
   ortho(-500, 500, 500, -500, 0, 1000);
   rotateX(QUARTER_PI);
   rotateY(atan(1/sqrt(2))*1.2);


   //draw toruses
   let surtax = 0;

   for(let x=10; x<400; x+=20) {
       push();
       let ang = angle + surtax;
       rotateX(ang);
       rotateY(ang);
       ambientMaterial(0,255,0,80);
       torus(x, 5, 80, 50);
       pop();
       surtax += 0.27;
   }

   angle += 0.04;
}

Coin Marketplace

STEEM 0.27
TRX 0.13
JST 0.032
BTC 62656.62
ETH 2941.90
USDT 1.00
SBD 3.59