How to make 3D out of this assignment?

Hi, I am new to this, so maybe I am not supposed to send it like this…

I would be very grateful if someone could help me to make a 3D out of this project that I have, I am stuck. When you start it, you’ll see what happens. Now, the next step should be to make a 3D out of this existing script. Everything will be the same, 2D shapes will move but in one moment those shapes should form some mesh 3D shape.

IMG-8992

import java.util.Random;

ArrayList<Blob> taskbls = new ArrayList<Blob>();

//assiging variables

color c1 = #FFFFFF;

color c2 = #6699FF;

color c3 = #808080;

color c4 = #F08080;

color c5 = #F5F5DC;

color[] colors = {c1, c2, c3, c4, c5};

int novariation = 0;

float xScale, yScale, centerX, centerY; //co-ordinates variable

float changeDuration = 3000;

float lchange = 0;



public class Blob {

float x, y, size, lastX, lastY, direction;

color blobColor;

}



public void settings() {

size(800, 800);

noSmooth();

}



void setup() {

textAlign(CENTER, CENTER); //aligining text

xScale = width / 20; //fixing on x scale

yScale = height / 20 * (width / height); //fixing on y scale

centerX = width / 2;

centerY = height / 2;

}



void draw() { //drawing shapes function

if (mousePressed) { //condition for mouse click

for (int i = 0; i < 50; i++) { //for loop for desifning using assigned co ordinates

float x = mouseX + random(-100, 100);

float y = mouseY + random(-100, 100);

Blob blob = new Blob();

blob.x = getXPos(x);

blob.y = getXPos(y);

blob.size = random(1, 3);

blob.lastX = x;

blob.lastY = y;

blob.blobColor = colors[floor(random(0, colors.length))];

blob.direction = random(0.1, 1) * (Math.random() > 0.5 ? 1 : -1); //directions

taskbls.add(blob);

}

}

int length = taskbls != null ? taskbls.size() : 0;

if (length == 0) {

background(26,6,51); //default background color

noStroke();

fill(50,50,50);

textSize(40); //defining size of text

textAlign(CENTER, CENTER);

text("Click On Mouse", centerX, centerY); //click on mouse functionallity

return;

}

noStroke();

fill(26, 6, 51, 10);

rect(0, 0, width, height); //filling rectanangle

float time = millis();

if (time - lchange > changeDuration) { //setting time duration in filling colors

lchange = time;

novariation++;

fill(255);

if (novariation > 11) novariation = 0;

}

int deltaTime = 5;

float stepsize = deltaTime * 0.002;

for (int i = length - 1; i >= 0; i--) { //loop for small circles

Blob blob = taskbls.get(i);

float x = getSlopeX(blob.x, blob.y);

float y = getSlopeY(blob.x, blob.y);

blob.x += blob.direction * x * stepsize;

blob.y += blob.direction * y * stepsize;

x = getXPrint(blob.x);

y = getYPrint(blob.y);

stroke(blob.blobColor);

strokeWeight(blob.size);

line(x + 1, y - 1, blob.lastX, blob.lastY);

blob.lastX = x;

blob.lastY = y;

}

}

float getSlopeX(float y, float x){ //direction function one using math formula 1

switch(novariation){

case 0:return (float)Math.sin(x)+cos(-y);

case 1:return (float)Math.sin(x*5)*y*0.3*(float)Math.log(Math.abs(y));

case 2:return (float)Math.cos(x*y)+sin(x);

case 3:return (float)Math.sin(x)*(float)Math.cos(y);

case 4:return (float)Math.sin(x)+cos(-x)*(float)Math.log(Math.abs(y));

case 5:return (float)Math.sin(x)+cos(-x);

case 6:return (float)Math.tan(x)*(float)Math.cos(y)*(float)Math.log(Math.abs(y));

case 7:return (float)Math.sin(x*5.1)*-3;

case 8:return (x-x*x*x)*0.01;

case 9:return (float)Math.sin(x)+cos(-x);

case 10:return -y-(float)Math.sin(1.5*x) + 0.7;

case 11:return (float)Math.sin(x)*(float)Math.cos(y)*(float)Math.log(Math.abs(y));

default: return (float)Math.sin(x)+cos(-y);

} }



float getSlopeY(float x, float y) { //direction function one using math formula 2

switch (novariation) {

case 0: return (float)Math.sin(x) + cos(-y) * (float)Math.log(Math.abs(y));

case 1: return (float)Math.sin(x * 5) * y * 0.3 * (float)Math.log(Math.abs(y));

case 2: return (float)Math.cos(x * y) + sin(x);

case 3: return (float)Math.sin(x) * (float)Math.cos(y) * (float)Math.log(Math.abs(y));

case 4: return (float)Math.sin(x) + cos(-x) * (float)Math.log(Math.abs(y));

case 5: return (float)Math.sin(x) + cos(-x);

case 6: return (float)Math.tan(x) * (float)Math.cos(y) * (float)Math.log(Math.abs(y));

case 7: return (float)Math.sin(x * 5.1) * -3;

case 8: return (x - x * x * x) * 0.01;

case 9: return (float)Math.sin(x) + cos(-x) * (float)Math.log(Math.abs(y));

case 10: return -y - (float)Math.sin(1.5 * x) + 0.7;

case 11: return (float)Math.sin(x) * (float)Math.cos(y) * (float)Math.log(Math.abs(y));

default: return (float)Math.sin(x) + cos(-y) * (float)Math.log(Math.abs(y));

}

}



float getXPos(float x){ //getting position on x axis

return (x-centerX)/xScale;

}

float getYPos(float y){ //getting position on y axis

return (y-centerY)/yScale;

}

float getXPrint(float x){ //show designs x axis with all parameters

return xScale*x+centerX;

} float getYPrint(float y){ //show designs y axis with all parameters

return yScale*y+centerY;

}
1 Like

A way to convert a sketch in 3D elements can be found in:

image http://toxiclibs.org/2011/12/metworks-workshop-facade/

it is not answering your question directly but might help in getting the concept and use a library to convert a sketch in dxf /stl or .obj models

in draw in the if mousePressed section:

blob.x = getXPos(x);
blob.y = getXPos(y);

in the 2nd line it should be getYPos

In the class Blob there is direction - wouldn’t a directionX and directionY separately be better?

Why

float getSlopeX(float y, float x) {

?

better

float getSlopeX(float x, float y) {

?

Basically to position and previous position and movement always add a Z position.

The resulting structure is 3D

To rotate it though, you would have to store the drawing and display it from the storage