本文目錄一覽:
- 1、用python畫一個圓
- 2、等一個大佬啊 要求用python創建一個窗口,窗口按鈕功能是創建一個球體或立方體。明天上課之前交給我
- 3、python編寫 球體,我可以借鑒哪些東西?
- 4、Python程序開發之簡單小程序實例(11)小遊戲-跳動的小球
- 5、c4d怎麼用python畫三維圖
用python畫一個圓
###################################
# coding=utf-8
# !/usr/bin/env python
# __author__ = ‘pipi’
# ctime 2014.10.11
# 繪製橢圓和圓形
###################################
from matplotlib.patches import Ellipse, Circle
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ell1 = Ellipse(xy = (0.0, 0.0), width = 4, height = 8, angle = 30.0, facecolor= ‘yellow’, alpha=0.3)
cir1 = Circle(xy = (0.0, 0.0), radius=2, alpha=0.5)
ax.add_patch(ell1)
ax.add_patch(cir1)
x, y = 0, 0
ax.plot(x, y, ‘ro’)
plt.axis(‘scaled’)
# ax.set_xlim(-4, 4)
# ax.set_ylim(-4, 4)
plt.axis(‘equal’) #changes limits of x or y axis so that equal increments of x and y have the same length
plt.show()
你可以試試,謝謝。
等一個大佬啊 要求用python創建一個窗口,窗口按鈕功能是創建一個球體或立方體。明天上課之前交給我
下面的代碼是創建一個立方體
”’
This examples creates and displays a simple box.
”’
# The first line loads the init_display function, necessary to
# enable the builtin simple gui provided with pythonocc
from OCC.Display.SimpleGui import init_display
# Then we import the class that instanciates a box
# Here the BRepPrimAPI module means Boundary Representation Primitive API.
# It provides an API for creation of basic geometries like spheres,cones etc
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox
# Following line initializes the display
# By default, the init_display function looks for a Qt based Gui (PyQt, PySide)
display, start_display, add_menu, add_function_to_menu = init_display()
# The BRepPrimAPI_MakeBox class is initialized with the 3 parameters of the box: widht, height, depth
my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()
# Then the box shape is sent to the renderer
display.DisplayShape(my_box, update=True)
# At last, we enter the gui mainloop
start_display()
創建頁面
#coding:utf8
import wx
app = wx.App() #創建對象
win = wx.Frame(None,title=”ahuang1900″, size=(410,340)) #創建窗口對象
wx.Button(win, label=”open”, pos = (245,5), size=(80,25)) #創建按鈕1
wx.Button(win, label=”save”, pos = (325,5), size=(80,25)) #創建按鈕2
wx.TextCtrl(win, pos=(5,5), size=(240,25)) #創建文本框1
#創建文本框2
wx.TextCtrl(win, pos=(5,35), size=(400,300), style=wx.TE_MULTILINE|wx.HSCROLL)
win.Show() #顯示
app.MainLoop() #主事件循環
python編寫 球體,我可以借鑒哪些東西?
Matplotlib模塊應該能夠畫出來,具體你去查看一下官方文檔。三維圖形繪製裡面應該有的,至少有相似的操作。
Python程序開發之簡單小程序實例(11)小遊戲-跳動的小球
Python程序開發之簡單小程序實例
(11)小 遊戲 -跳動的小球
一、項目功能
用戶控制擋板來阻擋跳動的小球。
二、項目分析
根據項目功能自定義兩個類,一個用於控制小球在窗體中的運動,一個用於接收用戶按下左右鍵時,擋板在窗體中的運動。在控制小球的類中,我們還需要考慮當小球下降時,碰到擋板時的位置判斷。
三、程序源代碼
源碼部分截圖:
源碼:
#!/usr/bin/python3.6
# -*- coding: GBK -*-
#導入相應模塊
from tkinter import *
import random
import time
#自定義小球的類 Ball
class Ball:
# 初始化
def __init__(self,canvas,paddle,color):
#傳遞畫布值
self.canvas=canvas
#傳遞擋板值
self.paddle=paddle
#畫圓並且保存其ID
self.id=canvas.create_oval(10,10,25,25,fill=color)
self.canvas.move(self.id,245,100)
#小球的水平位置起始列表
start=[-3,-2,-1,1,2,3]
#隨機化位置列表
random.shuffle(start)
self.x=start[0]
self.y=-2
self.canvas_heigh=self.canvas.winfo_height()#獲取窗口高度並保存
self.canvas_width=self.canvas.winfo_width()
#根據參數值繪製小球
def draw(self):
self.canvas.move(self.id,self.x,self.y)
pos=self.canvas.coords(self.id)#返回相應ID代表的圖形的當前坐標(左上角和右上角坐標)
#使得小球不會超出窗口
pad=self.canvas.coords(self.paddle.id)#獲取小球擋板的坐標
if pos[1]=self.canvas_heigh or(pos[3]=pad[1] and pos[2]=pad[0] and pos[2]
c4d怎麼用python畫三維圖
要以Python生成器為媒介。
用以下代碼可以簡單行程一個三維圖,在這個基礎上根據您的需要改寫代碼就可以了。
在生成器內的python代碼會生成一個object。默認下,生成了一個立方體,並返回:
import c4d
def main():
return c4d.BaseObject(c4d.Ocube)
UserData輸入
當然也可以返回別的物體,或者用userdata調整物體參數。注意op可以快速引用生成器對象。
importc4d
defmain():
cone =c4d.BaseObject(c4d.Ocone)
cone[c4d.PRIM_CONE_TRAD] = op[c4d.ID_USERDATA,1]
return cone
具體創建三維圖步驟如下
1首先要【創建】-【造型】-【python生成器】,默認生成一個立方體即python編輯器
2-選中對象,右下角【打開python編輯器】
3-代碼表示定義一個函數並返回C4D基本物體
4-這裡簡單改一下,把原代碼中的Ocube改成Osphere,點一下執行,會生成一個三維球體。對於基本造型對象,這裡的對象名稱通用語法為大寫字母O加對象的英文。
5-這裡還可以用定義變數返回值的表達方法,比如這裡定義變數cone(圓錐),c4d的屬性就是大寫字母O加上圓錐的英文即Ocone,返回這個變數值,執行就得到了一個圓錐。
6-除了生成基本三維圖形,python編輯器可以做很多事情,這裡如果有一定的python編碼基礎,會更容易一些。可以在網上找幾個實例試一下,比如這種,生成數字的。可以在搜索引擎輸入關鍵字Cinema 4D – Python scripts來檢索別人寫好的腳本。
原創文章,作者:KMTX4,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/129915.html