Last active
April 5, 2020 02:16
-
-
Save moziauddin/261582b872d2d5eb52891c30beb2f060 to your computer and use it in GitHub Desktop.
Processing Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int x = 0; | |
int y = 0; | |
int rectSize = 20; | |
int numRect; | |
int count = 0; | |
void setup() { | |
size(200,200); | |
frameRate(10); | |
background(240); | |
noStroke(); | |
} | |
void draw() { | |
numRect = (width/rectSize) * (height/rectSize); // Counts number of squares so the loop can restart | |
fill(random(0,200), random(0,200), random(0,200)); // generate a random color to fill the square | |
rect(x, y, rectSize, rectSize); | |
// Create square after square | |
if(x < width) { | |
x += rectSize; | |
} else if (count > numRect) { | |
background(240); | |
count = 0; // Restarts the drawing from top | |
x = 0; | |
y = 0; | |
} else { | |
x = 0; | |
y += rectSize; | |
} | |
// Make x and y zero if they reach end of the screen and re-draw | |
count += 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int x = 0; | |
int y = 0; | |
int rectSize = 40; | |
int numRect; | |
int count = 0; | |
boolean scalingCheck = false; // Controls loop or noLoop code | |
void setup() { | |
size(640,480); | |
frameRate(60); | |
background(240); | |
if(width % rectSize != 0 || height % rectSize != 0) { | |
scalingCheck = true; | |
noLoop(); | |
} | |
} | |
void draw() { | |
if(scalingCheck) { | |
fill(255, 0, 0); | |
String s = "Your rectSize variable and canvas size are incompatible."; | |
textSize(width / 20); | |
text(s, width * 0.1, height * 0.1, width * 0.9, height * 0.5); | |
println(s); | |
} else { | |
// Counts number of squares so the loop can restart | |
numRect = (width/rectSize) * (height/rectSize); | |
// generate a random color to fill the square | |
fill(random(0,200), random(0,255), random(0,255), 100); | |
noStroke(); | |
rect(x, y, rectSize, rectSize); | |
// Create square after square | |
if(x < width) { | |
x += rectSize; | |
} else if (count > numRect) { | |
count = 0; // Restarts the drawing from top | |
x = 0; | |
y = 0; | |
delay(100); | |
background(250); | |
} else { | |
x = 0; | |
y += rectSize; | |
} | |
// Make x and y zero if they reach end of the screen and re-draw | |
count += 1; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size(500,200); | |
background(0); | |
String s = "hello"; | |
String binaryString = ""; | |
for(int i = 0; i<s.length();i++){ | |
binaryString += s.charAt(i) + " - " + binary(s.charAt(i)); | |
binaryString += "\n"; | |
} | |
textSize(20); | |
text(binaryString, 10, 10, width, height); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float rate = 4; // Change pow to int and fraction | |
void setup() { | |
size(400,400); | |
noFill(); | |
} | |
void draw() { | |
for(int x = 0; x< width; x+=5) { | |
float n = norm(x, 0, width); // Create a Range | |
float y = pow(n, rate); // Compute curve | |
y*=height; // Scalte to height | |
strokeWeight(n); | |
ellipse(x, y, width + rate * 100, height + rate * 100); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float rate = 6; // Change pow to int and fraction | |
void setup() { | |
size(400,400); | |
noFill(); | |
} | |
void draw() { | |
for(int x = 0; x< width; x+=5) { | |
float n = map(x, 0, width, -1, 1); // Create a Range | |
float p = pow(n, rate); // Compute curve | |
float y = lerp(0, height, p); // Scalte to height | |
line(x, 0, x, y); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float rate = 2; // Change pow to int and fraction | |
void setup() { | |
size(400,400); | |
} | |
void draw() { | |
for(int x = 0; x< width; x++) { | |
float n = norm(x, 0, width); // Create a Range | |
float c = n * 255; | |
stroke(c); | |
line(x, 0, x, height / 2); | |
float cSq = pow(c, rate) * 255; | |
stroke(cSq); | |
line(x, height / 2, x, height); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float ratio = 0.15; | |
int size = width/10; | |
void setup() { | |
size(800, 800); | |
size = width/10; | |
} | |
void draw() { | |
noStroke(); | |
//int size = width/10; | |
for (int x = 0; x <= width; x+=size) { | |
for (int y = 0; y<= height; y+=size) { | |
fill((x+y) * ratio); | |
rect(x, y, size, size); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int size = 10; | |
void setup() { | |
size(400,200); | |
} | |
void draw() { | |
fill(0); | |
noStroke(); | |
for (int x = -width; x <= width + size; x+=size) { | |
for (int y = -height; y<= height; y+=size) { | |
ellipse(x + y/3.0, y + x / 8.0, 4, 8); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// y = x ^ 4 | |
float rate = 2; // Change pow to int and fraction | |
void setup() { | |
size(400,400); | |
} | |
void draw() { | |
for(int x = 0; x< width; x++) { | |
float n = norm(x, 0, width); | |
float y = pow(n, rate); | |
y*=height; | |
point(x, y); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float x, y; | |
int sizeX = 400; | |
int sizeY = 400; | |
void setup() { | |
background(0); | |
x = 0; | |
y = 0; | |
ellipseMode(CORNER); | |
} | |
void settings() { | |
size(sizeX, sizeY); | |
} | |
void draw() { | |
ellipse(x, y, 10, height); | |
x+=15; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float x, y, r; | |
color c; | |
void setup() { | |
r = random(0,255); | |
size(400, 200); | |
} | |
void draw() { | |
x = map(mouseX, 0, width, 0, 255); | |
y = map(mouseX, 0, height, 0, 255); | |
c = color(x, y, r); | |
background(c); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment