Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Natural Selection Simulator Python
A graphical natural selection simulation.

##To Run
## To Run
Execute the file natural_selection.py.

##Credit
## Credit
graphics.py is an open source library written by John Zelle and licensed under the terms of the
GPL (http://www.gnu.org/licenses/gpl.html).

## Condtibutions

- Release of 15/01/2021 by Kristian Harge
Reorganization on sub folders, added reproduction on omnivores and carnivores,
added energy consumption relative to size
Binary file added __pycache__/analyse.cpython-36.pyc
Binary file not shown.
Binary file added __pycache__/analyse.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/configuration.cpython-36.pyc
Binary file not shown.
Binary file added __pycache__/configuration.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/graphics.cpython-36.pyc
Binary file not shown.
Binary file added __pycache__/graphics.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/organism.cpython-36.pyc
Binary file not shown.
Binary file added __pycache__/organism.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/organisms.cpython-36.pyc
Binary file not shown.
Binary file added __pycache__/organisms.cpython-38.pyc
Binary file not shown.
37 changes: 37 additions & 0 deletions analyse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import numpy as np
import matplotlib.pyplot as plt

figure = None
plot = None

def plotValues(Organisms):
'''This function plots the interesting values of the organisms
'''
global figure
global plot
speeds = []
sizes = []

if figure != None:

for Organism in Organisms:
speeds.append(Organism.speed)
sizes.append(Organism.size)

plot.set_ydata(sizes)
plot.set_xdata(speeds)


else:

plt.ion()
figure = plt.figure()

for Organism in Organisms:
speeds.append(Organism.speed)
sizes.append(Organism.size)

plot, = figure.add_subplot(1, 1, 1).plot(speeds, sizes, 'b*')
plt.title("Living organisms attributes")
plt.xlabel("Speed")
plt.ylabel("Size")
8 changes: 8 additions & 0 deletions configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Simulation configuration
windowSize = 100
tickTime = .5
gameTicks = 200
eventLog = False
speedFactor = 1
loop = False
energyFactor = 0.0001
Binary file added configuration.pyc
Binary file not shown.
14 changes: 0 additions & 14 deletions graphics.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
# graphics.py
"""Simple object oriented graphics library

The library is designed to make it very easy for novice programmers to
experiment with computer graphics in an object oriented fashion. It is
written by John Zelle for use with the book "Python Programming: An
Introduction to Computer Science" (Franklin, Beedle & Associates).

LICENSE: This is open-source software released under the terms of the
GPL (http://www.gnu.org/licenses/gpl.html).

PLATFORMS: The package is a wrapper around Tkinter and should run on
any platform where Tkinter is available.

INSTALLATION: Put this file somewhere where Python can see it.

OVERVIEW: There are two kinds of objects in the library. The GraphWin
class implements a window where drawing can be done and various
GraphicsObjects are provided that can be drawn into a GraphWin. As a
simple example, here is a complete program to draw a circle of radius
10 centered in a 100x100 window:

--------------------------------------------------------------------
from graphics import *

def main():
win = GraphWin("My Circle", 100, 100)
c = Circle(Point(50,50), 10)
c.draw(win)
win.getMouse() # Pause to view result
win.close() # Close window when done

main()
--------------------------------------------------------------------
GraphWin objects support coordinate transformation through the
setCoords method and mouse and keyboard interaction methods.

The library provides the following graphical objects:
Point
Line
Expand All @@ -45,16 +36,13 @@ def main():
Text
Entry (for text-based input)
Image

Various attributes of graphical objects can be set such as
outline-color, fill-color and line-width. Graphical objects also
support moving and hiding for animation effects.

The library also provides a very simple class for pixel-based image
manipulation, Pixmap. A pixmap can be loaded from a file and displayed
using an Image object. Both getPixel and setPixel methods are provided
for manipulating the image.

DOCUMENTATION: For complete documentation, see Chapter 4 of "Python
Programming: An Introduction to Computer Science" by John Zelle,
published by Franklin, Beedle & Associates. Also see
Expand Down Expand Up @@ -927,7 +915,6 @@ def getHeight(self):
def getPixel(self, x, y):
"""Returns a list [r,g,b] with the RGB color values for pixel (x,y)
r,g,b are in range(256)

"""

value = self.img.get(x,y)
Expand All @@ -948,7 +935,6 @@ def setPixel(self, x, y, color):
def save(self, filename):
"""Saves the pixmap image to filename.
The format for the save image is determined from the filname extension.

"""

path, name = os.path.split(filename)
Expand Down
Binary file added graphics.pyc
Binary file not shown.
Loading