Skip to content

Commit

Permalink
version 30
Browse files Browse the repository at this point in the history
  • Loading branch information
sixhat committed Nov 8, 2018
1 parent c8ba7a6 commit 99eb7a7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
37 changes: 31 additions & 6 deletions lib/utils.dave.p5.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// utils.dave.p5.js v.29
// utils.dave.p5.js v.30
class Dave {
// Short version of functions bellow.
constructor(){
this.grid=new Grid();
constructor() {
this.grid = new Grid();
this.g = this.grid;
}
// alias for fillHsluv
f(h, s, l) {
this.fillHsluv(h,s,l);
this.fillHsluv(h, s, l);
}
// alias for strokeHsluv
s(h, s, l) {
this.strokeHsluv(h,s,l);
this.strokeHsluv(h, s, l);
}
// sets fill according to hsluv parameters
fillHsluv(h, s, l) {
Expand All @@ -23,6 +23,25 @@ class Dave {
let rgb = hsluv.hsluvToRgb([h, s, l]);
stroke(rgb[0] * 255, rgb[1] * 255, rgb[2] * 255);
}
// Create a fast get function to use instead of in P5.
pget(x, y, img) {
img.loadPixels();
let d = pixelDensity();

for (var i = 0; i < d; i++) {
for (var j = 0; j < d; j++) {
// loop over
let idx = 4 * ((y * d + j) * img.width * d + (x * d + i));
pixels[idx] = r;
pixels[idx + 1] = g;
pixels[idx + 2] = b;
pixels[idx + 3] = a;
}
}
// Things to take into consideration: x,y must be in image.
// pixelDensity has to be taken into consideration.
// loadPixels should be called only during the first time for this particular image.
}
}
// A simple Grid System to place over drawings
class Grid {
Expand Down Expand Up @@ -132,7 +151,12 @@ class Turtle {
// + turn right
// - turn left
drawLSystem(ls, step, angle) {
for (let letter of ls.endString) {
this.drawString(ls.endString,step,angle);
}

// Draw a string (used by drawLSystem, but can be generic)
drawString(string, step, angle) {
for (let letter of string) {
switch (letter) {
case 'F':
this.pd();
Expand All @@ -158,6 +182,7 @@ class Turtle {
}
}
}

// Pushes the current state of turtle to stack.
push() {
this.stack.push({
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
29
30

0 comments on commit 99eb7a7

Please sign in to comment.