Chisato

2 minute read

Starting today, recreational weed is legal in Canada. This news has some how lead me to find Cannabis Curve, a mathematical equation to draw Cannabis….!!!

So to celebrate? being 2nd country in the world (1st was Uruguay) to legalize the green stuff for fun, I decided I’ll try drawing cannabis curve with ggplot. Here’s the final results.

Cannabis_Final

Cannabis_Final

Here’s the step I took, because I couldn’t really understand the mathematical equation, so I’ve break it down step by step to sort of understand what each part of equation is doing.

library(tidyverse)

cannabis <- tibble(
  t = seq(-pi,pi, length.out=1000),
  r1 = (1+.9*cos(8*t)), ## this will draw 8 petals  ## this number determines number of leafs!
  r2 = r1 * (1+.1*cos(24*t)), ## this make it pointy
  r3 = r2 * (.9+0.5*cos(200*t)), ## this makes it jaggy
  r4 = r3 * (1+sin(t)), ## Hmm.. I think I want to rorate it 90 degree... 
  r4_alt = r3 * (1+sin(t-pi/2)), ## one way to do it...
  r = (1+.9*cos(8*t)) * (1+.1*cos(24*t)) * (.9+0.5*cos(200*t)) * (1+sin(t))  ## Put all in line line!
) 

cannabis %>% 
  ggplot(aes(x=t, y=r1)) + 
  geom_path(color="#7ABA71", size=2) +
  coord_polar() +
  theme_void(base_family="Roboto Condensed") +
  labs(title = "(1+.9*cos(8*t) draws 8 petals")

cannabis %>% 
  ggplot(aes(x=t, y=r2)) + 
  geom_path(color="#7ABA71", size=2) +
  coord_polar() +
  theme_void(base_family="Roboto Condensed") +
  labs(title = "(1+.9*cos(8*t) * * (1+.1*cos(24*t)) makes the tip pointy")

cannabis %>% 
  ggplot(aes(x=t, y=r3)) + 
  geom_path(color="#7ABA71", size=0.5) +
  coord_polar() +
  theme_void(base_family="Roboto Condensed") +
  labs(title = "(1+.9*cos(8*t) * * (1+.1*cos(24*t)) * (.9+0.5*cos(200*t)) makes zaggy")

cannabis %>% 
  ggplot(aes(x=t, y=r4)) + 
  geom_path(color="#7ABA71", size=0.5) +
  coord_polar(start=pi/2) +
  theme_void(base_family="Roboto Condensed") +
  labs(title = "(1+.9*cos(8*t) * * (1+.1*cos(24*t)) * (.9+0.5*cos(200*t)) * (1+sin(t)) - OK Cool, Now 2 leaves are small!", subcaption="Notice I used start=pi/2 to rotate!")

cannabis %>% 
  ggplot(aes(x=t, y=r)) + 
  geom_polygon(fill="#499b4a", color="#74Ba71", size=0.1) +
  coord_polar(theta="x", start=pi/2) +
  theme_void(base_family="Roboto Condensed") +
  labs(title = "Instead of using geom_path, I used geom_polygon")

I couldn’t figure out how to “crop” the polar coordinate image, so there’s lots of white space on final image, but I like my little cannabis!


I couldn’t find way to crop the image, but I realized I just need to plot the above in Cartesian coordinate…!

# To translate polar coordinate to cartesian, I can use below 
## x = r * cos(theta)
## y = r * sin(theta)

cannabis <- cannabis %>% mutate(
  x = r * cos(t),
  y = r * sin(t)
)

cannabis %>% 
  ggplot(aes(x=x, y=y)) + 
  geom_polygon(fill="#499b4a", color="#74Ba71", size=0.1) +
  theme_void(base_family="Roboto Condensed") +
  labs(title = "Cannabis on Cartesian Coordinate")