Week 02. Computer Aided Design

Assignments for this week

  • model a possible final project
  • compress my images and videos
  • post a description with your design files on my class pages

What I've done this week

  1. Draw a 2D model of the silhouettes
    • generator an image of a bird with AI
    • make a silhouette of a bird
  2. Model a structure to express the glowing and flickering of candles
    • overlapping lattices
    • overlapping lattice shell structures
    • animation of the moving shells

1. Draw a 2D model of the silhouettes

The first thing I did this week is to Draw the 2D model for silhouettes on my lamp

generator an image of a bird with AI

First, I used some AI art genorators to make some references of flying birds.

wonder

First, I used the same iPhone app as last week, wonder, to generate images of birds.

This time I didn't select any style.

Set the aspect ratio to 3:2.

Set the keyword as "bird flying"

This is what I got:

img from wonder 1

img from wonder 2

Stable Diffusion

The next AI art generator I tried was Stable Diffusion I entered each options as followed:

option value
prompt bird flying
negative_prompt -
width 768
height 512
num_outputs 4

The outputs were PNG files. I converted the images to JPG file.

I made a bash file to convert every PNG file in a designated directory to JPG.

png2jpg.sh
for f in $1/*.png; do
    g=$(basename ${f%.*})
    if [ ! -e $g.jpg ]; then
        convert $f $g.jpg
    fi
done

To use this bash file, run the following command in cammoand line.

bash png2jpg.sh pngs #directory with PNG files

png2jpg

This is what I got:

img from sd0

img from sd1

img from sd2

img from sd3

make a silhouette of a bird

I chose this picture as an example.

img from wonder 2

I imported the picture into Affinity Designer

Then I traced the outline of the bird.

silhouette_trace1

Filled the line with black.

silhouette_trace2

silhouette_trace3

Edited the silhouetted to change the angle of the bird.

silhouette_trace4

silhouette_trace5

Tracing bitmaps

Since, there is no functions to trace bitmaps in Affinity designer, I used Inkscape.

It took me few steps to get the silhouette of the bird

I used "Path>Trace bitmap" in the tool bar to get the silhouette of the bird. The bird was white, black, gray and blue.

First I traced the white part by cutting off the dark part, and traced the black part by cutting off the bright part.

cutoff dark

cutoff bright

Adding these paths together, I got a part of the silhouette of the bird.

bird inkscape

bird inkscape silhouette

There were two difficult things I wasn't able to do:

  • Get the silhouette of the head of the bird.
    • Because, the head is overlapped with the left wing.
  • Get the silhouette of the whole right wing
    • Because, the gray part of the right wing was almost the same color with the shadows on the corners of the image.

I tried with a different image:

img from wonder 1

did the same process above and got:

bird inkscape2

bird inkscape silhouette2

The gradient of brightness and the angle of the bird is an important factor in the term of selecting the image to use.

2. Model a structure to express the glowing and flickering of candles

Last week, I modeled the outline of the lamp I plan to make for my final project.

This week, I will model structure inside the lampshade. The structures will move and create shadow on the shade. the shadow will be a pattern that decorates the lamp.

For the candle mode, I will use lattice shells to express the glowing and flickering of candels.

overlapping lattices

I will first draw an 2D example of lattices expressing candles flickering.

To draw the lattices, I use python. Here are the python libraries I used.

library version
matplotlib 3.6.3
numpy 1.23.4
opencv 4.6.0.66

These were installed by followings:

pip install matplotlib
pip install numpy
pip instell opencv-python

Caution

I failed to successfully create a mp4 files with opencv. A file was exported, but I could not open it. Insted of using opencv, I used ffmpeg.

Step 1. Import libraries

import cv2
import matplotlib.pyplot as plt
import numpy as np
import os
import shutil
import sys

%matplotlib inline

Step 2. Set the area to plot curves

fig = plt.figure()
ax = fig.add_subplot(111, polar=True)

ax.grid(False)
ax.set_yticklabels([])
ax.set_xticklabels([])

py_step2

Step 3. Draw a curve in polar coordinates

ax = plt.subplot(111, polar=True)

ax.grid(False)
ax.set_yticklabels([])
ax.set_xticklabels([])

x = np.linspace(0,np.pi/3)
y = x/np.pi

ax.plot(x,y,c='k')

py_step3

Step 4. Multipy curves in a circular pattern

def multipy(ax, num, B, color):
    for i in range(num):
        a = i * 2*np.pi / num

        x0 = B*x+a
        y0 = x/np.pi

        ax.plot(x0,y0,c=color)
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)

ax.grid(False)
ax.set_yticklabels([])
ax.set_xticklabels([])

x = np.linspace(0,np.pi/3)

multipy(ax, 8, 1, 'k')

py_step4

Step 5. Create curves bent in the oppsite direction

fig = plt.figure()
ax = fig.add_subplot(111, polar=True)

ax.grid(False)
ax.set_yticklabels([])
ax.set_xticklabels([])

x = np.linspace(0,np.pi/2)

multipy(ax, 12, 1, 'k')
multipy(ax, 10, -1/2, 'k')

pystep5

Step 6. Make frame of two lattices rotating

def rotate(ax, num, B, d, color):
    for i in range(num):
        a = i * 2*np.pi / num

        x0 = B*x+a + d
        y0 = x/np.pi

        ax.plot(x0,y0,c=color)
if os.path.exists('frames'):
    shutil.rmtree('frames')
os.mkdir('frames')

frame = 200
for j in range(frame):
    fig = plt.figure()
    ax = fig.add_subplot(111, polar=True)

    ax.grid(False)
    ax.set_yticklabels([])
    ax.set_xticklabels([])

    x = np.linspace(0,np.pi/2)

    multipy(ax, 12, 1, 'k')
    multipy(ax, 10, -1/2, 'k')

    d = j * 2*np.pi / frame

    rotate(ax, 12, 1, d, 'k')
    rotate(ax, 10, -1/2, d, 'k')

    fig.savefig(f'./frames/pic_{j:02}.jpg')

    plt.clf()
    plt.close()

Step 7. Make video file

First I tried opencv

fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video = cv2.VideoWriter('lattice_rotate.mp4', fourcc, 20.0, (100,100))

if not video.isOpened():
    print("can't be opened")
    sys.exit()

for i in range(frame):
    img = cv2.imread(f'./frames/pic_{j:02}.jpg')

    if img is None:
        print("can't read")
        break

    video.write(img)

video.release()
print('written')

'lattice_rotate.mp4' was exported. However, I couldn't open it in my PC.

So, I tried ffmpeg, and got this:

ffmpeg -r 20 -i ./frames/pic_%02d.jpg rotate.mp4

overlapping lattice shell structures

Next, I modeled a 3D structure that make shadow like the video above.

Step 1. Design the curve on lampshade

Draw two curves (in purple) that corespond to Step 3 in the 2D lattice. Black lines are support line from the lightsource to points on the curves.

cad01

Step 2. Loft the black lines to two curved surfaces

cad02

Step 3. Thicken the surfaces

cad03

Step 4. Create the base shell model of the lattice shell

cad04

Step 5. Intersect the base shell and curved surface

cad05

Step 6. Multiply the intersections by cilrcular pattern and Union all to get a llattice shell

cad06

Step 7. Make an inner lattice shell

cad07

Step 8. Make a movie of lattice shells rotating

Shadow on shade will look like this:

The next problem will be how to fix the lattice shells on the base, and how to make the lattice shells to rotate.

Downloads

Here are the files I created this week.