Ok, I modified some tutorial code to draw some parabolas and draw some data from a data file. This used to be the code that changed background colors with mouse button clicks. Anyway, I think it is continuously redrawing the scene, which I do not want because it is going through a lot of operations for the same picture and slowing my machine down. Is there a way that it will run once, then hold the image on the screen until i press q or esc?
import math
import Blender
from Blender.BGL import *
from Blender import Draw
R = G = B = 1.0
A = 1
title = "Testing BGL + Draw"
instructions = "Use mouse buttons or wheel to change the background color."
quitting = " Press ESC or q to quit."
len1 = Draw.GetStringWidth(title)
len2 = Draw.GetStringWidth(instructions + quitting)
#
def show_win():
glClearColor(R,G,B,A) # define color used to clear buffers
glClear(GL_COLOR_BUFFER_BIT) # use it to clear the color buffer
glColor3f(0,0,0) # define default color
for i in range(1000):
for j in range(1000):
y1 = (((i-500)**2)/(-150.0)) + 700
y2 = (((i-500)**2)/(-300.0)) + 850
if i<500:
y5 = 200*math.cos(6.28318530781*(i+150)/500)+200
else:
y5 = 200*math.sin(6.28318530781*(i-25)/500)+200
if ((j<y1 and j>y2) or (j > y1 and j <y2))and j>y5:
glBegin(GL_POLYGON)
glVertex2f(i/2.0-0.25, j/2.0-.25)
glVertex2f(i/2.0-0.25, j/2.0+.25)
glVertex2f(i/2.0+0.25, j/2.0+.25)
glVertex2f(i/2.0+0.25, j/2.0-.25)
glEnd()
glColor3f(.5,.5,.5)
for i in range(1000):
for j in range(1000):
y3 = (((i-500)**2)/(-200.0)) + 750
y4 = (((i-500)**2)/(-250.0)) + 800
if i<500:
y6 = 200*math.cos(6.28318530781*(i+150)/500)+225
else:
y6 = 200*math.sin(6.28318530781*(i-25)/500)+225
if ((j<y3 and j>y4) or (j>y3 and j<y4)) and j>y6:
glBegin(GL_POLYGON)
glVertex2f(i/2.0-0.25, j/2.0-0.25)
glVertex2f(i/2.0-0.25, j/2.0+0.25)
glVertex2f(i/2.0+0.25, j/2.0+0.25)
glVertex2f(i/2.0+0.25, j/2.0-0.25)
glEnd()
f=file('c:\documents and settings\sshumat\desktop\cppdata.txt','r')
f.seek(0)
str=f.readline()
temp=str.split()
numberdata=float(temp[0])
str=f.readline()
temp=str.split()
popmax=float(temp[0])
for i in range(numberdata):
str=f.readline()
temp=str.split()
x=float(temp[0])
y=float(temp[1])
pop=float(temp[2])
shade=(pop/(4*popmax)+0.75)
glColor3f(shade, shade, shade)
glBegin(GL_POLYGON)
glVertex2f(x/2.0-0.25, y/2.0-0.25)
glVertex2f(x/2.0-0.25, y/2.0+0.25)
glVertex2f(x/2.0+0.25, y/2.0+0.25)
glVertex2f(x/2.0+0.25, y/2.0-0.25)
glEnd()
def ev(evt, val): # event callback for Draw.Register()
global R,G,B,A # ... it handles input events
if evt == Draw.ESCKEY or evt == Draw.QKEY:
Draw.Exit() # this quits the script
Draw.Register(show_win, ev, None) # start the main loop