如何从头开始创建实时渲染窗口?(How do I create a real-time rendering window from scratch?)
我已经在自己研究3D图形了一段时间了,我希望能够更好地理解一切是如何工作的。 我想做的是在不使用DirectX或OpenGL的情况下创建一个简单的游戏。 我理解我相信的大部分数学,但我遇到的问题是我不知道如何控制窗口中显示的像素。
如何在窗口中指定每个像素的颜色?
我知道我可能会遇到缓冲区和图像剪切以及可能是非常糟糕的效率问题,但我想创建自己的程序,以便从最低级别的高级语言中看到渲染过程的工作原理。 我真的不知道从哪里开始。 我已经想出了如何输出BMP,但我希望有一个正在运行的程序每秒吐出20多帧。 我该如何做到这一点?
I've been studying 3D graphics on my own for a while now and I want to get a greater understanding of just how everything works. What I would like to do is to create a simple game without using DirectX or OpenGL. I understand most of the math I believe, but the problem I am running up against is I do not know how to get control of the pixels being displayed in a window.
How do I specify what color I want each pixel in my window to be?
I understand I will probably run into issues with buffers and image shearing and probably terrible efficiency problems, but I want to create my own program so that I could see from the very lowest level, of the high level language, how the rendering process works. I really have no idea where to start though. I've figured out how to output BMPs, but I would like to have a running program spitting out 20+ frames per second. How do I accomplish this?
原文:https://stackoverflow.com/questions/8977728
最满意答案
您可以使用:
#convert if dtype not datetime df.Date = pd.to_datetime(df.Date) #create index from column Date df = df.set_index('Date') #convert all times to timedelta df.columns = pd.to_timedelta(df.columns + ':00', unit='h') #reshape - columns to second level of index df = df.stack() #Multindex to index df.index = df.index.get_level_values(0) + df.index.get_level_values(1) #create column from index df = df.reset_index() #get new column names df.columns = ['date','val'] print (df) date val 0 2004-05-01 00:15:00 3.74618 1 2004-05-01 00:30:00 3.58507 2 2004-05-01 00:45:00 3.30998 3 2004-05-01 23:15:00 2.97236 4 2004-05-01 23:30:00 2.92008 5 2004-05-01 23:45:00 2.80101 6 2004-05-02 00:00:00 2.60670 7 2004-05-02 00:15:00 3.09098 8 2004-05-02 00:30:00 3.84625 9 2004-05-02 00:45:00 3.54672 10 2004-05-02 23:15:00 2.83725 11 2004-05-02 23:30:00 2.93876 12 2004-05-02 23:45:00 2.82762 13 2004-05-03 00:00:00 2.62550
You can use:
#convert if dtype not datetime df.Date = pd.to_datetime(df.Date) #create index from column Date df = df.set_index('Date') #convert all times to timedelta df.columns = pd.to_timedelta(df.columns + ':00', unit='h') #reshape - columns to second level of index df = df.stack() #Multindex to index df.index = df.index.get_level_values(0) + df.index.get_level_values(1) #create column from index df = df.reset_index() #get new column names df.columns = ['date','val'] print (df) date val 0 2004-05-01 00:15:00 3.74618 1 2004-05-01 00:30:00 3.58507 2 2004-05-01 00:45:00 3.30998 3 2004-05-01 23:15:00 2.97236 4 2004-05-01 23:30:00 2.92008 5 2004-05-01 23:45:00 2.80101 6 2004-05-02 00:00:00 2.60670 7 2004-05-02 00:15:00 3.09098 8 2004-05-02 00:30:00 3.84625 9 2004-05-02 00:45:00 3.54672 10 2004-05-02 23:15:00 2.83725 11 2004-05-02 23:30:00 2.93876 12 2004-05-02 23:45:00 2.82762 13 2004-05-03 00:00:00 2.62550
相关问答
更多-
在Pandas中按时间顺序合并日期上的DataFrame(Merging DataFrames on dates in chronological order in Pandas)[2023-10-27]
您需要做的就是在所有示例数据帧上使用pd.concat 。 但你必须设置一些东西。 一,将每个索引的索引设置为要合并的列。 确保该列是日期列。 以下是如何操作的示例。 一个班轮 pd.concat([s.set_index('Unnamed: 0') for s in [sample1, sample2]], axis=1).rename_axis('Unnamed: 0').reset_index() Unnamed: 0 sample_1 sample_2 0 2004/04/27 ... -
我相信这会奏效: df.groupby(['product', (df.start_ts != df.end_ts.shift()).cumsum()], \ as_index=False).agg({'start_ts':min, 'end_ts':max, 'value':sum}) # product end_ts start_ts value # 0 a 2018-05-14 12:54:33 2018-05- ...
-
熊猫将行元素合二为一(Pandas combine row element in one)[2021-09-15]
这是一个例子。 它添加了一个新列,其中每个条目都是另外两列的列表。 我希望它有所帮助! df= pd.DataFrame(np.random.randn(10,4)) df[4]= [[df[2][x],df[3][x]] for x in range(df.shape[0])] Here is an example. It adds a new column where each entry is the list of two other columns. I hope it helps! df= p ... -
强化错误和dropna即: dates['Date'] = pd.to_datetime(dates['Date'],errors='coerce') dates.dropna(inplace=True) Coerce the errors and dropna i.e: dates['Date'] = pd.to_datetime(dates['Date'],errors='coerce') dates.dropna(inplace=True)
-
将日期和时间从Excel拉到Pandas并将其与时间戳相结合(Pulling date and time from Excel to Pandas and combining it to a timestamp)[2021-07-03]
一种方法是将时间字符串转换为datetime但只占用时间部分,然后调用apply并调用datetime.combine来生成两列的日期时间: In [61]: df['OEtime'] = pd.to_datetime(df['OEUhrzeit']).dt.time df['OEDatum'] = df[['OEDatum','OEtime']].apply(lambda x: dt.datetime.combine(x['OEDatum'].date(),x['OEtime']), axis=1 ... -
不确定我是否完全承认你的要求,但做这样的工作?: df_contract['TOTAL_YEARS'] = (df_contract['END_DATE'] - df_contract['START_DATE'] )/np.timedelta64(1,'Y') df_contract['TOTAL_YEARS'][(df['CANCEL_FLAG'] == 1) && (df['TOTAL_YEARS'] > 1)] = 1 After a lo ...
-
我有点不愿回答b / c似乎@chrisb可能已经成功回答了原来的问题,后来改变了。 但是,Chris几天之内没有更新答案,这个答案确实采用了不同的方法,所以我要给Chris的答案+1并加上这个答案。 首先,只需使用'index'='date2'从原始数据框创建一个新的数据框。 这将是附加到现有数据框的基础(请注意,'index'是此处的列,而不是索引): df2 = df[ df['index'] != df['date2'] ] df2['index'] = df2['date2'] df2['valu ...
-
以特定的优先顺序将pandas列合并到新列中(Combine pandas column into new column in certain order of preference)[2022-05-27]
用bfill解决方法与bfill相同, method='bfill' df['D'] = df.bfill(axis=1).iloc[:, 0] print (df) A B C D 0 alpha alpha_1 NaN alpha 1 beta NaN beta_2 beta 2 NaN NaN gamma_2 gamma_2 3 NaN delta_1 delta_2 ... -
您可以使用: #convert if dtype not datetime df.Date = pd.to_datetime(df.Date) #create index from column Date df = df.set_index('Date') #convert all times to timedelta df.columns = pd.to_timedelta(df.columns + ':00', unit='h') #reshape - columns to second level o ...
-
split,groupby,在Pandas中结合以找到日期的差异(split, groupby, combine in Pandas to find a difference in dates)[2023-10-03]
你可以像这样使用apply: earliest_by_id = DF.groupby('id')['date'].min() def since_earliest(row): return row.date - earliest_by_id[row.id] DF['days_since_earliest'] = DF.apply(since_earliest, axis=1) print(DF) id date days_since_earliest 0 1 2015-0 ...