Skip to content

Commit f058b16

Browse files
committed
new sketches from the last 3 meetings
1 parent dd06677 commit f058b16

File tree

10 files changed

+1110
-0
lines changed

10 files changed

+1110
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
void setup() {
2+
size(600, 600);
3+
frameRate(24); //24 frames per second
4+
background(255,255,255); // RGB, otherwise is gray scale
5+
}
6+
7+
void draw(){
8+
9+
println(mouseX, mouseY);
10+
noStroke();
11+
12+
if(mouseX < 300){
13+
fill(255,0,0,128);
14+
ellipse(mouseX, mouseY, 100,100);
15+
}
16+
17+
if(mouseX > 300){
18+
fill(0,0,255,128);
19+
rectMode(CENTER);
20+
rect(mouseX, mouseY, 100,100);
21+
}
22+
23+
24+
fill(255);
25+
rectMode(CORNER);
26+
rect(0,0,200,30);
27+
fill(255,0,0);
28+
textSize(20);
29+
text("Press a,s,d or f", 10,20);
30+
31+
}
32+
33+
void keyPressed(){
34+
println(key);
35+
if(key == 'a'){
36+
background(255,0,0); // RGB, otherwise is gray scale
37+
}else if(key == 's'){
38+
background(0,255,0); // RGB, otherwise is gray scale
39+
}else if(key == 'd'){
40+
background(0,0,255); // RGB, otherwise is gray scale
41+
}else if(key == 'f'){
42+
background(255,255,255); // RGB, otherwise is gray scale
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
void setup() {
2+
size(600, 600);
3+
frameRate(24); //24 frames per second
4+
background(255,255,255); // RGB, otherwise is gray scale
5+
}
6+
7+
void draw(){
8+
9+
println(mouseX, mouseY);
10+
noStroke();
11+
12+
if(mouseX < 200){ // smaller than 200
13+
14+
fill(255,0,0,128);
15+
ellipse(mouseX, mouseY, 100,100);
16+
17+
}else if((mouseX > 200) && (mouseX < 400)){ // using the && operator to check interval
18+
// asking two questions at the same time
19+
fill(0,0,255,128);
20+
rectMode(CENTER); //draw the Rect from the CENTER
21+
rect(mouseX, mouseY, 100,100);
22+
23+
} else if(mouseX > 400){ // asking if is bigger than 400
24+
fill(0,255,0,128);
25+
ellipse(mouseX, mouseY, 100,100);
26+
}
27+
28+
29+
fill(255);
30+
rectMode(CORNER);
31+
rect(0,0,200,30);
32+
fill(255,0,0);
33+
textSize(20);
34+
text("Press a,s,d or f", 10,20);
35+
36+
37+
}
38+
39+
void keyPressed(){
40+
println(key);
41+
if(key == 'a'){
42+
background(128,0,0); // RGB, otherwise is gray scale
43+
}else if(key == 's'){
44+
background(0,128,0); // RGB, otherwise is gray scale
45+
}else if(key == 'd'){
46+
background(0,0,128); // RGB, otherwise is gray scale
47+
}else if(key == 'f'){
48+
background(255,255,255); // RGB, otherwise is gray scale
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
void setup() {
2+
size(800, 500);
3+
frameRate(24);
4+
smooth();
5+
}
6+
7+
void draw() {
8+
background(255);
9+
drawRobot(1, 50,50); //calling the function with fixed parameters
10+
11+
12+
}
13+
//function to draw my shape
14+
void drawRobot(int blink, float posx, float posy) {
15+
pushMatrix();
16+
//translate to given parameters
17+
translate(posx, posy);
18+
ellipse(0,0,50,50);
19+
ellipse(-10,0,10,10);
20+
ellipse(-10,0,3,3);
21+
22+
ellipse(10,0,10,10);
23+
ellipse(10,0,3,3);
24+
25+
arc(0, 10, 20, 20, radians(30),radians(150)); //randians convert degrees
26+
27+
popMatrix();
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
float posx;
2+
float posy;
3+
float scaleValue = 1;
4+
color backColor;
5+
6+
void setup() {
7+
size(800, 500);
8+
frameRate(24);
9+
posx = random(0, width);
10+
posy = random(0, height);
11+
backColor = color(255);
12+
13+
}
14+
15+
void draw() {
16+
17+
background(255);
18+
drawRobot(scaleValue, 1, posx, posy); //calling the function with fixed parameters
19+
20+
//posx = posx + 10;
21+
// posy = posy + 10;
22+
23+
if(posx > width){
24+
posx = random(0, width);
25+
scaleValue = random(0.5,5);
26+
}
27+
if(posy > height){
28+
posy = random(0, height);
29+
scaleValue = random(0.5,5);
30+
}
31+
32+
pushStyle();
33+
fill(0);
34+
noStroke();
35+
textSize(20);
36+
text("Press the arrows to move, q and w to random", 10,20);
37+
popStyle();
38+
}
39+
40+
void keyPressed() {
41+
if (key == 'q') {
42+
posx = random(0, width);
43+
posy = random(0, height);
44+
}else if(key == 'w'){
45+
scaleValue = random(0.5,5);
46+
}else if(key == CODED){
47+
//arrow keys tests
48+
if(keyCode == UP){
49+
posy = posy - 10;
50+
}else if(keyCode == DOWN){
51+
posy = posy + 10;
52+
}else if(keyCode == LEFT){
53+
posx = posx - 10;
54+
}else if(keyCode == RIGHT){
55+
posx = posx + 10;
56+
}
57+
}
58+
59+
}
60+
61+
62+
//function to draw my shape
63+
void drawRobot(float scaleValue, int blink, float posx, float posy) {
64+
pushMatrix();
65+
//translate to given parameters
66+
67+
translate(posx, posy);
68+
scale(scaleValue);
69+
ellipse(0, 0, 50, 50);
70+
ellipse(-10, 0, 10, 10);
71+
ellipse(-10, 0, 3, 3);
72+
73+
ellipse(10, 0, 10, 10);
74+
ellipse(10, 0, 3, 3);
75+
76+
arc(0, 10, 20, 20, radians(30), radians(150)); //randians convert degrees
77+
78+
popMatrix();
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
float posx;
2+
float posy;
3+
float scaleValue = 1;
4+
color backColor;
5+
int blink = 2;
6+
7+
long lastTime = 0;
8+
void setup() {
9+
size(800, 500);
10+
frameRate(24);
11+
posx = random(0, width);
12+
posy = random(0, height);
13+
backColor = color(255);
14+
}
15+
16+
void draw() {
17+
18+
background(backColor);
19+
20+
21+
drawRobot(scaleValue, blink, posx, posy); //calling the function with fixed parameters
22+
23+
if(millis() - lastTime > 200 ){
24+
blink = (int)random(0,3);
25+
lastTime = millis();
26+
}
27+
//posx = posx + 10;
28+
//posy = posy + 10;
29+
float r = map(posx, 0, width, 0, 255);
30+
float b = map(posy, 0, width, 0, 255);
31+
32+
backColor = color(r, b, 255);
33+
34+
if (posx > width) {
35+
posx = random(0, width);
36+
scaleValue = random(0.5, 5);
37+
}
38+
if (posy > height) {
39+
posy = random(0, height);
40+
scaleValue = random(0.5, 5);
41+
}
42+
43+
pushStyle();
44+
fill(0);
45+
noStroke();
46+
textSize(20);
47+
text("Press the arrows to move, q and w to random", 10,20);
48+
popStyle();
49+
}
50+
51+
void keyPressed() {
52+
if (key == 'q') {
53+
posx = random(0, width);
54+
posy = random(0, height);
55+
} else if (key == 'w') {
56+
scaleValue = random(0.5, 5);
57+
} else if (key == CODED) {
58+
//arrow keys tests
59+
if (keyCode == UP) {
60+
posy = posy - 10;
61+
} else if (keyCode == DOWN) {
62+
posy = posy + 10;
63+
} else if (keyCode == LEFT) {
64+
posx = posx - 10;
65+
} else if (keyCode == RIGHT) {
66+
posx = posx + 10;
67+
}
68+
}
69+
}
70+
71+
72+
//function to draw my shape
73+
void drawRobot(float scaleValue, int blink, float posx, float posy) {
74+
pushMatrix();
75+
//translate to given parameters
76+
77+
translate(posx, posy);
78+
scale(scaleValue);
79+
if (blink == 0) {
80+
81+
ellipse(0, 0, 50, 50);
82+
ellipse(-10, 0, 10, 10);
83+
ellipse(-10, 0, 3, 3);
84+
ellipse(10, 0, 10, 10);
85+
ellipse(10, 0, 3, 3);
86+
87+
} else if (blink == 1) {
88+
89+
ellipse(0, 0, 50, 50);
90+
91+
ellipse(-10, 0, 10, 1);
92+
ellipse(-10, 0, 3, 3);
93+
94+
ellipse(10, 0, 10, 1);
95+
ellipse(10, 0, 3, 3);
96+
97+
} else if (blink == 2) {
98+
99+
ellipse(0, 0, 50, 50);
100+
101+
ellipse(-10, 0, 10, 15);
102+
ellipse(-10, 0, 3, 1);
103+
104+
ellipse(10, 0, 10, 15);
105+
ellipse(10, 0, 3, 1);
106+
107+
}
108+
109+
arc(0, 10, 20, 20, radians(30), radians(150)); //randians convert degrees
110+
111+
popMatrix();
112+
}

0 commit comments

Comments
 (0)