Skolekoding.no > Tekst-koding > p5.js > NOC trinn for trinn
Forslag til løsning av oppgave 7
- let ax, ay, bx, by;
- let pencil_x, pencil_y;
- let angleA, angleB;
- let speedA, speedB;
- function setup() {
- createCanvas(400, 400);
- noFill();
- angleA = 0.0;
- angleB = 0.0;
- speedA = 0.05;
- speedB = 0.07;
- }
- function draw() {
- background(220);
- strokeWeight(1);
- ellipse(100, 100, 100);
- ellipse(300, 300, 100);
- ax = 100 + cos(angleA) * 50;
- ay = 100 + sin(angleA) * 50;
- bx = 300 + cos(angleB) * 50;
- by = 300 + sin(angleB) * 50;
- pencil_x = bx;
- pencil_y = ay;
- line(ax, ay, pencil_x, pencil_y);
- line(bx, by, pencil_x, pencil_y);
- strokeWeight(4);
- point(ax, ay);
- point(bx, by);
- point(pencil_x, pencil_y);
- angleA = angleA + speedA;
- angleB = angleB + speedB;
- }
Oppgave 8
Tegn et spor etter pennen som skal lage figuren
skolekoding.no
Stein Olav Kivle