From 48c179d931d2a0b1c65aa4b4f8d545ff542724b9 Mon Sep 17 00:00:00 2001 From: twang1999 Date: Wed, 2 Dec 2015 14:34:20 -0500 Subject: [PATCH 1/6] added DrawARandomCircle function --- VoidFunctions/VoidFunctions.pde | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/VoidFunctions/VoidFunctions.pde b/VoidFunctions/VoidFunctions.pde index 8b13789..a3b7569 100644 --- a/VoidFunctions/VoidFunctions.pde +++ b/VoidFunctions/VoidFunctions.pde @@ -1 +1,31 @@ +void setup(){ + size(800,600); +} +void draw(){ + drawARandomCircle(); + if(mousePressed){ + drawACircleAt(mouseX,mouseY); + } + if(keyPressed){ + drawACircleAt(width/2,height/2); + } +} + +void drawARandomCircle(){ + float diam = random (5,50); + fill(0,random(255),random(100,255)); + ellipse(random(width),random(height),diam,diam); +} + +void drawACircleAt(float x, float y){ //float x & y revert back to mouseX and mouseY + fill(255); + fill(x,y,25,25); +} + + +/********************************* +how to define function: dataType name (parmeters){ + block of code +} +**********************************/ \ No newline at end of file From 4b766670793720a498f6c0dbb717334c70bbc281 Mon Sep 17 00:00:00 2001 From: twang1999 Date: Wed, 2 Dec 2015 14:40:36 -0500 Subject: [PATCH 2/6] class example --- VoidFunctions/VoidFunctions.pde | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/VoidFunctions/VoidFunctions.pde b/VoidFunctions/VoidFunctions.pde index a3b7569..9084b4a 100644 --- a/VoidFunctions/VoidFunctions.pde +++ b/VoidFunctions/VoidFunctions.pde @@ -1,18 +1,18 @@ + void setup(){ size(800,600); } void draw(){ - drawARandomCircle(); + DrawARandomCircle(); if(mousePressed){ - drawACircleAt(mouseX,mouseY); + DrawACircleAt(mouseX,mouseY); } if(keyPressed){ - drawACircleAt(width/2,height/2); + DrawACircleAt(width/2,height/2); } -} -void drawARandomCircle(){ +void DrawARandomCircle(){ float diam = random (5,50); fill(0,random(255),random(100,255)); ellipse(random(width),random(height),diam,diam); @@ -23,9 +23,8 @@ void drawACircleAt(float x, float y){ //float x & y revert back to mouseX and fill(x,y,25,25); } - /********************************* -how to define function: dataType name (parmeters){ +how to define function: dataType name (parameters- that are not included in code){ block of code } **********************************/ \ No newline at end of file From 4540dd89b767bcec758419b13b453e46acb6ff6b Mon Sep 17 00:00:00 2001 From: twang1999 Date: Wed, 2 Dec 2015 14:50:31 -0500 Subject: [PATCH 3/6] voidfunction practice --- VoidFunctions/VoidFunctions.pde | 41 +++++++++++++++------------------ 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/VoidFunctions/VoidFunctions.pde b/VoidFunctions/VoidFunctions.pde index 9084b4a..3d54a07 100644 --- a/VoidFunctions/VoidFunctions.pde +++ b/VoidFunctions/VoidFunctions.pde @@ -1,30 +1,25 @@ - -void setup(){ - size(800,600); +float fill = random(100); +void setup() { + size(800, 600); } -void draw(){ - DrawARandomCircle(); - if(mousePressed){ - DrawACircleAt(mouseX,mouseY); - } - if(keyPressed){ - DrawACircleAt(width/2,height/2); - } - -void DrawARandomCircle(){ - float diam = random (5,50); - fill(0,random(255),random(100,255)); - ellipse(random(width),random(height),diam,diam); +void draw() { + DrawABlueSquare(); + DrawACircle(fill); } -void drawACircleAt(float x, float y){ //float x & y revert back to mouseX and mouseY - fill(255); - fill(x,y,25,25); +void DrawABlueSquare() { + fill(#082EFF); + rect(375, 275, 50, 50); } -/********************************* -how to define function: dataType name (parameters- that are not included in code){ - block of code +void DrawACircle(float fill){ + fill(random(100)); + ellipse(mouseX,mouseY,30,30); } -**********************************/ \ No newline at end of file + +/********************************* + how to define function: dataType name (parameters- that are not included in code){ + block of code + } + **********************************/ \ No newline at end of file From 7cc96fb5eb575d22fa5183db9079cac59ddce324 Mon Sep 17 00:00:00 2001 From: twang1999 Date: Fri, 4 Dec 2015 13:56:48 -0500 Subject: [PATCH 4/6] added DrawACircle function with adjustable colors --- VoidFunctions/VoidFunctions.pde | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/VoidFunctions/VoidFunctions.pde b/VoidFunctions/VoidFunctions.pde index 3d54a07..9460e94 100644 --- a/VoidFunctions/VoidFunctions.pde +++ b/VoidFunctions/VoidFunctions.pde @@ -1,11 +1,10 @@ -float fill = random(100); void setup() { size(800, 600); } void draw() { DrawABlueSquare(); - DrawACircle(fill); + DrawACircle(100,0,200); } void DrawABlueSquare() { @@ -13,8 +12,8 @@ void DrawABlueSquare() { rect(375, 275, 50, 50); } -void DrawACircle(float fill){ - fill(random(100)); +void DrawACircle(float red, float green, float blue){ + fill(red,green,blue); ellipse(mouseX,mouseY,30,30); } From ab1ceb7ede793f320e7f80d8d78f09b5c4799bb9 Mon Sep 17 00:00:00 2001 From: twang1999 Date: Fri, 4 Dec 2015 14:03:43 -0500 Subject: [PATCH 5/6] added DrawATriangle function --- VoidFunctions/VoidFunctions.pde | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/VoidFunctions/VoidFunctions.pde b/VoidFunctions/VoidFunctions.pde index 9460e94..0a7e697 100644 --- a/VoidFunctions/VoidFunctions.pde +++ b/VoidFunctions/VoidFunctions.pde @@ -5,6 +5,7 @@ void setup() { void draw() { DrawABlueSquare(); DrawACircle(100,0,200); + DrawATriangle(150); } void DrawABlueSquare() { @@ -16,9 +17,14 @@ void DrawACircle(float red, float green, float blue){ fill(red,green,blue); ellipse(mouseX,mouseY,30,30); } + +void DrawATriangle(float d){ + fill(#0DA026); + triangle(40,75,60,20,d,d); +} /********************************* how to define function: dataType name (parameters- that are not included in code){ block of code } - **********************************/ \ No newline at end of file +/**********************************/ \ No newline at end of file From cfb5615b6fe8311def68df0d80f5f9c7a2ac7ae5 Mon Sep 17 00:00:00 2001 From: twang1999 Date: Fri, 4 Dec 2015 14:29:15 -0500 Subject: [PATCH 6/6] sin function --- ReturningValues/ReturningValues.pde | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ReturningValues/ReturningValues.pde b/ReturningValues/ReturningValues.pde index 8b13789..13a8249 100644 --- a/ReturningValues/ReturningValues.pde +++ b/ReturningValues/ReturningValues.pde @@ -1 +1,23 @@ +float theta = 0; +float thetaStart = 0; +float circleSize = 100; +void setup() { + colorMode(HSB, 360, 100, 100, 100); + size(2800, 1200); +} + +void draw() { + theta = thetaStart; + background(0, 0, 100); + stroke(3); + println(sin(theta)); + for (int x = 0; x < width; x += circleSize - 20) { + noStroke(); + fill(map(x, 0, width, 0, 360), 100, 100, 50); + float y = map(sin(theta), -1, 1, height*.25, height*.75); + ellipse(x, y, circleSize, circleSize); + theta += .3; + } + thetaStart += .005; +} \ No newline at end of file