-
Notifications
You must be signed in to change notification settings - Fork 926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Visualization changes #1278
Open
GaelLucero
wants to merge
9
commits into
projectmesa:main
Choose a base branch
from
aiwhoo-parks:visualization_changes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Visualization changes #1278
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fce4a85
adding heading information and created setxy function which sets the …
aiwhoo 1e4e46f
created distancexy function, which gives you the distance of the agen…
GaelLucero ed6921f
Created forward_backward function, which calculates the next position…
GaelLucero 6a939f5
Created die function, which removes the agent from the schedule and t…
GaelLucero 8bc5b50
Created face, facexy, towards, towardsxy,and random random choice fun…
BryanHRojas 9f6587d
Updating die function and forward_backward function to consider error…
GaelLucero d66924f
Created face, facexy, towards, towardsxy,and random random choice fun…
BryanHRojas 0858679
removed repeated functions.
BryanHRojas 8a2b3fe
Updating function names per comments in pull request #1278. Adding ba…
GaelLucero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from mesa.visualization.ModularVisualization import VisualizationElement | ||
|
||
|
||
class SimpleCanvas(VisualizationElement): | ||
local_includes = ["simple_continuous_canvas.js"] | ||
portrayal_method = None | ||
canvas_height = 500 | ||
canvas_width = 500 | ||
|
||
def __init__(self, portrayal_method, canvas_height=500, canvas_width=500, background_src=None): | ||
""" | ||
Instantiate a new SimpleCanvas | ||
""" | ||
self.portrayal_method = portrayal_method | ||
self.canvas_height = canvas_height | ||
self.canvas_width = canvas_width | ||
self.background_src = background_src | ||
new_element = "new Simple_Continuous_Module({}, {}, {})".format( | ||
self.canvas_width, self.canvas_height, "'" + self.background_src + "'" if self.background_src != None else "null" | ||
) | ||
self.js_code = "elements.push(" + new_element + ");" | ||
|
||
def render(self, model): | ||
space_state = [] | ||
for obj in model.schedule.agents: | ||
portrayal = self.portrayal_method(obj) | ||
x, y = obj.pos | ||
x = (x - model.space.x_min) / (model.space.x_max - model.space.x_min) | ||
y = (y - model.space.y_min) / (model.space.y_max - model.space.y_min) | ||
portrayal["x"] = x | ||
portrayal["y"] = y | ||
portrayal["heading"] = obj.heading | ||
space_state.append(portrayal) | ||
return space_state |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
set_position(self, position)
? This way, the API remains the same in the implementation with higher number of dimensions, instead of e.g.set_xyz
for 3D.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setxy
needs to be removed now that we haveset_pos
.