编写绘制立方体的功能。我可以设法制作一个完整的立方体,只有y轴心数据集(文本中的更多信息)
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()
正如标题所说,我想为吸引魔方的学校制定一个课程。本质上,用户输入了立方体的大小(3x3,4x4,...),并且该程序读取输入大小的第一个数字。因此,如果用户写3x3,则程序将在开始时读取数字“ 3”。
从那里,程序将运行y = canvas.create_polygon(100,cube_y,200,cube_y,200,cube_y2,100,cube_y2,fill = e,fill = e,utline ='black ='black',
100x100宽度的宽度与循环的运行次数多次,块将增加100 px(例如,它将升高y轴)。 ,每次它都会上升100 px。 如果我输入3x3
我需要帮助的是x轴。我设法使程序在垂直轴上绘制了立方体,但是我无法在水平轴上进行管理。 我的计划本质上是要有代码y = canvas.create_polygon(100,cube_y,200,cube_y,200,cube_y2,100,cube_y2,cube_y2,fill = e,fill = e,utline ='black'
运行多次运行作为计数器,但每次,多边形的X点正确
。 - 使用y = canvas.create_polygon()代码,然后将其绘制相同的形状,但是这次整个代码将在x轴上移动100个PX,而最终产品则看起来像是类似的。
如果有人有任何想法关于这样做的,请告诉我,并为THX的墙壁道歉!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我编写的代码,这是为了让您开始,它并不完美,但是您可以调整Cube的大小以及所需的方式和窗口。
我实现了一个循环,该循环循环沿列和行循环,该循环设置为立方体大小。如果将立方体尺寸设置为3,则循环将从1变为3并绘制每个形状。使用
canvas.create_rectangle(tilesize * col,tilesize * row,tilesize * col + tilesize,tilesize * row + tilesize,fill ='red'')
。tilesize*col
=50*1,50*2,50*3 == 50,100,100,150
对于
tilesize *行
第二
x
和y
是x和y上方这使每个矩形50x50像素。您可以根据自己的喜好调整尺寸和位置。
调整此部分:CANVAS.CREATE_RECTANGLE(
tilesize * col,tilesize * low
,tilesize * col + tilesize,tilesize,tilesize * row + tilesize,fill ='red ='red ='red ='red ='red ='red'),以更改多个立方体开始绘制的地方。调整此部分:canvas.create_rectangle(
tilesize
* col,tilesize
*行,tilesize * col +tilesize
,tilesize *行 +> tilesize
,fill ='red')对于每个正方形的大小。This is the code I have written, this is to give you a start, it isn't perfect but you can adjust the sizes of the cube how you want, and the window.
I implemented a loop which loops over columns and rows, which is set to the cube size. If the cube size is set to 3, the loop will go from 1 to 3 and draw each shape. The shape is draw using
canvas.create_rectangle(tileSize * col, tileSize * row, tileSize * col + tileSize, tileSize * row + tileSize, fill='red')
.tileSize * col
=50*1, 50*2, 50*3 == 50, 100, 150
and it is the same for
tileSize * row
the second
x
andy
are the x and y above+ tileSize
which makes each rectangle 50x50 pixels. You can adjust the sizes and placement to your liking.Adjust this part: canvas.create_rectangle(
tileSize * col, tileSize * row
, tileSize * col + tileSize, tileSize * row + tileSize, fill='red') to change where the cube starts to draw.Adjust this part: canvas.create_rectangle(
tileSize
* col,tileSize
* row, tileSize * col +tileSize
, tileSize * row +tileSize
, fill='red') for the size of each square.