#๐Ÿ”’ drawing a mandelbrot figure using tkinter and pillow.

10 messages ยท Page 1 of 1 (latest)

frank minnowBOT
#

@kindred bolt

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

kindred bolt
#

So for my homework of my programming class we must draw a mandelbrot figure using tkinter and pillow according to the formula that is in the code. However when i want to draw the points into the label of the figure nothing happens or too few points are drawn. How do i fix these issues. this is the code

#
from tkinter import Frame, Button, Label, Entry
from PIL import Image, ImageTk
from PIL.ImageDraw import Draw
from PIL.ImageTk import PhotoImage
import math

scherm = Frame()
scherm.configure(width=500, height=500)
scherm.master.title("Basis")
scherm.pack()

plaatje = Image.new(mode="RGBA", size=(500,500))

afbeelding = Label(scherm,width=500,height=180)
afbeelding.place(x=0,y=0)
afbeelding.configure(background="gray")

mandel = Label(scherm, width=460, height=300)
mandel.place(x=20, y=180)
mandel.configure(background="white")

draw = Draw(plaatje)

text = Label(scherm); text2 = Label(scherm); text3 = Label(scherm); text4 = Label(scherm)
knop = Button(scherm)
invoer_mx = Entry(scherm); invoer_my = Entry(scherm); invoer_schaal = Entry(scherm); invoer_aantal = Entry(scherm)

text.place(x=20,y=10); invoer_mx.place(x=100, y=10)
text.configure(text="Midden X")
text.configure(background="gray")

text2.place(x=20, y=40); invoer_my.place(x=100, y=40)
text2.configure(text="Midden Y")
text2.configure(background="gray")

text3.place(x=20, y=70); invoer_schaal.place(x=100, y=70)
text3.configure(text="Schaal")
text3.configure(background="gray")

text4.place(x=20, y=100); invoer_aantal.place(x=100, y=100)
text4.configure(text="Max Aantal")
text4.configure(background="gray")

knop.place(x=20, y=130)
knop.configure(text="Go")

mx = 0
my = 0

fy = 0
fx = 0

offset = 0

mb_getal = 0
max_herhalingen = 100
def mandelbrot(x, y):
    global invoer_mx, invoer_my, invoer_schaal, invoer_aantal
    global mb_getal, invoer_x, invoer_y, fx, fy, foto,offset

    while mb_getal < max_herhalingen:
        a = fx*fx - fy*fy + x # formula to calculate the x and y coordinate of the point
        b = 2*fx*fy+ y
        fx = a # stel deze opnieuw gelijk aan fx zodat er mee doorgerekend kan worden
        fy = b
        pytago = math.sqrt(fx*fx + fy*fy) # bereken of de hypo niet groter is dan 2
#
        if mb_getal == 0 and pytago > -2.0 and pytago < 2.0: # check of de ingevulde getallen niet gelijk al een hypo van 2 geven
            print("Increase",pytago)
            draw.rectangle(((200,200),(300,300)), outline="blue")
            mb_getal +=1
        elif mb_getal > 0 and pytago > -2.0 and pytago < 2.0: # Zet de count voort
            if mb_getal % 2==0:
                draw.rectangle(((fx,fy),(fx,fy)), fill="red")
                mb_getal += 1
                offset += 10
                print(mb_getal, pytago, fx, fy)
            elif mb_getal % 2 != 0:
                draw.rectangle(((fx,fy), (fx, fy)), fill="black")

                mb_getal += 1
                offset+=10
                print(mb_getal, pytago, fx, fy)
        elif pytago < -2.0 or pytago > 2.0:
            mb_getal+=1
            print(mb_getal, pytago)
            break

    foto = PhotoImage(plaatje)
    mandel.configure(image=foto)

def knop_klik(): #Wat er gebeurd als er de knop word gedrukt
    global mx, my
    try:
        mx = float(invoer_mx.get()) #Zet de mx om van entry naar float
        my = float(invoer_my.get())
        mandelbrot(mx,my)
    except ValueError:
        print("fill in a normal number")

knop.configure(command=knop_klik)

omgezetPlaatje = PhotoImage(plaatje)
afbeelding.configure(image=omgezetPlaatje)
scherm.mainloop()

indigo fractal
#

!paste

frank minnowBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

indigo fractal
#

It's easier if it's all together so we can run it and check it

indigo fractal
frank minnowBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.