How do I use imported images in the CMU Graphics template?

Question:
I’m storing image links in an array because I used them later on in my program, but they throw an error when used. I tried downloading the images and using the file source into the img src property but it also threw an error. Can you even use images at all in the template?
Repl link:
https://replit.com/@ShashaVaquita/Monster-High-Docs#main.py

You have to change the main image store for this to work.

MainImageStorage=['https://replit.com/@ShashaVaquita/Monster-High-Docs#images/cleo.png','https://replit.com/@ShashaVaquita/Monster-High-Docs#images/draculaura.png','https://replit.com/@ShashaVaquita/Monster-High-Docs#images/frankie.png','https://replit.com/@ShashaVaquita/Monster-High-Docs#images/abbey.png'];

Change to your local files:

MainImageStorage = [
		'images/cleo.png',
		'images/draculaura.png',
		'images/frankie.png',
		'images/abbey.png'
]

The same thing when you are referencing the source for the initial image load

#Character Pic
Circle(200,150,90)
AnimatedFrame= Star(200,150,90,40)
AnimatedSpikes= Star(200,150,90,20)
AnimatedImageBorder= Circle(200,150,80)
app.image=Image('https://replit.com/@ShashaVaquita/Monster-High-Docs#images/cleo.png',130,80)

You change the app.image to:

app.image = Image(MainImageStorage[0], 130, 80)

MainImageStorage[0] references the first element in the MainImageStorage array, which, after we updated the array paths, now points to the local file path images/cleo.png.

4 Likes

I’ll try that. Thanks!

It works! That was helpful.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.