Added some things

This commit is contained in:
Cametendo
2026-04-20 11:20:54 +02:00
parent 97a7c9f0fb
commit 372b892862
29 changed files with 406 additions and 92 deletions

10
Week-2/Pictures/image.js Normal file
View File

@@ -0,0 +1,10 @@
let img;
function preload() {
img = loadImage("/Images/monitoring-miku.png");
}
function setup() {
createCanvas(720, 400);
image(img, 0, 0, 300, 300);
}

View File

@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sketch</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="/libraries/p5.min.js"></script>
<script src="/libraries/p5.sound.min.js"></script>
</head>
<body>
<script src="styleSettings.js"></script>
</body>
</html>

38
Week-2/Pictures/pixels.js Normal file
View File

@@ -0,0 +1,38 @@
let img;
function preload() {
img = loadImage("/Images/monitoring-miku.png");
}
function setup() {
createCanvas(600, 600);
pixelDensity(1);
}
function draw() {
background(0);
image(img, 100, 100, 400, 400);
/* img.loadPixels();
for (let i = 0; i < img.pixels.length; i += 4) {
let red = img.pixels[i + 0];
let green = img.pixels[i + 1];
let blue = img.pixels[i + 2];
let alpha = img.pixels[i + 3];
img.pixels[i + 0] = red;
img.pixels[i + 1] = green;
img.pixels[i + 2] = blue;
img.pixels[i + 3] = alpha;
}
img.updatePixels(); */
img.loadPixels();
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const index = (x + y * width) * 4;
img.pixels[index + 0] = mouseX;
img.pixels[index + 1] = mouseY;
img.pixels[index + 2] = y;
img.pixels[index + 3] = 100;
}
}
img.updatePixels();
}

View File

@@ -0,0 +1,32 @@
function setup() {
createCanvas(100, 150);
background(0, 150, 0);
ellipse(0, 50, 33, 33);
push();
translate(50, 0);
strokeWeight(10);
fill(204, 153, 0);
ellipse(0, 50, 33, 33);
pop();
ellipse(100, 50, 33, 33);
translate(0, 50);
ellipse(0, 50, 33, 33);
push();
strokeWeight(10);
fill(204, 153, 0);
ellipse(33, 50, 33, 33);
push();
stroke(0, 102, 153);
ellipse(66, 50, 33, 33);
pop();
pop();
ellipse(100, 50, 33, 33);
}

View File

@@ -0,0 +1,13 @@
function setup() {
createCanvas(800, 800);
background(200);
fill(150, 0, 0);
rect(0, 0, 60, 150);
translate(200, 120);
rotate(0.5);
scale(1.5);
fill(0, 150, 0);
rect(0, 0, 60, 150);
}

View File

@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Following circles sketch</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="libraries/p5.min.js"></script>
<script src="libraries/p5.sound.min.js"></script>
</head>
<body>
<script src="sketch.js"></script>
</body>
</html>

View File

@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bouncing DVD-type sketch</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="libraries/p5.min.js"></script>
<script src="libraries/p5.sound.min.js"></script>
</head>
<body>
<script src="random_sketch.js"></script>
</body>
</html>

View File

@@ -0,0 +1,82 @@
const amountOfFormPoints = 5;
const stepSize = 1;
const initRadius = 150;
// const mouseAttraction = 1; let centerX, centerY;
let x = [];
let y = [];
posX = 1;
posY = 1;
let movement_angle;
let xDirection = -1;
let yDirection = -1;
function setup() {
createCanvas(windowWidth, windowHeight);
// inital setup
centerX = width / 2;
centerY = height / 2;
const angle = radians(360 / amountOfFormPoints);
for (let i = 0; i < amountOfFormPoints; i++) {
x.push(cos(angle * i) * initRadius);
y.push(sin(angle * i) * initRadius);
}
movement_angle = random(360);
// styling
stroke(0.75);
strokeWeight(5);
noFill();
}
function draw() {
background(255, 255, 255, 10);
// float towards random position
if (centerX > windowWidth) {
xDirection = -1;
}
if (centerX < 0) {
xDirection = 1;
}
if (centerY > windowHeight) {
yDirection = -1;
}
if (centerY < 0) {
yDirection = 1;
}
posX = posX + 2 * xDirection;
posY = posY + 2 * yDirection;
centerX = windowWidth / 2 + posX;
centerY = windowHeight / 2 + posY;
console.log(xDirection);
// calculate new points
for (let i = 0; i < amountOfFormPoints; i++) {
x[i] += random(-stepSize, stepSize);
y[i] += random(-stepSize, stepSize);
// ellipse(x[i] + centerX, y[i] + centerY, 5, 5);
}
// first controlPoint
beginShape();
curveVertex(x[0] + centerX, y[0] + centerY);
// only these points are drawn
for (let i = 0; i < amountOfFormPoints; i++) {
curveVertex(x[i] + centerX, y[i] + centerY);
}
// Connect to the first poing again
// or use endShape(CLOSE); but result is different
curveVertex(x[0] + centerX, y[0] + centerY);
// end controlPoint
curveVertex(
x[amountOfFormPoints - 1] + centerX,
y[amountOfFormPoints - 1] + centerY,
);
endShape();
}

59
Week-2/Shapes/sketch.js Normal file
View File

@@ -0,0 +1,59 @@
const amountOfFormPoints = 5;
const stepSize = 1;
const initRadius = 150;
const mouseAttraction = 1;
let centerX, centerY;
let x = [];
let y = [];
function setup() {
createCanvas(windowWidth, windowHeight);
// inital setup
centerX = width / 2;
centerY = height / 2;
const angle = radians(360 / amountOfFormPoints);
for (let i = 0; i < amountOfFormPoints; i++) {
x.push(cos(angle * i) * initRadius);
y.push(sin(angle * i) * initRadius);
}
// styling
stroke(0, 75);
strokeWeight(0.5);
background(255);
noFill();
}
function draw() {
// float towards mouse position
centerX += (mouseX - centerX) * mouseAttraction;
centerY += (mouseY - centerY) * mouseAttraction;
// calculate new points
for (let i = 0; i < amountOfFormPoints; i++) {
x[i] += random(-stepSize, stepSize);
y[i] += random(-stepSize, stepSize);
// ellipse(x[i] + centerX, y[i] + centerY, 5, 5);
}
// first controlPoint
beginShape();
curveVertex(x[0] + centerX, y[0] + centerY);
// only these points are drawn
for (let i = 0; i < amountOfFormPoints; i++) {
curveVertex(x[i] + centerX, y[i] + centerY);
}
// Connect to the first poing again
// or use endShape(CLOSE); but result is different
curveVertex(x[0] + centerX, y[0] + centerY);
// end controlPoint
curveVertex(
x[amountOfFormPoints - 1] + centerX,
y[amountOfFormPoints - 1] + centerY,
);
endShape();
}