textSize (variable) using dictionary values making word cloud

edited December 2017 in Python Mode

Hi I have a quick question about textSize

I have a dictionary, that has values such as this {'birthday': 6, 'think': 5, 'cookie': 15, 'happy': 5, 'ice': 5, 'cream': 5, 'nom': 25, 'boy': 6}

Since I'm making a wordCloud, certain words have to be bigger than the other, and I was going to take the value and times it by three so it would be something like this

pop_words = {'birthday': 18, 'think': 15, 'cookie': 45, 'happy': 15, 'ice': 15, 'cream': 15, 'nom': 75, 'boy': 18}

I wanted to use those numbers as the textSize but I don't quite know how to do that.

I thought about putting it in a for loop but that doesn't seem to work for me, and I'm personally stuck

#Text data 
for value in pop_words:
    text_data = pop_words [value] *3
    textSize (text_data)
    text ("\n". join (pop_words), 250, 50+text_data)



#Display on canvas

size (500, 500)
background (0)
fill (255)
textAlign (CENTER)

Answers

  • Your code fragment makes it look like you are trying to use a static sketch (no setup, no draw) but attempting to draw to the screen before you have called size. That isn't right. Your #Text data should appear after you set up the screen -- the text() command draws to the screen, but it can't do that until the screen has a size and a background. You also want to make sure that you aren't drawing black text on a black background.

    Can you provide your whole sketch please?

  • Answer ✓

    Nvm figured it out

Sign In or Register to comment.