Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python grafikk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Leo Moe
python grafikk
Commits
f7071c45
Commit
f7071c45
authored
1 year ago
by
Leo Moe
Browse files
Options
Downloads
Patches
Plain Diff
spawns random circles
parent
e182adfc
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
run.py
+44
-3
44 additions, 3 deletions
run.py
with
44 additions
and
3 deletions
run.py
+
44
−
3
View file @
f7071c45
import
pygame
as
pg
import
pygame
as
pg
import
numpy
as
np
from
random
import
randint
def
randomColor
()
->
tuple
[
int
]:
return
(
randint
(
0
,
256
),
randint
(
0
,
256
),
randint
(
0
,
256
))
def
random2DPointOnScreen
(
screen
:
pg
.
Surface
)
->
tuple
:
tup
=
screen
.
get_size
()
xCoord
=
int
(
np
.
random
.
uniform
()
*
tup
[
0
])
#I want the position on the screen to be random.
yCoord
=
int
(
np
.
random
.
uniform
()
*
tup
[
1
])
return
(
xCoord
,
yCoord
)
#I imagine that there are some advantages with having it as a tuple.
def
randomCircleSize
():
return
30
+
10
*
np
.
random
.
normal
()
#I want the radius to be centered around 30 with some spread.
#This isnt controlling that I may make circles with negative sizes.
#This is not common because it is 3 standard deviations out of normal,
#but I may have to find a better distribution that doesnt create negatives, like the poisson.
def
drawCircleOnScreen
(
screen
:
pg
.
Surface
)
->
None
:
pg
.
draw
.
circle
(
screen
,
randomColor
(),
random2DPointOnScreen
(
screen
),
randomCircleSize
())
def
run
():
def
run
():
pg
.
init
()
pg
.
init
()
screen
=
pg
.
display
.
set_mode
((
400
,
400
))
clock
=
pg
.
time
.
Clock
()
screen
=
pg
.
display
.
set_mode
((
400
,
400
))
#The first number is left-right and the second is up-down.
done
=
False
done
=
False
while
not
done
:
while
not
done
:
for
event
in
pg
.
event
.
get
():
for
event
in
pg
.
event
.
get
():
if
event
.
type
==
pg
.
QUIT
:
if
event
.
type
==
pg
.
QUIT
:
done
=
True
done
=
True
pg
.
display
.
flip
()
if
event
.
type
==
pg
.
KEYDOWN
:
dealWithPressed
(
event
)
#print(event.key) I am not using this one.
drawCircleOnScreen
(
screen
)
#get the radius in here.
pg
.
display
.
update
()
clock
.
tick
(
5
)
def
dealWithPressed
(
event
):
if
event
.
key
==
pg
.
K_LEFT
:
print
(
"
hi
"
)
if
event
.
key
==
pg
.
K_RIGHT
:
print
(
"
howdi
"
)
run
()
run
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment