Monday, 28 May 2018

Processing drawing using Math.





Code for the final dragrams.

float t=0;

void setup() {
  size(1200, 500);
  background(0);
  //Usingg same formula three time with different constant in tis case 7 and 11
  translate(200,200);
  for(t=0;t<Math.PI*2;t+=0.001){
    float x=cos(t) + cos(7 * t)/2 + sin(11 * t)/3;
    float y=sin(t) + sin(7 * t)/2 + cos(11 * t)/3;
    noStroke();
    color c=color(38,191,250);
    fill(c);
    ellipse(100*x,100*y,3,3);
  }
  
  //here 6 and 14
  resetMatrix();
  translate(600,200);
  
  for(t=0;t<Math.PI*2;t+=0.001){
      float x=cos(t) + cos(6 * t)/2 + sin(14 * t)/3;
      float y=sin(t) + sin(6 * t)/2 + cos(14 * t)/3;
      noStroke();
      color c=color(38,191,250);
      fill(c);
      ellipse(100*x,100*y,3,3);
  }
  // in las one 5 and 15
  resetMatrix();
  translate(1000,200);
  
  for(t=0;t<Math.PI*2;t+=0.001){
      float x=cos(t) + cos(5 * t)/2 + sin(15 * t)/3;
      float y=sin(t) + sin(5 * t)/2 + cos(15 * t)/3;
      noStroke();
      color c=color(38,191,250);
      fill(c);
      ellipse(100*x,100*y,3,3);
  }
}

Friday, 25 May 2018

Simple processing Generative Art/Drawing 4

 




Below is the code to generate the above shown drawing..

float r=0;

void setup() {
  size(400, 400);
  background(0);
  smooth();
  noStroke();
}

void draw() {
  
  if (r>300) {     // To reset the drawing
    fill(0);
    r=0;
    rect(0, 0, width, height);
  }
  rotate(r);
  translate(width/2, height/2); //to bring it to center
  fill(0, random(r, 255), random(r, 255));
  float circle_size= random(5, 15);
  ellipse(100+r, 10, circle_size, circle_size);
  r=r+0.2;
}

Thursday, 24 May 2018

Project Euler Problem 1 Solution in Java- Multiples of 3 and 5

Problem 1


If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.

__________________________________________________________________________________


public class Problem_1 {

  public static void main(String[] args) {

    int n=10;
    int sum=0;
    for (int i=0; i<1000; i++) {
      if (i%3==0)
        sum+=i;
      else
        if (i%5==0)
          sum+=i;
    }
    System.out.println("Sum is "+sum);
  }
}



Answer: Sum is 233168

Tuesday, 8 May 2018

Cafe Wall Illusion using processing




Cafe Wall Illusion

int s=89;
color black=color(0);
color white=color(255);
Line l[];
float update=0;

void setup() {
  size(810, 680);
  stroke(89, 89, 89);
  strokeWeight(2);
  l=new Line[8];

  for (int i=0; i<8; i++) {
    l[i]=new Line(i*90);
  }
}

void draw() {

  for (int i=0; i<8; i++) {
    if (i%2==0)
      l[i].drawL(-270+update);
    else
      l[i].drawL(-270-update);
  }
  update=update+0.5;
  //println(update+"");
  if (update==180)
    update=0;
}

class Line {

  int n=20;
  float posY;

  Line(float posY) {
    this.posY=posY;
  }

  void drawL(float diff) {

    for (int i=0; i<16; i++) {
      float posX=i*90 +diff;
      if (i%2==0) {
        fill(0);
        rect(posX, posY, s, s);
      } else {
        fill(255);
        rect(posX, posY, s, s);
      }
    }
  }
}