我正在尝试为我自己的工作调整此草图,但我似乎无法弄清楚如何使瓷砖是纯色并且每一行都没有那个阴影。
渐变和阴影由第 116 到 123 行控制。
我正在尝试为我自己的工作调整此草图,但我似乎无法弄清楚如何使瓷砖是纯色并且每一行都没有那个阴影。
渐变和阴影由第 116 到 123 行控制。
要使每个图块成为纯色,只需将调用替换为给定所需颜色gradient()
的调用和.fill()
rect(x, y, w, h)
// P_1_2_3_03
//
// Generative Gestaltung – Creative Coding im Web
// ISBN: 978-3-87439-902-9, First Edition, Hermann Schmidt, Mainz, 2018
// Benedikt Groß, Hartmut Bohnacker, Julia Laub, Claudius Lazzeroni
// with contributions by Joey Lee and Niels Poldervaart
// Copyright 2018
//
// http://www.generative-gestaltung.de
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
var colorCount = 30;
var hueValues = [];
var saturationValues = [];
var brightnessValues = [];
var actRandomSeed = 0;
var alphaValue = 255;
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100, 100);
noStroke();
}
function draw() {
noLoop();
background(0);
randomSeed(actRandomSeed);
// ------ colors ------
// create palette
for (var i = 0; i < colorCount; i++) {
if (i % 2 == 0) {
hueValues[i] = 0;
saturationValues[i] = 0;
brightnessValues[i] = random(100);
} else {
hueValues[i] = 0;
saturationValues[i] = 0;
brightnessValues[i] = 100;
}
}
// ------ area tiling ------
// count tiles
var counter = 0;
// row count and row height
var rowCount = 6;
var rowHeight = height / rowCount;
// seperate each line in parts
for (var i = rowCount; i >= 0; i--) {
// how many fragments
var partCount = i + 1;
var parts = [];
for (var ii = 0; ii < partCount; ii++) {
// sub fragments or not?
if (random() < 0.075) {
// take care of big values
var fragments = int(random(2, 20));
partCount = partCount + fragments;
for (var iii = 0; iii < fragments; iii++) {
parts.push(random(2));
}
} else {
parts.push(random(2, 20));
}
}
// add all subparts
var sumPartsTotal = 0;
for (var ii = 0; ii < partCount; ii++) {
sumPartsTotal += parts[ii];
}
// draw rects
var sumPartsNow = 0;
for (var ii = 0; ii < parts.length; ii++) {
sumPartsNow += parts[ii];
var x = map(sumPartsNow, 0, sumPartsTotal, 0, width);
var y = rowHeight * i;
var w = -map(parts[ii], 0, sumPartsTotal, 0, width);
var h = rowHeight * 1.5;
var index = counter % colorCount;
var col1 = color(0);
var col2 = color(hueValues[index], saturationValues[index], brightnessValues[index], alphaValue);
// gradient(x, y, w, h, col1, col2);
fill(col2);
rect(x, y, w, h);
counter++;
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>