Project tutorial
Rotational Symmetry Drawing

Rotational Symmetry Drawing © GPL3+

Use potentiometer inputs from Arduino along with your mouse to control a rotational symmetry drawing program in Processing.

  • 1,353 views
  • 0 comments
  • 8 respects

Components and supplies

About this project

Control a symmetry design sketch in Processing using your mouse and potentiometers as drawing tools. Left click controls penup/pendown and right click clears the screen. Use 3 potentiometer inputs to control the RGB colors of a symmetry design sketch in Processing. Additional design inputs such as number of symmetries and ellipse size are directly coded into the Processing sketch, but could be moved to the Arduino side of the project as well.

////Inputs/////
int rotation = 8;//type in rotational symmetry
color backgroundColor = 255;//type in background color
//int penColor = color(255,0,0);//type in pen color
int xSize = 10;
int ySize = 10;
/////////////// 

The code for this was adapted from Arduino -- Examples -- Communication -- SerialCallResponse.

You can use a breadboard for the potentiometer inputs, but for fun I made a console out of wood and used a screw shield for more secure connections.

Code

Rotational Symmetry Drawing ArduinoArduino
Arudino code to send potentiometer inputs through serial communication.
int potArduino0;
int potArduino1;
int potArduino2;

int inByte = 0;

void setup() {
  Serial.begin(9600);
  establishContact();
}

void loop() {
  if(Serial.available() > 0){
    inByte = Serial.read();
    
    potArduino0 = analogRead(A0)/4;
    Serial.write(potArduino0);
    delay(10);

    potArduino1 = analogRead(A1)/4;
    Serial.write(potArduino1);
    delay(10);

    potArduino2 = analogRead(A2)/4;
    Serial.write(potArduino2);
    delay(10);
  }
}

void establishContact(){
  while(Serial.available() <= 0){
    Serial.println('A');
    delay(300);
  }
}
Rotational Symmetry Drawing ProcessingProcessing
//Right click pen up/down
//Left click clear

////Inputs/////
int rotation = 8;//type in rotational symmetry
color backgroundColor = 255;//type in background color
//int penColor = color(255,0,0);//type in pen color
int xSize = 10;
int ySize = 10;
///////////////

boolean penTool = true;

import processing.serial.*;
Serial myPort;
int[] serialArray = new int[3];
int serialCount = 1;
int red;//serial input A0
int green;//serial input A1
int blue;//serial input A2
int penColor;//type in pen color 
boolean firstContact = false;

void setup() {
  size(500, 500);
  background(backgroundColor);
  noStroke();
  rectMode(CENTER);
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);

  instructions();
}

void instructions() {
  textSize(14);
  textAlign(LEFT);
  fill(0);
  text("Left click - pen up/down", 5, 493);
  textAlign(RIGHT);
  text("Right click - clear screen", 495, 493);
}

void serialEvent(Serial myPort) {
  int inByte = myPort.read();
  //println(inByte);
  if (firstContact == false) {
    if (inByte == 'A') {
      myPort.clear();
      firstContact = true;
      myPort.write('A');
      println('A');
    }
  } else {
    serialArray[serialCount] = inByte;
    serialCount++;
    if(serialCount > 2){
      red = serialArray[0]; 
      println("red: " + red);
      green = serialArray[1]; 
      println("green: " + green);
      blue = serialArray[2]; 
      println("blue: " + blue);
      delay(10);

      myPort.write('A');
      serialCount = 0;
    }
  }
}

void colorCheck(){
  fill(255);
  rect(width/2, 490, 120, 10);
  textAlign(LEFT);
  textSize(10);
  fill(0);
  text("R: " + red, (width/2)-60, 495);
  text("G: " + green, (width/2)-15, 495);
  text("B: " + blue, (width/2)+25, 495);
}

void draw() {
  penColor = color(red,green,blue);
  fill(penColor);
  rect(width/2, 480, 120, 10);
  rotation();//enter the sides in variable above
  colorCheck();
}

void mouseClicked() {
  if (mouseButton == LEFT) {
    penTool = !penTool;
  }
  if (mouseButton == RIGHT) {
    background(color(backgroundColor));
    instructions();
  }
}

void rotation() {
  mouseX -= width/2;
  mouseY -= height/2;

  if (penTool) {
    translate(width/2, height/2);
    for (int i = 0; i < rotation; i++) {
      rotate(2*PI/rotation);
      ellipse(mouseX, mouseY, xSize, ySize);
    }
  }
}

Schematics

Rotational Symmetry Drawing Fritzing
Rotationalsymmetrydrawingfritzing 389ez16rzh

Comments

Similar projects you might like

Drawing with a Laser - Hack-a-Day Logo

Project tutorial by Enrico L

  • 4,841 views
  • 0 comments
  • 5 respects

Graphical Programming Drawing Robot On The Wall

Project tutorial by Team KittenBot

  • 12,405 views
  • 1 comment
  • 45 respects

The Drawing Machine

Project showcase by Kramick Saha

  • 7,623 views
  • 5 comments
  • 18 respects

Crazy Engineer’s Drawing Robot Arduino GRBL CoreXY Drawbot

Project tutorial by Arnab Kumar Das

  • 33,732 views
  • 21 comments
  • 106 respects

Caravaggio, A Drawing Machine

Project showcase by Michele

  • 21,048 views
  • 10 comments
  • 133 respects

Use a hard disk like a rotational input device

Project tutorial by Arduino_Scuola

  • 3,416 views
  • 1 comment
  • 12 respects
Add projectSign up / Login