create account

Very Simple Random Pixelated Planet Generation by zealouscoder

View this thread on: hive.blogpeakd.comecency.com
· @zealouscoder ·
$6.36
Very Simple Random Pixelated Planet Generation
![1529503346.png](https://cdn.steemitimages.com/DQmZ5RCPUEefyVnGdihrZuWTuXHGq55H3kwmUYkP68sdGNU/1529503346.png)

Above is a screenshot from my game **Amber Sol**, currently in development. You can try the latest demo version out by downloading it from the projects [itch page](https://anorstudios.itch.io/amber-game-project).

The above planet is generated with filled cells each being drawn every frame using a random seed value which is also derived based on a master seed and the location of the cell. So given the same master seed and the location the same planet image will be generated. This is a really cool property of pseudo-random number generators. It is also a really useful technique used to create large unique but reproducible worlds.

Pseudo-Random Number Generators...
===

So pseudo-random number generators use __seed values__ to derive a unique list of numbers with an even distribution. 

Meaning the order will be unique but you will also see each number close to the same number of times. This means that we have some predictability to the sequence as well as reproducibility, which is really cool.

Effects of seed values
---
In other words, if I use one of these pseudo random number generators to generate a random number between 1 and 10 with a specific seed value. I will get the same sequence with that seed each run of the program. Or each time I reset the seed value for that generator. 

In the solitaire game that I wrote [_available on itch and android_](https://anorstudios.itch.io/simply-solitaire) I save games simply by saving the seed value used to shuffle the cards. As well as every move you made since you started. Those moves are then used when loading a game to get you back to the state you were in when you left the game. This minimizes the game saves. Is very quick to save and reload. And provides a way to undo all moves you've ever made even after loading an old save. 

Even distribution
---
If I generate 10,000 integers I will get each of the ten numbers approximately the same number of times. One thing that you want to do in many games is give something a chance to happen. Maybe it's dice roles or whether a monster attacks you or not. You can apply chance to these generators pretty easily, by picking x in y chances. 

Writing a chance function
---
So you can write a simple chance function knowing that every number in any sequence will occur a similar number of times. Say you want 1 in 5 odds that a statement is true. Have your generator generate numbers between 1 and 5 pick a number lets just say 1. If the number is 1 then the statement is true. And the function will return true approximately once for every five generations. But depending on the sequence it could happen at seemingly random intervals.

Here is an example of a chance function. For the [Love2D engine](https://love2d.org/) which is what I am writing my games in:

```Lua
function chance(once, everyn)
  return love.math.random(1,everyn) == once
end
```

We can write this in just plain lua using the `math.random` function instead by just removing the `love.` part.

Here is what happens if we add a random amount of green to each cell with a 1 in five chance for a cell to contain green if the planet is gray.

![1529515941.png](https://cdn.steemitimages.com/DQmNbiMqH4fq85HTRcyTg3V6Nzre5GACqyZWFkWmD1ViAZB/1529515941.png)

So each cell has a 1 in 5 chance of being randomly some amount of green. In the future I hope to add multiple types of random features to each planet making them more distinguishable and unique. Things like lakes, and rivers, mountains. Volcano etc.

Here is another one I added.

![1529516095.png](https://cdn.steemitimages.com/DQmWtKo9wpUYYc5f97kcVXe5zRQepuc37D976Y8jP8cesEv/1529516095.png)

_P.S. The green rectangle is where enemy ships appear orbiting the planet that you need to eliminate in the game._
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 40 others
properties (23)
authorzealouscoder
permlinkvery-simple-random-pixelated-planet-generation
categorygamedev
json_metadata{"tags":["gamedev","gaming","technology","steemstem","programming"],"image":["https://cdn.steemitimages.com/DQmZ5RCPUEefyVnGdihrZuWTuXHGq55H3kwmUYkP68sdGNU/1529503346.png","https://cdn.steemitimages.com/DQmNbiMqH4fq85HTRcyTg3V6Nzre5GACqyZWFkWmD1ViAZB/1529515941.png","https://cdn.steemitimages.com/DQmWtKo9wpUYYc5f97kcVXe5zRQepuc37D976Y8jP8cesEv/1529516095.png"],"links":["https://anorstudios.itch.io/amber-game-project","https://anorstudios.itch.io/simply-solitaire","https://love2d.org/"],"app":"steemit/0.1","format":"markdown"}
created2018-06-20 19:48:09
last_update2018-06-20 19:48:09
depth0
children3
last_payout2018-06-27 19:48:09
cashout_time1969-12-31 23:59:59
total_payout_value4.806 HBD
curator_payout_value1.549 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,867
author_reputation109,466,698,511
root_title"Very Simple Random Pixelated Planet Generation"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id61,538,375
net_rshares3,105,957,737,914
author_curate_reward""
vote details (104)
@a-0-0-0 ·
Upvote this for me please? https://steemit.com/christianity/@bible.com/verse-of-the-day-hebrews-4-16-nlt
properties (22)
authora-0-0-0
permlinkre-zealouscoder-very-simple-random-pixelated-planet-generation-20180620t194842499z
categorygamedev
json_metadata{"tags":["gamedev"],"links":["https://steemit.com/christianity/@bible.com/verse-of-the-day-hebrews-4-16-nlt"],"app":"steemit/0.1"}
created2018-06-20 19:48:45
last_update2018-06-20 19:48:45
depth1
children0
last_payout2018-06-27 19:48:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length104
author_reputation-846,595,185,511
root_title"Very Simple Random Pixelated Planet Generation"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id61,538,440
net_rshares0
@dalz ·
Pixelated ... never go out of style :) I see you have quite a method to genrate this... appreciated.
👍  
properties (23)
authordalz
permlinkre-zealouscoder-very-simple-random-pixelated-planet-generation-20180621t065540036z
categorygamedev
json_metadata{"tags":["gamedev"],"app":"steemit/0.1"}
created2018-06-21 06:55:39
last_update2018-06-21 06:55:39
depth1
children0
last_payout2018-06-28 06:55:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length100
author_reputation1,923,327,531,356,790
root_title"Very Simple Random Pixelated Planet Generation"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id61,599,612
net_rshares126,721,883
author_curate_reward""
vote details (1)
@utopian-io ·
#### Hi @zealouscoder!

Your post was upvoted by utopian.io in cooperation with steemstem - supporting knowledge, innovation and technological advancement on the Steem Blockchain.

#### Contribute to Open Source with utopian.io
Learn how to contribute on <a href="https://join.utopian.io">our website</a> and join the new open source economy.

**Want to chat? Join the Utopian Community on Discord https://discord.gg/h52nFrV**
properties (22)
authorutopian-io
permlink20180621t024503273z
categorygamedev
json_metadata{"tags":["utopian.tip"],"app":"utopian-io"}
created2018-06-21 02:45:03
last_update2018-06-21 02:45:03
depth1
children0
last_payout2018-06-28 02:45:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length426
author_reputation152,955,367,999,756
root_title"Very Simple Random Pixelated Planet Generation"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id61,576,182
net_rshares0