• Guest
HabraHabr
  • Main
  • Users

  • Development
    • Programming
    • Information Security
    • Website development
    • JavaScript
    • Game development
    • Open source
    • Developed for Android
    • Machine learning
    • Abnormal programming
    • Java
    • Python
    • Development of mobile applications
    • Analysis and design of systems
    • .NET
    • Mathematics
    • Algorithms
    • C#
    • System Programming
    • C++
    • C
    • Go
    • PHP
    • Reverse engineering
    • Assembler
    • Development under Linux
    • Big Data
    • Rust
    • Cryptography
    • Entertaining problems
    • Testing of IT systems
    • Testing Web Services
    • HTML
    • Programming microcontrollers
    • API
    • High performance
    • Developed for iOS
    • CSS
    • Industrial Programming
    • Development under Windows
    • Image processing
    • Compilers
    • FPGA
    • Professional literature
    • OpenStreetMap
    • Google Chrome
    • Data Mining
    • PostgreSQL
    • Development of robotics
    • Visualization of data
    • Angular
    • ReactJS
    • Search technologies
    • Debugging
    • Test mobile applications
    • Browsers
    • Designing and refactoring
    • IT Standards
    • Solidity
    • Node.JS
    • Git
    • LaTeX
    • SQL
    • Haskell
    • Unreal Engine
    • Unity3D
    • Development for the Internet of things
    • Functional Programming
    • Amazon Web Services
    • Google Cloud Platform
    • Development under AR and VR
    • Assembly systems
    • Version control systems
    • Kotlin
    • R
    • CAD/CAM
    • Customer Optimization
    • Development of communication systems
    • Microsoft Azure
    • Perfect code
    • Atlassian
    • Visual Studio
    • NoSQL
    • Yii
    • Mono и Moonlight
    • Parallel Programming
    • Asterisk
    • Yandex API
    • WordPress
    • Sports programming
    • Lua
    • Microsoft SQL Server
    • Payment systems
    • TypeScript
    • Scala
    • Google API
    • Development of data transmission systems
    • XML
    • Regular expressions
    • Development under Tizen
    • Swift
    • MySQL
    • Geoinformation services
    • Global Positioning Systems
    • Qt
    • Dart
    • Django
    • Development for Office 365
    • Erlang/OTP
    • GPGPU
    • Eclipse
    • Maps API
    • Testing games
    • Browser Extensions
    • 1C-Bitrix
    • Development under e-commerce
    • Xamarin
    • Xcode
    • Development under Windows Phone
    • Semantics
    • CMS
    • VueJS
    • GitHub
    • Open data
    • Sphinx
    • Ruby on Rails
    • Ruby
    • Symfony
    • Drupal
    • Messaging Systems
    • CTF
    • SaaS / S+S
    • SharePoint
    • jQuery
    • Puppet
    • Firefox
    • Elm
    • MODX
    • Billing systems
    • Graphical shells
    • Kodobred
    • MongoDB
    • SCADA
    • Hadoop
    • Gradle
    • Clojure
    • F#
    • CoffeeScript
    • Matlab
    • Phalcon
    • Development under Sailfish OS
    • Magento
    • Elixir/Phoenix
    • Microsoft Edge
    • Layout of letters
    • Development for OS X
    • Forth
    • Smalltalk
    • Julia
    • Laravel
    • WebGL
    • Meteor.JS
    • Firebird/Interbase
    • SQLite
    • D
    • Mesh-networks
    • I2P
    • Derby.js
    • Emacs
    • Development under Bada
    • Mercurial
    • UML Design
    • Objective C
    • Fortran
    • Cocoa
    • Cobol
    • Apache Flex
    • Action Script
    • Joomla
    • IIS
    • Twitter API
    • Vkontakte API
    • Facebook API
    • Microsoft Access
    • PDF
    • Prolog
    • GTK+
    • LabVIEW
    • Brainfuck
    • Cubrid
    • Canvas
    • Doctrine ORM
    • Google App Engine
    • Twisted
    • XSLT
    • TDD
    • Small Basic
    • Kohana
    • Development for Java ME
    • LiveStreet
    • MooTools
    • Adobe Flash
    • GreaseMonkey
    • INFOLUST
    • Groovy & Grails
    • Lisp
    • Delphi
    • Zend Framework
    • ExtJS / Sencha Library
    • Internet Explorer
    • CodeIgniter
    • Silverlight
    • Google Web Toolkit
    • CakePHP
    • Safari
    • Opera
    • Microformats
    • Ajax
    • VIM
  • Administration
    • System administration
    • IT Infrastructure
    • *nix
    • Network technologies
    • DevOps
    • Server Administration
    • Cloud computing
    • Configuring Linux
    • Wireless technologies
    • Virtualization
    • Hosting
    • Data storage
    • Decentralized networks
    • Database Administration
    • Data Warehousing
    • Communication standards
    • PowerShell
    • Backup
    • Cisco
    • Nginx
    • Antivirus protection
    • DNS
    • Server Optimization
    • Data recovery
    • Apache
    • Spam and antispam
    • Data Compression
    • SAN
    • IPv6
    • Fidonet
    • IPTV
    • Shells
    • Administering domain names
  • Design
    • Interfaces
    • Web design
    • Working with sound
    • Usability
    • Graphic design
    • Design Games
    • Mobile App Design
    • Working with 3D-graphics
    • Typography
    • Working with video
    • Work with vector graphics
    • Accessibility
    • Prototyping
    • CGI (graphics)
    • Computer Animation
    • Working with icons
  • Control
    • Careers in the IT industry
    • Project management
    • Development Management
    • Personnel Management
    • Product Management
    • Start-up development
    • Managing the community
    • Service Desk
    • GTD
    • IT Terminology
    • Agile
    • Business Models
    • Legislation and IT-business
    • Sales management
    • CRM-systems
    • Product localization
    • ECM / EDS
    • Freelance
    • Venture investments
    • ERP-systems
    • Help Desk Software
    • Media management
    • Patenting
    • E-commerce management
    • Creative Commons
  • Marketing
    • Conferences
    • Promotion of games
    • Internet Marketing
    • Search Engine Optimization
    • Web Analytics
    • Monetize Web services
    • Content marketing
    • Monetization of IT systems
    • Monetize mobile apps
    • Mobile App Analytics
    • Growth Hacking
    • Branding
    • Monetize Games
    • Display ads
    • Contextual advertising
    • Increase Conversion Rate
  • Sundry
    • Reading room
    • Educational process in IT
    • Research and forecasts in IT
    • Finance in IT
    • Hakatonas
    • IT emigration
    • Education abroad
    • Lumber room
    • I'm on my way

How to create procedural art in less than 100 lines of code

 3r33312. 3r3-31. How to create procedural art in less than 100 lines of code
3r33300.  3r33312.

What is generative art? 3r33232. 3r33300.  3r33312. This is the result of a system that makes its own decisions about the subject instead of the person. A system can be as simple as a single Python program, if it has rules and a moment of randomness. 3r33300.  3r33312. 3r33300.  3r33312. With programming, it's pretty easy to come up with rules and restrictions. For this there are conditional operators. But finding ways to make these rules create something interesting may not be so easy. 3r33300.  3r33312. 3r33300.  3r33312. Conway’s Game of Life [/i] 3r33300.  3r33312. 3r33300.  3r33312. 3r3334. The game "Life"
(Conway’s Game of Life) is a well-known set of four simple rules defining the “birth” and “death” of each cell in the system. Each rule plays a role in advancing the system through each generation. Although the rules are simple and easy to understand, complex patterns quickly emerge that ultimately form exciting results. 3r33300.  3r33312. 3r33300.  3r33312. The rules may be responsible for creating the basics of something interesting, but even something as exciting as Conway’s Game of Life is predictable. Four rules are the determining factors for each generation. Therefore, in order to obtain unexpected results, you must enter a randomization in the initial state of the cells. Starting with a random matrix, each execution will be unique without the need to change the rules. 3r33300.  3r33312. 3r33300.  3r33312. The best examples of generative art are those that find a combination of predictability and chance to create something interesting that is statistically impossible to repeat. 3r33300.  3r33312. 3r33300.  3r33312.
Why should you try this? 3r33232. 3r33300.  3r33312. Generative art will not always be what you want to spend time on. But if you decide to work on it, then you can count on the following benefits: 3r-3300.  3r33312. 3r33300.  3r33312.
 3r33312.
Experience. Generative art is another opportunity to hone new and old skills. It can serve as an input for working out such concepts as algorithms, data structures, and even new languages. 3r3365.  3r33312.
Tangible results. In programming, we rarely see the physical results of our efforts. Well, or at least I don't see it. Right now in my living room there are several posters with prints of my procedural art. And I love that this is done by code. 3r3365.  3r33312.
Attractive designs. Everyone had the experience of explaining a personal project to someone, perhaps even during an interview. Generative art speaks for itself. Most people will appreciate the results, even if they cannot fully understand the methods. 3r3365.  3r33312.
3r33300.  3r33312.
Where to begin? 3r33232. 3r33300.  3r33312. Getting started with generative art is the same process as starting work with any other project. The most important step is to come up with an idea or find it for further development. As soon as you have a goal, you can start working on achieving it. 3r33300.  3r33312. 3r33300.  3r33312. Most of my creative projects are done in Python. It is a fairly simple language with many useful packages that help in image processing. For example, Pillow . 3r33300.  3r33312. 3r33300.  3r33312. Fortunately, you don’t need to search for a long time where to start - I’ll share my code below. 3r33300.  3r33312. 3r33300.  3r33312.
Sprite Generator 3-333299. 3r33300.  3r33312. This project started when I saw a post with a sprite generator written in jаvascript. The program created 5 × 5 pixel-art sprites with random color choices, and its result resembled multi-colored space invaders. 3r33300.  3r33312. 3r33300.  3r33312. I wanted to practice image processing in Python, so I decided to recreate this concept on my own. In addition, I thought that I could expand it, since the original project was severely limited in size of sprites. And I want to specify not only the size of the sprites, but also their number and even the size of the image. 3r33300.  3r33312. 3r33300.  3r33312. Here are two different results of my program:
 3r33312. 3r33300.  3r33312. 3r3104. 3r33300.  3r33312. 7x7–30–1900 3r33300.  3r33312. 3r33300.  3r33312. 3r3113. 3r33300.  3r33312. 43x43–6–1900 3r3–3289. 3r33300.  3r33312. 3r33300.  3r33312. These two images are completely different from each other, but they are both the results of the same system. Not to mention the fact that, due to the complexity and random generation of sprites, there is a high probability that even with the same arguments, these images will forever remain unique. I love it. 3r33300.  3r33312. 3r33300.  3r33312.
Environment

3r33300.  3r33312. Before meeting with the generator of sprites should prepare a small foundation for the work. 3r33300.  3r33312. 3r33300.  3r33312. If you haven't worked with Python before, download Python ??? . At first I had problems with setting up the environment, if you come across them too - look at 3r3136. virtual environments
. And make sure Pillow also installed. 3r33300.  3r33312. 3r33300.  3r33312. After setting up the environment, you can copy my code to a file with a extension. .py and run the following command: 3r300.  3r33312. 3r33300.  3r33312. 3r33170. 3r3171. python spritething.py[SPRITE_DIMENSIONS] [NUMBER] [IMAGE_SIZE]
3r33300.  3r33312. For example, the command to create the first matrix of sprites would be: 3r300.  3r33312. 3r33300.  3r33312. 3r33170. 3r3171. python spritething.py ???
3r33300.  3r33312.

Code

3r33300.  3r33312. 3r33170. 3r3171. import PIL, random, sys
from PIL import Image, ImageDraw
origDimension = 1500
r = lambda: random.randint (???)
rc = lambda: (r (), r (), r ())
listSym =[]3r33312. def create_square (border, draw, randColor, element, size):
if (element == int (size /2)):
draw.rectangle (border, randColor)
elif (len (listSym) == element + 1):
draw.rectangle (border, listSym.pop ())
else:
listSym.append (randColor)
draw.rectangle (border, randColor)
def create_invader (border, draw, size):
x? y? x? y1 = border
squareSize = (x1-x0) /size
randColors =[rc(), rc(), rc(), (0,0,0), (0,0,0), (0,0,0)]3r33312. i = 1r3r3312. for y in range (? size):
I * = -1
element = 0
for x in range (? size):
topLeftX = x * squareSize + x0
topLeftY = y * squareSize + y0
botRightX = topLeftX + squareSize
botRightY = topLeftY + squareSize
create_square ((topLeftX, topLeftY, botRightX, botRightY), draw, random.choice (randColors), element, size)
if (element == int (size /2) or element == 0): 3r3333312. I * = -1; 3r33312. element + = I
def main (size, invaders, imgSize):
origDimension = imgSize
origImage = Image.new (‘RGB’, (origDimension, origDimension))
draw = ImageDraw.Draw (origImage)
invaderSize = origDimension /invaders
padding = invaderSize /size
for x in range (? invaders):
for y in range (? invaders):
topLeftX = x * invaderSize + padding /2
topLeftY = y * invaderSize + padding /2
botRightX = topLeftX + invaderSize - padding
botRightY = topLeftY + invaderSize - padding
create_invader ((topLeftX, topLeftY, botRightX, botRightY), draw, size)
origImage.save (“Examples /Example -“ + str (size) + "x" + str (size) + "-" + str (invaders) + "-" + str (imgSize) + ". jpg") 3r33312. if __name__ == "__main__":
main (int (sys.argv[1]), int (sys.argv[2]), int (sys.argv[3]))
3r33300.  3r33312. This solution is far from perfect, but it shows that the creation of generative art does not require a ton of code. I will explain the key points. 3r33300.  3r33312. 3r33300.  3r33312. The main function starts with creating the original image and determining the size of the sprites. Two cycles for they are responsible for determining the boundary of each sprite, basically dividing the image size by the number of requested sprites. These values ​​are used to determine the coordinates for each of them. 3r33300.  3r33312. 3r33300.  3r33312. Look at the image below. Imagine that each of the four squares is a sprite with a size of 1. The border, which is passed to the next function, refers to the coordinates of the upper left and lower right corners. So the tuple in the upper left sprite will be (???1), and the tuple in the upper right will be (???1). They will be used as dimensions and base coordinates for the squares of each sprite. 3r33300.  3r33312. 3r33300.  3r33312. An example of determining the boundaries of the sprite
3r33300.  3r33312. 3r33300.  3r33312. Function create_invader defines the border for each square inside the sprite. The same boundary determination process is applied here and is presented below, only instead of the full image we use a predefined boundary for working inside. These final coordinates for each square will be used in the next function to draw the sprite. 3r33300.  3r33312. 3r33300.  3r33312. An example of the breakdown of the sprite 3 × 3 [/i] 3r33300.  3r33312. 3r33300.  3r33312. To determine the color, a simple array of three random RGB tuples and three black ones is used to simulate a 50% chance of being drawn. Lambda functions at the top of the code are responsible for generating RGB values. 3r33300.  3r33312. 3r33300.  3r33312. The real trick of this feature is the creation of symmetry. Each square is associated with the value of the element. The figure below shows how the values ​​of the elements increase as they reach the center, and then decrease. Squares with matching element values ​​are displayed in one color. 3r33300.  3r33312. 3r33300.  3r33312. Element values ​​and symmetrical colors for the line in the sprite 7 × 7 [/i] 3r33300.  3r33312. 3r33300.  3r33312. Since create_square gets its parameters from create_invader , it uses the queue and the previous values ​​of the elements to ensure symmetry. When values ​​first appear, their colors are placed in a queue, and mirror squares remove colors. 3r33300.  3r33312. 3r33300.  3r33312. The complete process of creating [/i] 3r33300.  3r33312. 3r33300.  3r33312. I understand how difficult it is to read someone else’s solution to the problem and the code curve, but I hope that you will find use for it. It will be cool if you completely abandon my code and find a completely different solution. 3r33300.  3r33312. 3r33300.  3r33312.
Conclusion 3r3299. 3r33300.  3r33312. Generative art takes time to reach its full potential. In general, there may be more useful projects around than generative art, which is not always worth spending time on. But it's very fun and you never know where it might come in handy. 3r3308. 3r33312. 3r33312. 3r3305. ! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e. ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r3306. 3r33312. 3r3308. 3r33312. 3r33312. 3r33312. 3r33312.

It may be interesting

  • Comments
  • About article
  • Similar news
This publication has no comments.

weber

Author

8-11-2018, 14:32

Publication Date

Python / Image processing / Programming

Category
  • Comments: 0
  • Views: 490
What I don't like in C and C ++
Video from Android Kolesa Mobile: about
Models Sequence-to-Sequence Part 1
Splunk. Easy Troubleshooting
Digital events in Moscow from October
"The devil pulled me to go to work in
Write a comment
Name:*
E-Mail:


Comments
Wow Tastic UK offers a huge range of toys, presents, and gadgets for kids and adults. Discover our great range of fun and unusual toys for baby and toddlers. Check Out: Gadgets for Kids
Today, 19:21

noorseo

Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiraopencarttion, both of which I need, thanks to offer such a helpful information here.

Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
메리트카지노

Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.

메리트카지노
Today, 18:33

taxiseo2

This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.

opencart eticaret

This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.

메리트카지노
Today, 18:27

taxiseo2

I really loved reading your blog. It was very well authored and easy to undertand. Unlike additional blogs I have read which are really not tht good. I also found your posts very interesting. In fact after reading. I had to go show it to my friend and he ejoyed it as well!seo toronto



Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you. [Url = https: //mtsoul.net] 먹튀 검증 [/ url]

Today, 16:41

raymond weber

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.먹튀검증

Today, 15:58

raymond weber

Adv
Website for web developers. New scripts, best ideas, programming tips. How to write a script for you here, we have a lot of information about various programming languages. You are a webmaster or a beginner programmer, it does not matter, useful articles will help to make your favorite business faster.

Login

Registration Forgot password