Plotting terrain pixels with PyGame based on random NumPy arrayTerrain generator in a PyGame gameSimCity clone with PyGameK-Mean with NumpySouped-up random walk terrain generatorNumPy array filter optimisationComparing pixels against RGB value in NumPySlicing a big NumPy arrayKoch snowflake in Python with numpy and pygameGet list of surrounding pixels of a pixel in pygameChecking surrounding pixels inefficiently in pygame
Aluminum electrolytic or ceramic capacitors for linear regulator input and output?
Why is a white electrical wire connected to 2 black wires?
What is the adequate fee for a reveal operation?
I am confused as to how the inverse of a certain function is found.
Why Choose Less Effective Armour Types?
Is there a hypothetical scenario that would make Earth uninhabitable for humans, but not for (the majority of) other animals?
Is "upgrade" the right word to use in this context?
How do you talk to someone whose loved one is dying?
Book about superhumans hiding among normal humans
Is honey really a supersaturated solution? Does heating to un-crystalize redissolve it or melt it?
Meme-controlled people
What is the significance behind "40 days" that often appears in the Bible?
My adviser wants to be the first author
What is "focus distance lower/upper" and how is it different from depth of field?
If I can solve Sudoku, can I solve the Travelling Salesman Problem (TSP)? If so, how?
Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?
How do I hide Chekhov's Gun?
Examples of transfinite towers
Is it insecure to send a password in a `curl` command?
Did Ender ever learn that he killed Stilson and/or Bonzo?
Bacteria contamination inside a thermos bottle
New passport but visa is in old (lost) passport
Welcoming 2019 Pi day: How to draw the letter π?
Python if-else code style for reduced code for rounding floats
Plotting terrain pixels with PyGame based on random NumPy array
Terrain generator in a PyGame gameSimCity clone with PyGameK-Mean with NumpySouped-up random walk terrain generatorNumPy array filter optimisationComparing pixels against RGB value in NumPySlicing a big NumPy arrayKoch snowflake in Python with numpy and pygameGet list of surrounding pixels of a pixel in pygameChecking surrounding pixels inefficiently in pygame
$begingroup$
I am experimenting with Perlin Noise and random map generation. I have a 2D numpy ndarray full of 16-bit floats called map_list
that I call from the singleton ST
. It has 900 rows with 1600 elements each. I am iterating through it to display different colored pixels to represent terrain at different points in the map. Array values in different ranges produce pixels of different colors. The total possible range is [0, 1] because I am normalizing the values.
My question is, is there a way to do this faster than I am capable of now?
"""
This file holds functions that modify pyGame surfaces.
"""
from __future__ import division
from singleton import ST
from pygame import gfxdraw
def display_map(surface):
"""
This takes in a pyGame surface, and draws colored tiles on it according to
the values in ST.map_list. The higher the value, the lighter the shade of
the tile.
:param surface: A pyGame surface.
"""
x_pos = 0
y_pos = 0
for y in range(len(ST.map_list)):
for x in range(len(ST.map_list[y])):
noise_value = ST.map_list[y][x]
shade = int(noise_value * 255)
color = __color_tiles(noise_value, shade)
gfxdraw.pixel(surface, x_pos, y_pos, color)
x_pos += ST.TILE_SIZE
x_pos = 0
y_pos += ST.TILE_SIZE
def __color_tiles(noise_value, shade):
"""
Treat this function as private. It should only be called by functions and
methods within this file. It returns a 3-element 1D tuple that represents
the rgb color values to display the tile as.
:param noise_value: The noise value at a specific point in ST.map_list.
:param shade: How dark or light the tile should be.
:return: tuple
"""
if noise_value < ST.WATER_LEVEL:
rgb = (shade, shade, 255)
elif noise_value > ST.MOUNTAIN_LEVEL:
rgb = (shade, shade, shade)
else:
rgb = (shade, 255, shade)
return rgb
What it generates
python performance python-2.x numpy pygame
$endgroup$
add a comment |
$begingroup$
I am experimenting with Perlin Noise and random map generation. I have a 2D numpy ndarray full of 16-bit floats called map_list
that I call from the singleton ST
. It has 900 rows with 1600 elements each. I am iterating through it to display different colored pixels to represent terrain at different points in the map. Array values in different ranges produce pixels of different colors. The total possible range is [0, 1] because I am normalizing the values.
My question is, is there a way to do this faster than I am capable of now?
"""
This file holds functions that modify pyGame surfaces.
"""
from __future__ import division
from singleton import ST
from pygame import gfxdraw
def display_map(surface):
"""
This takes in a pyGame surface, and draws colored tiles on it according to
the values in ST.map_list. The higher the value, the lighter the shade of
the tile.
:param surface: A pyGame surface.
"""
x_pos = 0
y_pos = 0
for y in range(len(ST.map_list)):
for x in range(len(ST.map_list[y])):
noise_value = ST.map_list[y][x]
shade = int(noise_value * 255)
color = __color_tiles(noise_value, shade)
gfxdraw.pixel(surface, x_pos, y_pos, color)
x_pos += ST.TILE_SIZE
x_pos = 0
y_pos += ST.TILE_SIZE
def __color_tiles(noise_value, shade):
"""
Treat this function as private. It should only be called by functions and
methods within this file. It returns a 3-element 1D tuple that represents
the rgb color values to display the tile as.
:param noise_value: The noise value at a specific point in ST.map_list.
:param shade: How dark or light the tile should be.
:return: tuple
"""
if noise_value < ST.WATER_LEVEL:
rgb = (shade, shade, 255)
elif noise_value > ST.MOUNTAIN_LEVEL:
rgb = (shade, shade, shade)
else:
rgb = (shade, 255, shade)
return rgb
What it generates
python performance python-2.x numpy pygame
$endgroup$
add a comment |
$begingroup$
I am experimenting with Perlin Noise and random map generation. I have a 2D numpy ndarray full of 16-bit floats called map_list
that I call from the singleton ST
. It has 900 rows with 1600 elements each. I am iterating through it to display different colored pixels to represent terrain at different points in the map. Array values in different ranges produce pixels of different colors. The total possible range is [0, 1] because I am normalizing the values.
My question is, is there a way to do this faster than I am capable of now?
"""
This file holds functions that modify pyGame surfaces.
"""
from __future__ import division
from singleton import ST
from pygame import gfxdraw
def display_map(surface):
"""
This takes in a pyGame surface, and draws colored tiles on it according to
the values in ST.map_list. The higher the value, the lighter the shade of
the tile.
:param surface: A pyGame surface.
"""
x_pos = 0
y_pos = 0
for y in range(len(ST.map_list)):
for x in range(len(ST.map_list[y])):
noise_value = ST.map_list[y][x]
shade = int(noise_value * 255)
color = __color_tiles(noise_value, shade)
gfxdraw.pixel(surface, x_pos, y_pos, color)
x_pos += ST.TILE_SIZE
x_pos = 0
y_pos += ST.TILE_SIZE
def __color_tiles(noise_value, shade):
"""
Treat this function as private. It should only be called by functions and
methods within this file. It returns a 3-element 1D tuple that represents
the rgb color values to display the tile as.
:param noise_value: The noise value at a specific point in ST.map_list.
:param shade: How dark or light the tile should be.
:return: tuple
"""
if noise_value < ST.WATER_LEVEL:
rgb = (shade, shade, 255)
elif noise_value > ST.MOUNTAIN_LEVEL:
rgb = (shade, shade, shade)
else:
rgb = (shade, 255, shade)
return rgb
What it generates
python performance python-2.x numpy pygame
$endgroup$
I am experimenting with Perlin Noise and random map generation. I have a 2D numpy ndarray full of 16-bit floats called map_list
that I call from the singleton ST
. It has 900 rows with 1600 elements each. I am iterating through it to display different colored pixels to represent terrain at different points in the map. Array values in different ranges produce pixels of different colors. The total possible range is [0, 1] because I am normalizing the values.
My question is, is there a way to do this faster than I am capable of now?
"""
This file holds functions that modify pyGame surfaces.
"""
from __future__ import division
from singleton import ST
from pygame import gfxdraw
def display_map(surface):
"""
This takes in a pyGame surface, and draws colored tiles on it according to
the values in ST.map_list. The higher the value, the lighter the shade of
the tile.
:param surface: A pyGame surface.
"""
x_pos = 0
y_pos = 0
for y in range(len(ST.map_list)):
for x in range(len(ST.map_list[y])):
noise_value = ST.map_list[y][x]
shade = int(noise_value * 255)
color = __color_tiles(noise_value, shade)
gfxdraw.pixel(surface, x_pos, y_pos, color)
x_pos += ST.TILE_SIZE
x_pos = 0
y_pos += ST.TILE_SIZE
def __color_tiles(noise_value, shade):
"""
Treat this function as private. It should only be called by functions and
methods within this file. It returns a 3-element 1D tuple that represents
the rgb color values to display the tile as.
:param noise_value: The noise value at a specific point in ST.map_list.
:param shade: How dark or light the tile should be.
:return: tuple
"""
if noise_value < ST.WATER_LEVEL:
rgb = (shade, shade, 255)
elif noise_value > ST.MOUNTAIN_LEVEL:
rgb = (shade, shade, shade)
else:
rgb = (shade, 255, shade)
return rgb
What it generates
python performance python-2.x numpy pygame
python performance python-2.x numpy pygame
edited 3 mins ago
200_success
130k17153419
130k17153419
asked 8 hours ago
LuminousNutriaLuminousNutria
1415
1415
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215575%2fplotting-terrain-pixels-with-pygame-based-on-random-numpy-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215575%2fplotting-terrain-pixels-with-pygame-based-on-random-numpy-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown