How to Create a Prime Number Image in Mathematica?

Click For Summary
SUMMARY

This discussion focuses on creating a visual representation of prime numbers using Mathematica. The user aims to generate an image where prime numbers from 1 to 480,000 are displayed as white cells, while non-prime numbers are black. The final output should be formatted into an 800x600 pixel grid. The provided code snippet utilizes the Graphics and Raster functions in Mathematica to achieve this visualization.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of prime number generation using PrimeQ function
  • Knowledge of image rendering concepts in Mathematica
  • Basic grasp of 2D array manipulation and graphics functions
NEXT STEPS
  • Explore advanced graphics techniques in Mathematica
  • Learn about optimizing performance for large data visualizations in Mathematica
  • Investigate alternative methods for prime number generation
  • Study the Image function in Mathematica for further image processing
USEFUL FOR

This discussion is beneficial for Mathematica users, data visualization enthusiasts, and anyone interested in prime number analysis and graphical representation of mathematical concepts.

RyanJ
Messages
17
Reaction score
6
Hey guys!

Basically I have a table of prime numbers. What is to write this table as an image - from 1 too 480000 - showing each cell that is a prime as white and the others as black.

So basically I'm cycling the numbers from 1-480000 and if they are prime then I want the cell white and otherwise black. I also want to be able to wrap the table to 800x600 pixels.

Any help appreciated since I have no idea how to do this!
 
Physics news on Phys.org
With[{w = 800, h = 600},
Graphics[Raster[
Table[Boole[PrimeQ[w i + j + 1]], {i, 0, h - 1}, {j, 0, w - 1}]]]]
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K