Components and supplies
Arduino UNO
Jumper wires (generic)
Rotary potentiometer (generic)
Project description
Code
Rotational Symmetry Drawing Processing
processing
1//Right click pen up/down 2//Left click clear 3 4////Inputs///// 5int rotation = 8;//type in rotational symmetry 6color backgroundColor = 255;//type in background color 7//int penColor = color(255,0,0);//type in pen color 8int xSize = 10; 9int ySize = 10; 10/////////////// 11 12boolean penTool = true; 13 14import processing.serial.*; 15Serial myPort; 16int[] serialArray = new int[3]; 17int serialCount = 1; 18int red;//serial input A0 19int green;//serial input A1 20int blue;//serial input A2 21int penColor;//type in pen color 22boolean firstContact = false; 23 24void setup() { 25 size(500, 500); 26 background(backgroundColor); 27 noStroke(); 28 rectMode(CENTER); 29 String portName = Serial.list()[0]; 30 myPort = new Serial(this, portName, 9600); 31 32 instructions(); 33} 34 35void instructions() { 36 textSize(14); 37 textAlign(LEFT); 38 fill(0); 39 text("Left click - pen up/down", 5, 493); 40 textAlign(RIGHT); 41 text("Right click - clear screen", 495, 493); 42} 43 44void serialEvent(Serial myPort) { 45 int inByte = myPort.read(); 46 //println(inByte); 47 if (firstContact == false) { 48 if (inByte == 'A') { 49 myPort.clear(); 50 firstContact = true; 51 myPort.write('A'); 52 println('A'); 53 } 54 } else { 55 serialArray[serialCount] = inByte; 56 serialCount++; 57 if(serialCount > 2){ 58 red = serialArray[0]; 59 println("red: " + red); 60 green = serialArray[1]; 61 println("green: " + green); 62 blue = serialArray[2]; 63 println("blue: " + blue); 64 delay(10); 65 66 myPort.write('A'); 67 serialCount = 0; 68 } 69 } 70} 71 72void colorCheck(){ 73 fill(255); 74 rect(width/2, 490, 120, 10); 75 textAlign(LEFT); 76 textSize(10); 77 fill(0); 78 text("R: " + red, (width/2)-60, 495); 79 text("G: " + green, (width/2)-15, 495); 80 text("B: " + blue, (width/2)+25, 495); 81} 82 83void draw() { 84 penColor = color(red,green,blue); 85 fill(penColor); 86 rect(width/2, 480, 120, 10); 87 rotation();//enter the sides in variable above 88 colorCheck(); 89} 90 91void mouseClicked() { 92 if (mouseButton == LEFT) { 93 penTool = !penTool; 94 } 95 if (mouseButton == RIGHT) { 96 background(color(backgroundColor)); 97 instructions(); 98 } 99} 100 101void rotation() { 102 mouseX -= width/2; 103 mouseY -= height/2; 104 105 if (penTool) { 106 translate(width/2, height/2); 107 for (int i = 0; i < rotation; i++) { 108 rotate(2*PI/rotation); 109 ellipse(mouseX, mouseY, xSize, ySize); 110 } 111 } 112}
Rotational Symmetry Drawing Processing
processing
1//Right click pen up/down 2//Left click clear 3 4////Inputs///// 5int rotation = 8;//type in rotational symmetry 6color backgroundColor = 255;//type in background color 7//int penColor = color(255,0,0);//type in pen color 8int xSize = 10; 9int ySize = 10; 10/////////////// 11 12boolean penTool = true; 13 14import processing.serial.*; 15Serial myPort; 16int[] serialArray = new int[3]; 17int serialCount = 1; 18int red;//serial input A0 19int green;//serial input A1 20int blue;//serial input A2 21int penColor;//type in pen color 22boolean firstContact = false; 23 24void setup() { 25 size(500, 500); 26 background(backgroundColor); 27 noStroke(); 28 rectMode(CENTER); 29 String portName = Serial.list()[0]; 30 myPort = new Serial(this, portName, 9600); 31 32 instructions(); 33} 34 35void instructions() { 36 textSize(14); 37 textAlign(LEFT); 38 fill(0); 39 text("Left click - pen up/down", 5, 493); 40 textAlign(RIGHT); 41 text("Right click - clear screen", 495, 493); 42} 43 44void serialEvent(Serial myPort) { 45 int inByte = myPort.read(); 46 //println(inByte); 47 if (firstContact == false) { 48 if (inByte == 'A') { 49 myPort.clear(); 50 firstContact = true; 51 myPort.write('A'); 52 println('A'); 53 } 54 } else { 55 serialArray[serialCount] = inByte; 56 serialCount++; 57 if(serialCount > 2){ 58 red = serialArray[0]; 59 println("red: " + red); 60 green = serialArray[1]; 61 println("green: " + green); 62 blue = serialArray[2]; 63 println("blue: " + blue); 64 delay(10); 65 66 myPort.write('A'); 67 serialCount = 0; 68 } 69 } 70} 71 72void colorCheck(){ 73 fill(255); 74 rect(width/2, 490, 120, 10); 75 textAlign(LEFT); 76 textSize(10); 77 fill(0); 78 text("R: " + red, (width/2)-60, 495); 79 text("G: " + green, (width/2)-15, 495); 80 text("B: " + blue, (width/2)+25, 495); 81} 82 83void draw() { 84 penColor = color(red,green,blue); 85 fill(penColor); 86 rect(width/2, 480, 120, 10); 87 rotation();//enter the sides in variable above 88 colorCheck(); 89} 90 91void mouseClicked() { 92 if (mouseButton == LEFT) { 93 penTool = !penTool; 94 } 95 if (mouseButton == RIGHT) { 96 background(color(backgroundColor)); 97 instructions(); 98 } 99} 100 101void rotation() { 102 mouseX -= width/2; 103 mouseY -= height/2; 104 105 if (penTool) { 106 translate(width/2, height/2); 107 for (int i = 0; i < rotation; i++) { 108 rotate(2*PI/rotation); 109 ellipse(mouseX, mouseY, xSize, ySize); 110 } 111 } 112}
Rotational Symmetry Drawing Arduino
arduino
Arudino code to send potentiometer inputs through serial communication.
1int potArduino0; 2int potArduino1; 3int potArduino2; 4 5int inByte = 0; 6 7void setup() { 8 Serial.begin(9600); 9 establishContact(); 10} 11 12void loop() { 13 if(Serial.available() > 0){ 14 inByte = Serial.read(); 15 16 potArduino0 = analogRead(A0)/4; 17 Serial.write(potArduino0); 18 delay(10); 19 20 potArduino1 = analogRead(A1)/4; 21 Serial.write(potArduino1); 22 delay(10); 23 24 potArduino2 = analogRead(A2)/4; 25 Serial.write(potArduino2); 26 delay(10); 27 } 28} 29 30void establishContact(){ 31 while(Serial.available() <= 0){ 32 Serial.println('A'); 33 delay(300); 34 } 35} 36 37
Downloadable files
Rotational Symmetry Drawing Fritzing
Rotational Symmetry Drawing Fritzing
Rotational Symmetry Drawing Fritzing
Rotational Symmetry Drawing Fritzing
Comments
Only logged in users can leave comments
eschulzpsd
0 Followers
•0 Projects
Table of contents
Intro
3
0