Giter VIP home page Giter VIP logo

paint-design's Introduction

paint-design

a web app that makes easy to paint designs using kaliedoscope

code explanation

  1. index.html
  2. sketch.js

index.html

making the site respnsive for any device using

 <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi">

importing p5.js library using

<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/addons/p5.sound.min.js"></script>

linking to style.css

 <link rel="stylesheet" type="text/css" href="style.css">

adding script.js

<script src="sketch.js"></script>

sketch.js

creating all required variables

let saveButton, clearButton, mouseButton, keyboardButton;
let slider;
let color;
let slider1;
let colorPicker;

creating canvas

if we want to create any slider or button or colur picker or canvas we hav to put it in function setup() of p5.js

createCanvas(windowWidth, windowHeight);

creating all required things

creating slider for number of reflections

slider1 = createSlider(0, 20, 100);
slider1.position(300, 20);
slider1.style('width', '80px');

creating save button

 saveButton = createButton('save');
 saveButton.mousePressed(saveFile);
saveButton.position(0,10);

and save function

function saveFile() { save('design.png');}

creating clear button

 clearButton = createButton('clear');
  clearButton.mousePressed(clearScreen);
clearButton.position(40,10);

and clear function

function clearScreen() {
  background(127);
}

creating fullscreen

fullscreenButton = createButton('Full Screen');
fullscreenButton.mousePressed(screenFull);
fullscreenButton.position(80,10);

fullscreen function

function screenFull() {
  let fs = fullscreen();
  fullscreen(!fs);
}

creating brush size slider and colour picker

sizeSlider.position(160,20);

  colorPicker = createColorPicker('#000000');

  colorPicker.position(0,40);

  colorPicker.size(100, 50);

making canvas responsive

function windowResized() {

resizeCanvas(windowWidth, windowHeight);

}

making the painting

to make the drawing we have to put it in draw function which is executed repeatedly

let sym = slider1.value();
\\getting the symmetry of mirror effect

  translate(width / 2, height / 2);

  if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {

    let mx = mouseX - width / 2;

    let my = mouseY - height / 2;

    let pmx = pmouseX - width / 2;

    let pmy = pmouseY - height / 2;

    // getting required mouse properties

    if (mouseIsPressed) {
// on mouse pressed creating drawing
      for (let i = 0; i < sym; i++) {
// javascript for loop
        rotate(360/sym);
// rotation of drawing
        let sw = sizeSlider.value();
// getting strokr width
        strokeWeight(sw);

        stroke(colorPicker.color());
// creating colour of the stroke
        line(mx, my, pmx, pmy);
// creating line on mouseX and mouseY
        push();

        scale(1, -1);

        line(mx, my, pmx, pmy);
// creating line isolated in push and pop such that the previous stroke is saved before the later
        pop();

      }

    }

  }

paint-design's People

Contributors

anubhavsingh0708 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.