# How to make 3D out of this assignment?

**URL:** https://discourse.processing.org/t/how-to-make-3d-out-of-this-assignment/16885
**Category:** Coding Questions
**Tags:** homework
**Created:** [January 5, 2020, 10:55pm UTC](https://discourse.processing.org/t/how-to-make-3d-out-of-this-assignment/16885 "2020-01-05T22:55:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![nuhic](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@nuhic](https://discourse.processing.org/u/nuhic)
#### Post date: [January 5, 2020, 10:55pm UTC](https://discourse.processing.org/t/how-to-make-3d-out-of-this-assignment/16885/1 "2020-01-05T22:55:16Z")

</div>

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.

 ![scr1](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f1c35f92e179f6b7f39e0be6a81c3d882a5e4183.png) ![IMG-8992](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/910b55f096fbeb6c1aaaab8959911db6c438297f.jpeg)

```auto
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;

}

```

---

<div class="post-metadata">

### Author: ![TTG](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ttg/32/983_2.png) [@TTG](https://discourse.processing.org/u/TTG)
#### Post date: [January 6, 2020, 9:22am UTC](https://discourse.processing.org/t/how-to-make-3d-out-of-this-assignment/16885/2 "2020-01-06T09:22:08Z")

</div>

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

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a29032b31fea40111dbfdede7a1d24e0a3a50956.png) [http://toxiclibs.org/2011/12/metworks-workshop-facade/](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

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 6, 2020, 3:47pm UTC](https://discourse.processing.org/t/how-to-make-3d-out-of-this-assignment/16885/3 "2020-01-06T15:47:09Z")

</div>

> [@nuhic](#):
>
> blob.x = getXPos(x);  
> blob.y = getXPos(y);

in draw in the if mousePressed section:

```auto
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?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 6, 2020, 3:51pm UTC](https://discourse.processing.org/t/how-to-make-3d-out-of-this-assignment/16885/4 "2020-01-06T15:51:02Z")

</div>

Why

float getSlopeX(float y, float x) {

?

better

float getSlopeX(float x, float y) {

?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 6, 2020, 5:44pm UTC](https://discourse.processing.org/t/how-to-make-3d-out-of-this-assignment/16885/5 "2020-01-06T17:44:46Z")

</div>

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
