hey,
I just know that this will have a simple solution, I just can’t figure it out.
I have a function that generates random points generate
; the idea is to generate points and display them on the canvas. Without the never ending loop of generating new points every time draw() runs . I did try noLoop()
, but the result is not what I want, it just halts everything and I’ll need to call loop()
again at some point…and I am back to the never ending loop.
I am passing the points to ellipse
through a loop in draw()
, is there a way to stop the loop from destroying my frame rate and just display the random points created by generate()
import random as rn
import math
width = 600
height = 600
xl, yl = width, height
groupSize = 10000 #change this,
time = 0
def distance(x, y, x1, y1):
distance = math.sqrt(((x2 - x1) ** 2) + ((y2 - y1)**2))
return distance
def pointFunction(xl, yl):
x = rn.uniform(0, xl)
y = rn.uniform(0, yl)
return x, y
def generate(groupSize, xl, yl):
groupDict = {}
for i in range(groupSize):
x, y = pointFunction(xl, yl)
groupDict[i] = {
'xValue': x,
'yValue': y,
'status': 0 # 0 = normal, 1 = infected, 2 = in hospital, 3 = cured, 4 = dead
}
# noLoop()
return groupDict
def prepareData():
sampleValues = generate(groupSize, xl, yl)
for i in range(len(sampleValues)):
x = sampleValues[i]['xValue']
y = sampleValues[i]['yValue']
status = sampleValues[i]['status']
return x, y, status
def setup():
size(width,height)
noStroke()
def draw():
global time
sampleValues = generate(groupSize, xl, yl)
# print sampleValues
background(0)
stroke(255)
fill(255, 155, 100)
x = 0
y = 0
for i in range(len(sampleValues)):
# oldX = float(x)
# oldY = float(y)
x = sampleValues[i]['xValue']
y = sampleValues[i]['yValue']
status = sampleValues[i]['status']
# ellipse(oldX, oldY, 5,5)
ellipse(x, y, 2, 2)