Difference between revisions of "CSC103 Processing Lab: Solution Sketches"
(Created page with "=Solutions= ==Orange Rectangles== <br /> <code><pre> void setup() { size(480, 480 ); smooth(); } void draw() { // ellipse(mouseX, mouseY, 80, 80); fill( 255, 200, 8 ); ...") |
(→Switching between rectangles and circles on mousePressed) |
||
(11 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
<br /> | <br /> | ||
<code><pre> | <code><pre> | ||
+ | void setup() { | ||
+ | size(480, 480 ); | ||
+ | smooth(); | ||
+ | } | ||
+ | | ||
+ | void draw() { | ||
+ | // ellipse(mouseX, mouseY, 80, 80); | ||
+ | fill( 255, 200, 8 ); | ||
+ | rect( mouseX, mouseY, 80, 80 ); | ||
+ | } | ||
+ | |||
+ | </pre></code> | ||
+ | <br /> | ||
+ | |||
+ | ==Swapping mouseX and mouseY== | ||
+ | <br /> | ||
+ | <code><pre> | ||
+ | void setup() { | ||
+ | size(480, 480 ); | ||
+ | smooth(); | ||
+ | } | ||
+ | | ||
+ | void draw() { | ||
+ | // ellipse(mouseX, mouseY, 80, 80); | ||
+ | fill( 255, 200, 8 ); | ||
+ | rect( mouseY, mouseX, 80, 80 ); | ||
+ | } | ||
+ | |||
+ | </pre></code> | ||
+ | <br /> | ||
+ | ==Squares and Circles== | ||
+ | <br /> | ||
+ | ::<source lang="java"> | ||
void setup() { | void setup() { | ||
− | + | size( 500, 500 ); | |
− | + | smooth(); | |
} | } | ||
− | + | ||
void draw() { | void draw() { | ||
− | + | fill( 200, 100, 100 ); | |
− | + | ellipse( mouseX, mouseY, 80, 80 ); | |
− | + | fill( 200, 0, 250 ); | |
+ | rect( mouseX, mouseY, 80, 80 ); | ||
+ | |||
} | } | ||
− | </ | + | </source> |
+ | <br /> | ||
+ | ==Squares move Horizontally, Circles Vertically== | ||
<br /> | <br /> | ||
+ | ::<source lang="java"> | ||
+ | void setup() { | ||
+ | size( 500, 500 ); | ||
+ | smooth(); | ||
+ | } | ||
+ | |||
+ | void draw() { | ||
+ | fill( 200, 100, 100 ); | ||
+ | ellipse( 100, mouseY, 80, 80 ); | ||
+ | fill( 200, 0, 250 ); | ||
+ | rect( mouseX, 100, 80, 80 ); | ||
− | == | + | } |
+ | </source> | ||
+ | <br /> | ||
+ | ==Random Circles== | ||
<br /> | <br /> | ||
− | < | + | ::<source lang="java"> |
void setup() { | void setup() { | ||
− | + | size( 500, 500 ); | |
− | + | smooth(); | |
} | } | ||
− | + | ||
void draw() { | void draw() { | ||
− | + | fill( 200, 150, 200 ); | |
− | + | ellipse( random(500), random(500), 80, 80 ); | |
− | + | // fill( 200, 0, 250 ); | |
+ | // rect( mouseX, 100, 80, 80 ); | ||
+ | |||
} | } | ||
− | </ | + | </source> |
<br /> | <br /> | ||
− | == | + | ==Random Circles with Varying Size and Color== |
<br /> | <br /> | ||
− | < | + | ::<source lang="java"> |
void setup() { | void setup() { | ||
− | + | size( 500, 500 ); | |
− | + | smooth(); | |
} | } | ||
− | + | ||
void draw() { | void draw() { | ||
− | + | fill( 200, random(255), mouseX/2 ); | |
− | + | ellipse( random(500), random(500), mouseX, mouseX ); | |
− | + | // fill( 200, 0, 250 ); | |
− | + | // rect( mouseX, 100, 80, 80 ); | |
− | + | ||
− | + | } | |
− | + | </source> | |
− | + | <br /> | |
− | + | ==Random Circles in Square Areas== | |
− | + | <br /> | |
− | + | ::<source lang="java"> | |
+ | void setup() { | ||
+ | size( 500, 500 ); | ||
+ | smooth(); | ||
} | } | ||
− | + | void draw() { | |
+ | fill( 200, random(255), mouseX/2 ); | ||
+ | ellipse( random(100,200), random(100,200), mouseX, mouseX ); | ||
+ | |||
+ | fill( 200, mouseX/2, random(255) ); | ||
+ | ellipse( random(300,400), random(300,400), mouseX, mouseX ); | ||
+ | |||
+ | } | ||
+ | </source> | ||
<br /> | <br /> | ||
− | == | + | |
+ | ==Switching between rectangles and circles on mousePressed== | ||
<br /> | <br /> | ||
− | < | + | <showafterdate after="20171019 12:00" before="20171231 00:00"> |
+ | ::<source lang="java"> | ||
+ | |||
void setup() { | void setup() { | ||
size(480, 480 ); | size(480, 480 ); | ||
Line 68: | Line 135: | ||
if ( mousePressed == true ) { | if ( mousePressed == true ) { | ||
fill( 231, 47, 39 ); // red | fill( 231, 47, 39 ); // red | ||
− | + | ellipse(mouseX, mouseY, 80, 80); | |
} | } | ||
else { | else { | ||
fill( 255, 200, 8 ); // orange | fill( 255, 200, 8 ); // orange | ||
− | rect(mouseX, mouseY, | + | rect(mouseX, mouseY, 80, 80); |
} | } | ||
} | } | ||
+ | </source> | ||
+ | </showafterdate> | ||
+ | <br /> | ||
+ | ==Tall-skinny, vs. short-wide Rectangles== | ||
+ | <br /> | ||
+ | <code><pre> | ||
+ | void setup() { | ||
+ | size(480, 480 ); | ||
+ | smooth(); | ||
+ | } | ||
+ | | ||
+ | void draw() { | ||
+ | //background( 200 ); | ||
+ | | ||
+ | if ( mousePressed == true ) { | ||
+ | fill( 231, 47, 39 ); // red | ||
+ | rect(mouseX, mouseY, 200, 20); | ||
+ | } | ||
+ | else { | ||
+ | fill( 255, 200, 8 ); // orange | ||
+ | rect(mouseX, mouseY, 20, 100); | ||
+ | } | ||
+ | | ||
+ | } | ||
</pre></code> | </pre></code> | ||
<br /> | <br /> | ||
Line 82: | Line 173: | ||
<br /> | <br /> | ||
<code><pre> | <code><pre> | ||
− | void setup() { | + | void setup() { |
− | + | size(480, 480 ); | |
− | + | smooth(); | |
− | } | + | } |
+ | | ||
+ | void draw() { | ||
+ | //background( 200 ); | ||
+ | if ( mousePressed ) { | ||
+ | line( mouseX, mouseY, pmouseX, pmouseY ); | ||
+ | } | ||
+ | | ||
+ | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</pre></code> | </pre></code> | ||
<br /> | <br /> | ||
Line 99: | Line 191: | ||
<br /> | <br /> | ||
<code><pre> | <code><pre> | ||
+ | void setup() { | ||
+ | size( 400, 400 ); | ||
+ | smooth(); | ||
+ | } | ||
+ | | ||
+ | void draw() { | ||
+ | | ||
+ | background(200); | ||
+ | | ||
+ | // count from 20 to 380 jumping 20 each time. | ||
+ | for( int x = 20; x < 400; x = x + 20 ) { | ||
+ | | ||
+ | // and draw a circle in that position, on a horizontal line. | ||
+ | fill( 250, 200, 8 ); | ||
+ | ellipse( 200, x, 15,15 ); | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </pre></code> | ||
+ | <br /> | ||
+ | ==Diagonal of Orange Circles== | ||
+ | <br /> | ||
+ | ::<source lang="java"> | ||
void setup() { | void setup() { | ||
size( 400, 400 ); | size( 400, 400 ); | ||
Line 107: | Line 223: | ||
background(200); | background(200); | ||
+ | fill( 250, 200, 8 ); | ||
// count from 20 to 380 jumping 20 each time. | // count from 20 to 380 jumping 20 each time. | ||
− | for( int | + | for( int xy = 20; xy < 400; xy = xy + 20 ) { |
− | + | // and draw a circle in that position, on a diagonal line | |
− | + | // where x and y have the same value. | |
− | + | ellipse( xy, xy, 15,15 ); | |
} | } | ||
} | } | ||
− | </ | + | </source> |
<br /> | <br /> | ||
+ | |||
==Cross of Orange Circles== | ==Cross of Orange Circles== | ||
<br /> | <br /> | ||
− | < | + | ::<source lang="java"> |
void setup() { | void setup() { | ||
size( 400, 400 ); | size( 400, 400 ); | ||
Line 141: | Line 259: | ||
} | } | ||
} | } | ||
− | </ | + | </source> |
<br /> | <br /> | ||
+ | |||
==Diagonal Orange Circles== | ==Diagonal Orange Circles== | ||
<br /> | <br /> | ||
<code><pre> | <code><pre> | ||
− | void setup() { | + | void setup() { |
− | + | size( 400, 400 ); | |
− | + | smooth(); | |
− | } | + | } |
− | + | | |
− | void draw() { | + | void draw() { |
+ | | ||
+ | background(200); | ||
+ | | ||
+ | // count from 20 to 380 jumping 20 each time. | ||
+ | for( int x = 20; x < 400; x = x + 20 ) { | ||
+ | fill( 255, 200, 8 ); | ||
+ | ellipse( x, x, 15, 15 ); | ||
+ | } | ||
+ | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</pre></code> | </pre></code> | ||
<br /> | <br /> | ||
Line 166: | Line 286: | ||
<br /> | <br /> | ||
<code><pre> | <code><pre> | ||
− | void setup() { | + | void setup() { |
− | + | size( 400, 400 ); | |
− | + | smooth(); | |
− | } | + | } |
+ | | ||
+ | void draw() { | ||
+ | | ||
+ | background(200); | ||
+ | | ||
+ | // count from 20 to 380 jumping 20 each time. | ||
+ | for( int x = 20; x < 400; x = x + 20 ) { | ||
+ | fill( 250, 200, 8 ); | ||
− | + | if ( x < mouseX ) { | |
+ | ellipse( x, x, 15,15 ); | ||
+ | } | ||
+ | } | ||
+ | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</pre></code> | </pre></code> | ||
<br /> | <br /> | ||
Line 189: | Line 310: | ||
<br /> | <br /> | ||
<code><pre> | <code><pre> | ||
− | void setup() { | + | void setup() { |
− | + | size( 400, 400 ); | |
− | + | smooth(); | |
− | } | + | } |
+ | | ||
+ | void draw() { | ||
+ | | ||
+ | background(200); | ||
+ | | ||
+ | // count from 20 to 380 jumping 20 each time. | ||
+ | for( int x = 20; x < 400; x = x + 20 ) { | ||
+ | fill( 250, x/2, 255-x/2 ); | ||
− | + | if ( x < mouseX ) { | |
− | + | ellipse( x, x, x/2,x/2 ); | |
− | + | } | |
− | + | } | |
− | + | } | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | } | ||
</pre></code> | </pre></code> | ||
<br /> | <br /> |
Latest revision as of 14:29, 18 October 2017
Contents
- 1 Solutions
- 1.1 Orange Rectangles
- 1.2 Swapping mouseX and mouseY
- 1.3 Squares and Circles
- 1.4 Squares move Horizontally, Circles Vertically
- 1.5 Random Circles
- 1.6 Random Circles with Varying Size and Color
- 1.7 Random Circles in Square Areas
- 1.8 Switching between rectangles and circles on mousePressed
- 1.9 Tall-skinny, vs. short-wide Rectangles
- 1.10 Drawing lines on mousePressed
- 1.11 Vertical Circles
- 1.12 Diagonal of Orange Circles
- 1.13 Cross of Orange Circles
- 1.14 Diagonal Orange Circles
- 1.15 Orange Circles Left of the Mouse
- 1.16 Growing Multicolored Circles
Solutions
Orange Rectangles
void setup() {
size(480, 480 );
smooth();
}
void draw() {
// ellipse(mouseX, mouseY, 80, 80);
fill( 255, 200, 8 );
rect( mouseX, mouseY, 80, 80 );
}
Swapping mouseX and mouseY
void setup() {
size(480, 480 );
smooth();
}
void draw() {
// ellipse(mouseX, mouseY, 80, 80);
fill( 255, 200, 8 );
rect( mouseY, mouseX, 80, 80 );
}
Squares and Circles
void setup() { size( 500, 500 ); smooth(); } void draw() { fill( 200, 100, 100 ); ellipse( mouseX, mouseY, 80, 80 ); fill( 200, 0, 250 ); rect( mouseX, mouseY, 80, 80 ); }
Squares move Horizontally, Circles Vertically
void setup() { size( 500, 500 ); smooth(); } void draw() { fill( 200, 100, 100 ); ellipse( 100, mouseY, 80, 80 ); fill( 200, 0, 250 ); rect( mouseX, 100, 80, 80 ); }
Random Circles
void setup() { size( 500, 500 ); smooth(); } void draw() { fill( 200, 150, 200 ); ellipse( random(500), random(500), 80, 80 ); // fill( 200, 0, 250 ); // rect( mouseX, 100, 80, 80 ); }
Random Circles with Varying Size and Color
void setup() { size( 500, 500 ); smooth(); } void draw() { fill( 200, random(255), mouseX/2 ); ellipse( random(500), random(500), mouseX, mouseX ); // fill( 200, 0, 250 ); // rect( mouseX, 100, 80, 80 ); }
Random Circles in Square Areas
void setup() { size( 500, 500 ); smooth(); } void draw() { fill( 200, random(255), mouseX/2 ); ellipse( random(100,200), random(100,200), mouseX, mouseX ); fill( 200, mouseX/2, random(255) ); ellipse( random(300,400), random(300,400), mouseX, mouseX ); }
Switching between rectangles and circles on mousePressed
<showafterdate after="20171019 12:00" before="20171231 00:00">
void setup() { size(480, 480 ); smooth(); } void draw() { //background( 200 ); if ( mousePressed == true ) { fill( 231, 47, 39 ); // red ellipse(mouseX, mouseY, 80, 80); } else { fill( 255, 200, 8 ); // orange rect(mouseX, mouseY, 80, 80); } }
</showafterdate>
Tall-skinny, vs. short-wide Rectangles
void setup() {
size(480, 480 );
smooth();
}
void draw() {
//background( 200 );
if ( mousePressed == true ) {
fill( 231, 47, 39 ); // red
rect(mouseX, mouseY, 200, 20);
}
else {
fill( 255, 200, 8 ); // orange
rect(mouseX, mouseY, 20, 100);
}
}
Drawing lines on mousePressed
void setup() {
size(480, 480 );
smooth();
}
void draw() {
//background( 200 );
if ( mousePressed ) {
line( mouseX, mouseY, pmouseX, pmouseY );
}
}
Vertical Circles
void setup() {
size( 400, 400 );
smooth();
}
void draw() {
background(200);
// count from 20 to 380 jumping 20 each time.
for( int x = 20; x < 400; x = x + 20 ) {
// and draw a circle in that position, on a horizontal line.
fill( 250, 200, 8 );
ellipse( 200, x, 15,15 );
}
}
Diagonal of Orange Circles
void setup() { size( 400, 400 ); smooth(); } void draw() { background(200); fill( 250, 200, 8 ); // count from 20 to 380 jumping 20 each time. for( int xy = 20; xy < 400; xy = xy + 20 ) { // and draw a circle in that position, on a diagonal line // where x and y have the same value. ellipse( xy, xy, 15,15 ); } }
Cross of Orange Circles
void setup() { size( 400, 400 ); smooth(); } void draw() { background(200); // count from 20 to 380 jumping 20 each time. for( int x = 20; x < 400; x = x + 20 ) { // and draw a circle in that position, on a horizontal line. fill( 250, 200, 8 ); ellipse( 200, x, 15,15 ); ellipse( x, 200, 15,15 ); } }
Diagonal Orange Circles
void setup() {
size( 400, 400 );
smooth();
}
void draw() {
background(200);
// count from 20 to 380 jumping 20 each time.
for( int x = 20; x < 400; x = x + 20 ) {
fill( 255, 200, 8 );
ellipse( x, x, 15, 15 );
}
}
Orange Circles Left of the Mouse
void setup() {
size( 400, 400 );
smooth();
}
void draw() {
background(200);
// count from 20 to 380 jumping 20 each time.
for( int x = 20; x < 400; x = x + 20 ) {
fill( 250, 200, 8 );
if ( x < mouseX ) {
ellipse( x, x, 15,15 );
}
}
}
Growing Multicolored Circles
void setup() {
size( 400, 400 );
smooth();
}
void draw() {
background(200);
// count from 20 to 380 jumping 20 each time.
for( int x = 20; x < 400; x = x + 20 ) {
fill( 250, x/2, 255-x/2 );
if ( x < mouseX ) {
ellipse( x, x, x/2,x/2 );
}
}
}