Hello!
I found this tutorial video online for creating Sine wave structures in p5.js
I don’t really know p5 very well, but I thought I would follow along, and try to do everything in the video with Processing instead.
For the most part I think I did ok. I got really confused with some of the rotations.
I think maybe p5 rotates from the center automatically, while Processing must be translated first?
I’m not really sure. But I wanted to see what everyone here thought.
Check my work, so to speak.
Here’s the original p5.js code from the tutorial.
function setup() {
createCanvas(400, 400, WEBGL)
angleMode(DEGREES)
}
function draw() {
background(30)
rotateX(60)
noFill()
stroke(255);
for (var i = 0; i < 50; i++) {
var r = map(sin(frameCount / 2), -1, 1, 100, 200)
var g = map(i, 0, 50, 100, 200)
var b = map(cos(frameCount), -1, 1, 200, 100)
stroke(r, g, b)
rotate(frameCount/ 20)
beginShape()
for (var j = 0; j < 360; j += 60) {
var rad = i * 3
var x = rad * cos(j)
var y = rad * sin(j)
var z = sin(frameCount * 2 + i * 5) * 50
vertex(x, y, z)
}
endShape(CLOSE)
}
}
Here is my translation into Processing.
void setup() {
size(400, 400, P3D);
frameRate(30);
pixelDensity(2);
}
void draw() {
background(30);
translate(0, height/4, -200);
rotateX(radians(60));
noFill();
stroke(255);
strokeWeight(2);
translate(width/2, height/2);
for (float i = 0; i < 50; i++) { // number of rings
float r = map(sin(radians(frameCount)), -1, 1, 100, 200);
float g = map(i, 0, 20, 100, 200);
float b = map(cos(radians(frameCount)), -1, 1, 255, 100);
stroke(r, g, b);
rotate(radians(frameCount)/50);
beginShape();
for (float j = 0; j < 360; j += 60) {
float rad = i * 3;
float x = (rad * cos(radians(j)));
float y = (rad * sin(radians(j)));
float z = sin(radians(frameCount * 2 + i * 5)) * 50;
vertex(x, y, z);
}
endShape(CLOSE);
}
}