Skip to content

Commit

Permalink
Sørg for at alle landskapsfarger kan leses (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornreppen authored Mar 31, 2019
1 parent f9de47a commit 1b1593d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 deletions.
24 changes: 0 additions & 24 deletions steg/09/colormap.js

This file was deleted.

4 changes: 2 additions & 2 deletions steg/09/colormap_la_klg.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const log = require("log-less-fancy")()
const Jimp = require("jimp")
const io = require("../../lib/io")

let koder = io.lesKildedatafilOld("Natur_i_Norge/Landskap/la_index")
let fargeindeks = io.lesKildedatafilOld("Natur_i_Norge/Landskap/la_index")
let farger = io.lesDatafil("la_farger")
let la = io.lesDatafil("landskap")
let klg = io.lesDatafil("landskapsgradient")
Expand Down Expand Up @@ -45,7 +45,7 @@ function fargelegg(image, klgKode) {
// throw new Error("Finner ikke " + klgKode)
}
typer.forEach(type => {
const index = koder[type]
const index = fargeindeks[type]
if (index) settFarge(image, klgKode, index)
})
}
Expand Down
38 changes: 38 additions & 0 deletions steg/11/colormap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const Jimp = require("jimp")
const io = require("../../lib/io")

let koder = io.lesKildedatafilOld("Natur_i_Norge/Landskap/la_index")
let meta = io.lesDatafil("metabase_med_farger")

new Jimp(512, 8, 0xff0000ff, (err, image) => {
const color = Jimp.cssColorToHex("#00f")
for (let y = 0; y < 8; y++) image.setPixelColor(color, 0, y)
for (let nivå = 1; nivå < 9; nivå++) fyllNivå(nivå, image, nivå - 1)
image.write("LA.palette.png")
})

function fyllNivå(nivå, image, y) {
Object.keys(koder).forEach(kode => {
const index = koder[kode]
let dybde = 0
// if (kode === "NN-LA-TI-M-A" && nivå === 4) debugger
while (true) {
dybde = kode.split("-").length
if (dybde <= nivå) break
const xoo = meta[kode]
const oo = meta[kode].foreldre
kode = oo[0]
}
settFarge(image, kode, index, y)
})
}
function settFarge(image, kode, x, y) {
if (!meta[kode]) {
console.log("Mangler farge: " + kode)
return
}
const farge = meta[kode].farge
if (kode.startsWith("NN-LA-TI-M")) console.log(y, x, farge, kode)
const color = Jimp.cssColorToHex(farge)
image.setPixelColor(color, x, y)
}

0 comments on commit 1b1593d

Please sign in to comment.