gpt4 book ai didi

processing - 循环和重复模式

转载 作者:行者123 更新时间:2023-12-04 07:47:59 29 4
gpt4 key购买 nike

我正在为我的 Processing 类(class)完成一个模式,这是我目前的代码

      color[] lemonspears =
{
#f9f8ae, //#0 highlight lemon
#fffc24, //#1 mid lemon
#d6c000, //#2 dark lemon
#242000, //#3 detailing
#e7b416, //#4 highlight pear
#a8da2b, //#5 mid pear
#667a2a, //#6 dark pear
#f2e6ba, //#7 light beige
#8acdff, //#8 light blue
#0551ff, //#9 dark blue

};

color palette[] = lemonspears;
PShape Circle, Triangle;
PShape Oval, Pear, Olives, Leaves;
PShape Twig, Dots, Stem, Lines;

PShape[] Fruit = new PShape[1];
PShape[] Details = new PShape[1];

void setup()
{
size(800, 800);
background(palette[7]);
}


void draw() {
scale(.3,.3);
pushMatrix();
//BACKGROUND
//outer circles

fill(palette[8]);
stroke(palette[9]);
strokeWeight(5);
circle( 30, 40, 200);
circle( 760, 40, 200);
circle( 30, 760, 200);
circle( 760, 760, 200);

//mid triangles
fill(palette[9]);
stroke(palette[8]);
triangle( 350, 0, 405, 80, 460, 0);
stroke(palette[8]);
triangle( 350, 800, 405, 720, 460, 800);

//mid circle
ellipseMode(CENTER);
stroke(palette[1]);
fill(palette[4]);
circle( 405, 400, 200);

// right dots
strokeWeight(3);
stroke(palette[1]);
fill(palette[4]);
circle(630, 330, 11);
circle(720, 400, 11);
circle(630, 470, 11);

// left dots
circle(170, 330, 11);
circle(80, 400, 11);
circle(170, 470, 11);
popMatrix();
}
我希望这个图像作为一个在整个屏幕上运行的磁贴,我想知道使用循环的最佳方法是什么。我试过 translate() 但由于明显的原因它不起作用。谢谢!

最佳答案

您可以将您的瓷砖保存为 PImage ( https://processing.org/reference/PImage.html ),然后通过将您的瓷砖视为正方形来使用循环来分割它。
以下解决方案应该会产生您正在寻找的输出。

color[] palette =
{
#f9f8ae, //#0 highlight lemon
#fffc24, //#1 mid lemon
#d6c000, //#2 dark lemon
#242000, //#3 detailing
#e7b416, //#4 highlight pear
#a8da2b, //#5 mid pear
#667a2a, //#6 dark pear
#f2e6ba, //#7 light beige
#8acdff, //#8 light blue
#0551ff, //#9 dark blue

};

boolean drawTile = true;

void setup() {
size(800, 800);
background(palette[7]);
}

void tessellateTile(float scale){
// Save the sketch as a PImage
PImage tile = get(0, 0, width, height);

// Calculate height and width of scaled tile
int tileWidth = (int)(width*scale);
int tileHeight = (int)(height*scale);

// Resize tile
tile.resize(tileWidth, tileHeight);

// Redraw the tile at every position
for(int i = 0; i <= width; i+= tileWidth){
for(int j =0; j <= height; j+= tileHeight){
image(tile, i, j);
}
}
}

void draw() {
// Tile should be drawn and tessellated once
if(drawTile){
//BACKGROUND
//outer circles
fill(palette[8]);
stroke(palette[9]);
strokeWeight(5);
circle( 30, 40, 200);
circle( 760, 40, 200);
circle( 30, 760, 200);
circle( 760, 760, 200);

//mid triangles
fill(palette[9]);
stroke(palette[8]);
triangle( 350, 0, 405, 80, 460, 0);
stroke(palette[8]);
triangle( 350, 800, 405, 720, 460, 800);

//mid circle
ellipseMode(CENTER);
stroke(palette[1]);
fill(palette[4]);
circle( 405, 400, 200);

// right dots
strokeWeight(3);
stroke(palette[1]);
fill(palette[4]);
circle(630, 330, 11);
circle(720, 400, 11);
circle(630, 470, 11);

// left dots
circle(170, 330, 11);
circle(80, 400, 11);
circle(170, 470, 11);

// Comment this line out to just work on your single tile.
tessellateTile(0.3);

drawTile = false;
}
}

关于processing - 循环和重复模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67114015/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com