Code Monkey home page Code Monkey logo

paletter's Introduction

paletter

build your palette from a picture
source

###----------- simply-------------------
painting <- readJPEG("sacra_famiglia_canigiani.jpg")
colours_vector <- palette_maker("sacra_famiglia_canigiani.jpg", number_of_colors = numOfcolor)

#-----Input number of color---------
numOfcolor <- 32
#-----------------------------------


# install Kang's basic functions package from the git-hub
if ("devtools" %in% installed.packages()[, "Package"]){cat("devtools is installed")}else(install.packages("devtools"))

devtools::install_github("kasaha1/kasaBasicFunctions")
devtools::install_github("andreacirilloac/paletter")
library(kasaBasicFunctions)
# install Kang's basic functions package from the git-hub
#------------- Packages ----
packages <- c("ggplot2", "dplyr", "readr", "data.table","jpeg","scales","paletter")
kasa.instPak (packages)




# download.file("https://andreacirilloac.github.io/dataviz/images/sacra_famiglia_canigiani.jpg", "image.jpg")
painting     <- readJPEG("sacra_famiglia_canigiani.jpg")

dimension    <- dim(painting)
painting_rgb <- data.frame(
  x = rep(1:dimension[2], each = dimension[1]),
  y = rep(dimension[1]:1, dimension[2]),
  R = as.vector(painting[,,1]), #slicing our array into three
  G = as.vector(painting[,,2]),
  B = as.vector(painting[,,3])
)
k_means        <- kmeans(painting_rgb[,c("R","G","B")], centers = numOfcolor, iter.max = 30)
show_col(rgb(k_means$centers))
rgb(k_means$centers)

#----------- simply-------------------
painting     <- readJPEG("sacra_famiglia_canigiani.jpg")
colours_vector <- palette_maker("sacra_famiglia_canigiani.jpg", number_of_colors = numOfcolor) #### 


# check
# ggplot(data = mtcars, aes(
#   x = disp,
#   y = hp,
#   color = rownames(mtcars)
# ))+geom_point(stat = 'identity', aes(size = cyl))+scale_color_manual(values = colours_vector)+theme_minimal()+geom_text(label = rownames(mtcars),color = 'grey40',check_overlap = TRUE) +  guides(size = FALSE) +  theme(legend.position ="bottom") +  labs(title = "disp vs hp")

paletter's People

Contributors

andreacirilloac avatar kasaha1 avatar

Watchers

 avatar  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.