5回目のp5.js
let x; //宣言 let y; let r; let add; function setup() { createCanvas(400, 400); colorMode(HSB, 360, 100, 100, 100); x = 200; //代入 y = 0; r = 100; } function draw() { add = random(140, 150); background(0, 0, 100); noStroke(); fill(0, 100, 100); ellipse(x, y, r, r); ellipse(x - add, y, r, r); ellipse(x + add, y, r, r); y=y+add%10; y=y%(height+r); }
let num = 150; function setup() { createCanvas(400, 400); colorMode(HSB, 360, 100, 100, 100); print(num == 100);//Q.numは100より大きいか? //A.下に書いたやで } function draw() { // background(220); if (mouseIsPressed) { fill(random(180, 250), 100, 100); noStroke(); ellipse(mouseX, mouseY, random(100), random(100)); } else { stroke(0,0,50,50); fill(random(-50,100),100,100,30); rectMode(CENTER); rect(random(width), random(height), random(100), random(100)); } }
let x; let y; let r; let sx; let sy; let count; let countw; let counth; let c; let wins; let winh; let rr; function setup() { createCanvas(400, 400); colorMode(HSB, 360, 100, 100, 100); x = width / 2; y = height / 2; r = random(5, 50); sx = random(-5, 5); sy = random(-5, 5); smooth(); count = 0; countw = 0; counth = 0; c = 0; winw = 0; winh = 0; rr = random(0, 1); } function draw() { //boll fill(c % 360, 100, 100); noStroke(); ellipse(x, y, r, r); fill((c + 30) % 360, 50, 100, 10); rect(0, 0, width, height); //speed x = x + sx * 2; y = y + sy * 2; //bownd if (x + r / 2 > width || x - r / 2 < 0) { sx = sx * -1; count = count + 1; countw = countw + 1; c = c + 1; } if (y + r / 2 > width || y - r / 2 < 0) { sy = sy * -1; count = count + 1; counth = counth + 1; c = c + 1; } //moji push(); translate(width / 2, height / 2); fill(0, 0, 100, 50); rectMode(CENTER); rect(0, 0, width, 100); fill(0, 0, 0); text(count, 0, 0); text(countw, 0 - 50, 0 + 30); text(counth, 0 + 50, 0 + 30); if (countw >= 30) { countw = 0; winw = winw + 1; } if (counth >= 30) { counth = 0; winh = winh + 1; } text("WINNING COUNT", 80, 0); text("WINNING COUNT", -180, 0); text(winw, -130, 20); text(winh, 130, 20); fill(0, 0, 0); text("総合計", 0 - 13, 0 - 15); text("左右", 0 - 50 - 7, 0 + 30 - 15); text("上下", 0 + 50 - 7, 0 + 30 - 15); pop(); }
割と長く書いててびっくりしてる。宣言と代入を別々にしてるからってのもあるからかもだけど。一番最後は先に勝った方が更新しない限り、勝ち続けるという単調なものになりました。