Skip to content

Commit 1fa2a5c

Browse files
committed
Planet Rotation
1 parent 2b40973 commit 1fa2a5c

5 files changed

Lines changed: 20 additions & 11 deletions

File tree

Planet.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -844,18 +844,19 @@ function rotate(original, degrees) {
844844
let width = original.width;
845845
let height = original.height;
846846

847-
var context = original.getContext('2d');
847+
var newImage = PImage.make(width, height);
848+
var context = newImage.getContext('2d');
848849

849850
var angle = degrees * Math.PI / 180;
850851

852+
context.clearRect(0,0,width,height);
851853
context.translate(width / 2, height / 2);
852854
context.rotate(angle);
853855
context.drawImage(original, -width / 2, -height / 2, width, height);
854-
context.fillRect(10,10,100,100);
855856
context.rotate(-angle);
856857
context.translate(-width, -height);
857858

858-
return original;
859+
return newImage;
859860
}
860861

861862
/*
@@ -869,5 +870,6 @@ module.exports = {
869870
generatePlanet: generatePlanet,
870871
generateStar: generateStar,
871872
getBuffer: getBuffer,
873+
rotate: rotate,
872874
save: save,
873875
}

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ const Planet = require("@stefftek/planet.js");
4040
*/
4141
let image = Planet.generatePlanet([...]);
4242

43+
/*
44+
Rotation
45+
*/
46+
image = Planet.rotate(image, 45 /*Degrees*/);
47+
4348
/*
4449
Export with PureImage
4550
*/

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "@stefftek/planet.js",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Generates 2D Pixelated Images of Planets",
55
"main": "Planet.js",
66
"author": "SteffTek",
77
"license": "Apache-2.0",
88
"dependencies": {
99
"perlin-noise": "^0.0.1",
10-
"pureimage": "^0.2.7",
10+
"pureimage": "^0.3.2",
1111
"seeded-perlin-noise": "git+https://github.com/aramperes/seeded-node-perlin-noise.git",
1212
"simplex-noise": "^2.4.0"
1313
},

test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let colors = {
1515
cloud_opacity: 70,
1616
atmosphere_color: "#4F7AAD",
1717
atmosphere_opacity: 70,
18-
shading_level: 2,
18+
shading_level: 0.9,
1919
add_detail: true,
2020
}
2121
let planet_options = {
@@ -100,4 +100,6 @@ let seed = "Clara";
100100
let image = Planet.generatePlanet(size, planet_options, colors, null, generator_options, cloud_generator);
101101
//let image = Planet.generateStar(size, sun_options, sun_colors, seed, generator_options, blind_spots);
102102

103+
image = Planet.rotate(image, 30);
104+
103105
Planet.save(image,"out.png");

0 commit comments

Comments
 (0)