Schreibe mit ein p5.js Skript, das viele unterschiedliche… · The Chat ArchiveSchreibe mit ein p5.js Skript, das viele unterschiedliche farbige Formen animiert und…
Download ▾
In OpenAssistant data, “assistant” turns were written by human volunteers as demonstrations. They are not model outputs.
User Schreibe mit ein p5.js Skript, das viele unterschiedliche farbige Formen animiert und Mausinteraktion integriert.
Assistant Gerne, hier ist ein Js. Code der mit der p5 Libary nutzbar ist und folgendes macht:
- Erzeugt unterschiedliche formen mit unterschiedlichen Farben
- animierte Bewegungen
- Mausklickinteraktion beim klicken auf eine Form:
let shapes = [];
let colors = ["#FF6F61", "#6B5B95", "#88B04B", "#F7CAC9", "#92A8D1"];
let numShapes = 30;
let speed = 1;
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
function setup() {
createCanvas(windowWidth, windowHeight);
for (let i = 0; i < numShapes; i++) {
shapes.push(new Shape(random(width), random(height), random(10, 60), random(10, 60), random(colors)));
}
}
function draw() {
background(255);
for (let i = 0; i < shapes.length; i++) {
shapes[i].move(speed);
shapes[i].display();
}
}
function mousePressed() {
for (let i = shapes.length - 1; i >= 0; i--) {
if (shapes[i].clicked(mouseX, mouseY)) {
shapes.splice(i, 1);
}
}
}
class Shape {
constructor(x, y, w, h, color) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.randShape = int(random(3));
switch (this.randShape) {
case 0:
this.shape = "ellipse";
break;
case 1:
this.shape = "rect";
break;
case 2:
this.shape = "triangle";
break;
}
this.color = color;
this.angle = random(360);
}
move(speed) {
this.angle += speed * 0.01;
this.x += sin(this.angle) * 1;
this.y += cos(this.angle) * 5;
if (this.x > width + this.w) {
this.x = -this.w;
}
if (this.x < -this.w) {
this.x = width + this.w;
}
if (this.y > height + this.h) {
this.y = -this.h;
}
if (this.y < -this.h) {
this.y = height + this.h;
}
}
display() {
fill(this.color);
switch (this.randShape) {
case 0:
ellipse(this.x, this.y, this.w, this.h);
break;
case 1:
rect(this.x, this.y, this.w, this.h);
break;
case 2:
triangle(this.x, this.y - this.h/2, this.x - this.w/2, this.y + this.h/2, this.x + this.w/2, this.y + this.h/2);
break;
}
}
clicked(mx, my) {
let d = dist(mx, my, this.x, this.y);
if (d < this.w/2 || d < this.h/2) {
return true;
} else {
return false;
}
}
}