// I asked ChatGPT "I have a p5.js program that show a side view of tall grasses. I want to make them move like brown by mild wind. What are possible revisions?"
5
// The following code is produced by ChatGPT, otherwise stated
6
7
letsegments=3;
8
letwindStrength=0;
9
letwindSpeed=0.05; // Controls how quickly the wind changes
10
letswayFactor=0.02; // Controls how much sway each grass blade has
11
12
functionsetup() {
13
createCanvas(500, 500);
14
noFill();
15
strokeWeight(5);
16
frameRate(12); // modified by schien@mail.ncku.edu.tw
17
}
18
19
functiondraw() {
20
background(255);
21
22
// Adjust the wind strength over time to simulate gusts of wind
23
windStrength+=random(-windSpeed, windSpeed);
24
25
// Use noise to make the wind gusts feel more natural
26
letnoiseFactor=noise(frameCount*swayFactor) *30;
27
28
// Draw many wiggle lines (grasses)
29
for (leti=10; i<490; i+=10) {
30
wiggle_line(i, 10, i, 450+noiseFactor);
31
}
32
}
33
34
functionwiggle_line(sx, sy, ex, ey) {
35
letxstep= (ex-sx) /segments;
36
letystep= (ey-sy) /segments;
37
letlastx=sx;
38
letlasty=sy;
39
lety=sy;
40
letx=sx;
41
42
// Simulate the sway by introducing a directional force based on wind
43
letsway=sin(windStrength) *15; // Wind effect on the sway
44
45
for (leti=0; i<segments; i++) {
46
x=x+xstep;
47
x=x+random(20) -10+sway; // Random wiggle + wind sway effect
48
y=y+ystep;
49
y=y+random(50) -25; // Slight random wiggle for natural effect
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
A fork of wiggle_lines by Sheng-Fen Nik Chien
CC Attribution ShareAlike
moving wiggle_lines
Nik Chien
xxxxxxxxxx
// schien@mail.ncku.edu.tw, DPD 2025
// based on the forked original
// I asked ChatGPT "I have a p5.js program that show a side view of tall grasses. I want to make them move like brown by mild wind. What are possible revisions?"
// The following code is produced by ChatGPT, otherwise stated
let segments = 3;
let windStrength = 0;
let windSpeed = 0.05; // Controls how quickly the wind changes
let swayFactor = 0.02; // Controls how much sway each grass blade has
function setup() {
createCanvas(500, 500);
noFill();
strokeWeight(5);
frameRate(12); // modified by schien@mail.ncku.edu.tw
}
function draw() {
background(255);
// Adjust the wind strength over time to simulate gusts of wind
windStrength += random(-windSpeed, windSpeed);
// Use noise to make the wind gusts feel more natural
let noiseFactor = noise(frameCount * swayFactor) * 30;
// Draw many wiggle lines (grasses)
for (let i = 10; i < 490; i += 10) {
wiggle_line(i, 10, i, 450 + noiseFactor);
}
}
function wiggle_line(sx, sy, ex, ey) {
let xstep = (ex - sx) / segments;
let ystep = (ey - sy) / segments;
let lastx = sx;
let lasty = sy;
let y = sy;
let x = sx;
// Simulate the sway by introducing a directional force based on wind
let sway = sin(windStrength) * 15; // Wind effect on the sway
for (let i = 0; i < segments; i++) {
x = x + xstep;
x = x + random(20) - 10 + sway; // Random wiggle + wind sway effect
y = y + ystep;
y = y + random(50) - 25; // Slight random wiggle for natural effect
stroke(20, 50, 70);
line(x, height - y, lastx, height - lasty);
lastx = x;
lasty = y;
}
}
See More Shortcuts
Please verify your email to comment
Verify Email