Comutare navigație
pbInfo.ro
Probleme
Probleme - clasa a IX-a
Probleme - clasa a X-a
Probleme - clasa a XI-a
Probleme din concursuri
Căutare problemă
Exerciții
Programează cu Blockly
Desenează cu Processing
Exersează SQL
Soluţii
Resurse
Resurse pentru clasa a IX-a
Resurse pentru clasa a X-a
Resurse pentru clasa a XI-a
Subiecte bacalaureat
Ajutor
Autentificare
Înregistrare
×
Autentificare
Utilizator sau email
Parola
Acest site foloseşte cookies. Navigând în continuare, vă exprimaţi acordul asupra folosirii cookie-urilor.
Îti place pbInfo? Atunci acceptă-l cu totul! Dezactivează modulul de blocare a reclamelor!
×
Lista scripturi
Script Nou
Ajutor
"Beculete cu probleme de identitate" - Processing
ID
Autor
Duplicat din
Ultima modificare
#3437
Takacs Robert (RoTak)
-
Marti, 10 dec 2019, 10:07
function distToCenter(x1, y1) { return sqrt(x1 * x1 + y1 * y1); } class Light { constructor(x, y, type, flip, scale = 1) { this.x = x; this.y = y; this.type = type; this.state = 0; //ON this.flip = flip; this.scale = scale; this.radius = scale * 45; this.originalRadius = this.radius; this.DECREMENT = 7; } update() { let inc = int(random(2)); if(inc == 0 && this.originalRadius - this.radius < 5){ this.radius--; } if(inc == 1 && this.radius - this.originalRadius < 5){ this.radius++; } } show() { let x = this.x; let y = this.y; let flip = this.flip; let scale = this.scale; let fillColor = "#00000000"; if(this.type == 1 && this.state == 0){ // BLUE OFF fillColor = "#034861"; } if(this.type == 1 && this.state == 1){ // BLUE ON fillColor = "#0cb7f5"; } if(this.type == 2 && this.state == 0){ // GOLD OFF fillColor = "#946d0a"; } if(this.type == 2 && this.state == 1){ // GOLD ON fillColor = "#fcc330"; } fill(fillColor); stroke(0); strokeWeight(1); beginShape(); curveVertex(x, y); curveVertex(x, y); curveVertex(x - 10 * flip * scale, y - 10 * flip * scale); vertex(x, y - 25 * flip * scale); curveVertex(x + 10 * flip * scale, y - 10 * flip * scale); endShape(CLOSE); fill("#481A04"); ellipse(x, y, 4 * scale, 8 * scale); let xMid = x, yMid = (4 * y + 10 * (y - 25 * flip * scale)) / 14; let GradColor = "#00000000"; if(this.type == 1){ GradColor = "#0cb7f510"; } if(this.type == 2){ GradColor = "#fcc33010"; } if(this.state == 1) { fill(GradColor); noStroke(); for(let r = this.radius; r >= 10 * scale; r -= this.DECREMENT){ ellipse(xMid, yMid, r, r); } } } OnOff() { this.state = !this.state; } } let COLOR_NO_HOVER = "#930B9B"; let COLOR_HOVER = "#B309BC"; let buttonColor = "#930B9B"; let lights = []; let pts = []; let alreadyPressed = false; function setup() { createCanvas(400, 400); textAlign(CENTER); let redOrBlue = 0; for(let i = 25; i <= 375; i += 35) { let x = (createVector(i, random(25) + 50)); let l = new Light(x.x, x.y, redOrBlue++ % 2 + 1, redOrBlue % 2 ? 1 : -1, 0.85); lights.push(l); } for(let i = 25; i <= 375; i += 35) { let x = (createVector(i, random(25) + 300)); let l = new Light(x.x, x.y, redOrBlue++ % 2 + 1, redOrBlue % 2 ? 1 : -1, 0.85); lights.push(l); } } function draw() { background(0); let len = lights.length; for(let i = 0; i < lights.length; ++i) { lights[i].update(); lights[i].show(); } push(); translate(200, 200); if(distToCenter(mouseX - 200, mouseY - 200) < 37.5 && !alreadyPressed){ buttonColor = COLOR_HOVER; } else{ buttonColor = COLOR_NO_HOVER; } noStroke(); fill(buttonColor); ellipse(0, 0, 75, 75); fill(255); textSize(15); text("ON/OFF", 0, 5); pop(); } function mousePressed() { if(distToCenter(mouseX - 200, mouseY - 200) < 37.5 && !alreadyPressed) { for(let i = 0; i < lights.length; ++i){ lights[i].OnOff(); } buttonColor = COLOR_NO_HOVER; alreadyPressed = true; } } function mouseReleased() { if(alreadyPressed){ alreadyPressed = false, buttonColor = COLOR_HOVER; } }
Duplicare
Executare
Cod
×
Cod HTML
<iframe sandbox="allow-scripts" src="/p5js/index.php?id=3437" style="width:408px; height:408px;border:solid 1px gray; overflow: scroll;"></iframe>
×
Duplicare script
Denumirea noului script
Du-te sus!