Coder Social home page Coder Social logo

ishiharamc's Introduction

IshiharaMC

Ishihara Test plates generated using Monte Carlo procedures

It uses a circle intersection algorithm, Jordan's curve theorem, and Monte Carlo placement to create an Ishihara test (Ishihara plate). The image to be created into an Ishihara plate must be an array of points in cartesian coordinates ordered such that the shape is generated in a clockwise fashion. It is assumed that the points are joined by straight lines, and not spline curves (which greatly complicates the mathematics). It is often easiest to increase the number of points in order to best represent the curves, which can usually be done with a vector graphics software (inkscape, etc.).

example code:

import ishiharaMC, scipy
angles = scipy.linspace(0,scipy.pi*2,4)[:3] #don't make the last and first points the same
v = .9
shape1 = scipy.array([v*scipy.cos(angles),v*scipy.sin(angles)]).T
angles += scipy.pi/3
shape2 = scipy.array([v*scipy.cos(angles),v*scipy.sin(angles)]).T
inp = (shape1,shape2)
output = scipy.array(ishiharaMC.createPlate(inp))
idx1 = scipy.logical_xor(ishiharaMC.circinPoly(inp[0],output),ishiharaMC.circinPoly(inp[1],output))
idx2 = scipy.logical_and(ishiharaMC.circinPoly(inp[0],output),ishiharaMC.circinPoly(inp[1],output))

To do simple plotting:

import matplotlib.pyplot as plt
plt.subplot(121)
ishiharaMC.plotIshi(output,color='g')
ishiharaMC.plotIshi(output[idx1],color='r')
ishiharaMC.plotIshi(output[idx2],color='b')
plt.subplot(122)
ishiharaMC.plotIshi(output)
plt.show() 

This should make a 6 pointed star

There is some functionality for setting the paint scheme, but generally logic based off the various objects should be known. Depending on the color scheme, it could be 2 sets of 2 colors, 2 sets of 3 colors, etc.

Output of above codes: alt text

Additional information on the logic of the code can be found at my website: http://ianfaust.com/2016/02/19/Ishihara/

ishiharamc's People

Contributors

icfaust avatar

Watchers

James Cloos 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.