def graphics ():
window = tkinter.Tk()
window.geometry("800x800") #You enter the window dimensions for
canvas = tkinter.Canvas(window, bg = 'white', width=800, height=800)
#Code for creating graphical shapes
# note for me: im going to make a graphical drawing that draws a the sizes of the cubes user wants ! (so if there's a 2x2 cube, 3x3, and 4x4, ima draw those (2d only)
user_size = input("What size cube would you like to have drawn? (3x3, 2x2, ...): ")
user_size.split()
cube_size = int(user_size[0])
cube_size += 1
counter = 0
cube_y = 800
cube_y2 = 700
cube_x = 100
cube_x2 = 200
counter = 1
e = 'red'
while (counter != cube_size):
y = canvas.create_polygon(100,cube_y,200,cube_y,200,cube_y2,100,cube_y2, fill = e, outline = 'black', width = 7)
cube_y = cube_y - 100
cube_y2 = cube_y2 - 100
print(counter)
counter+= 1
#Flips the shapes from memory onto the monitor
canvas.pack()
window.mainloop()
as the title says, I want to make a program for school that draws rubiks cube. Essentially, user enters size of cube (3x3, 4x4, ...) and the program reads the first number of the entered size. So if user writes 3x3, program will read the number '3' at the beginning.
From there, the program will run y = canvas.create_polygon(100,cube_y,200,cube_y,200,cube_y2,100,cube_y2, fill = e, outline = 'black',
which creates a red block 100x100 px wide. For as many times as the loop runs, the block will go up by 100 px (it'll go up y-axis). For example, if user enters 3x3, the y code block will be made 3 times, each time it'll go up 100 px.
this is what it looks like if i enter 3x3
What I require help with is dealing with the x axis. I've managed to get the program to draw the cube on the vertical axis, but i can't manage on the horizontal axis.
My plan was to essentially have the code y = canvas.create_polygon(100,cube_y,200,cube_y,200,cube_y2,100,cube_y2, fill = e, outline = 'black'
run as many times as the counter, but with each time, the x points of the polygon goes 100 px right.
So for ex. if I were to ask for 4x4 cube to be drawn, the program would firstly draw the 4 cubes going up/vertical/y-axis using the y = canvas.create_polygon() code i mentioned before, then it would draw the same shape but this time the entire code would be moved 100 px right, on the x axis, horizontally. The final product should look something like this (pardon the shitty drawing i did this on google jamboard using mouse)
If anyone has any idea on how to do so, please let me know. And apologies for the wall of text in advance! Thx!