## Wednesday, February 4, 2015

### HP Prime: Pixel Art (Pixel Noise)

And now for a fun experiment:  take a certain function, any functions f(x,y) and g(x,y) where x and y represent the pixels of a calculator screen, and plot their results.  I let x range from 1 to 318 and y range from 1 to 218 and plot the resulting components f(x,y) and g(x,y), respectively, on the screen.  In order to keep all results on the screen, I format the functions like this:

k = f(x,y) MOD 318
j = g(x,y) MOD 218

where pixel coordinate (k,j) gets plotted.  I would like to share some results.  If you are interested, I list all the programs involved with each picture at the end of this blog.  Here is the general format:

// General Format

EXPORT PIX09()
BEGIN
LOCAL x,y,j,k,n,l,s;
// set background color
RECT_P(#0h);
// add a counter if necessary
n:=0;
// list colors (if you want more than one colored pixel - optional)
l:={#FF0000h,#87CEEBh,#FFFF00h,#FF00h};
// main loop
FOR x FROM 1 TO 318 DO
FOR y FROM 1 TO 218 DO
// next two lines needed if l is defined
n:=n+1;
s:=1+n MOD 4;
// k and j represent functions of x and y - they really can be anything
// The MOD 318 and MOD 218 commands are needed to keep the pixels inbound
k:=IP((x^2*y)^3+(x*y^2)^3) MOD 318;
j:=IP(e^(x)+e^(y)) MOD 218;
// draw a pixel
PIXON_P(k,j,l(s));
END;
END;
// this just tells the user "I'm done"
TEXTOUT_P("DONE",0,219,3,#FFFFFFh);
FREEZE;
END;

Enjoy and try this if you want.

Eddie

PIX05:  This looks like mist.

 PIX05
PIX09:  This is what TV looked like at light night before Cable and Satellite TV.  Yes, I just aged myself.
 PIX09

PIX10:
 PIX10

PIX11:
 PIX11

PIX12: Could this be a view of a forest or jungle from a helicopter?

 PIX12

PIX14:  This looks like a fabric pattern.
 PIX14

This blog is property of Edward Shore - 2015.

PROGRAMS:

EXPORT PIX05()
BEGIN
LOCAL x,y,j,k;
RECT_P(#0h);
FOR x FROM 1 TO 318 DO
FOR y FROM 1 TO 218 DO
k:=IP(√x+√y+√(x*y)) MOD 318;
j:=(x^2+y^2+x*y) MOD 218;
PIXON_P(k,j,#87CEEBh);
END;
END;
TEXTOUT_P("DONE",0,219,3,#FFFFFFh);
FREEZE;
END;

EXPORT PIX09()
BEGIN
LOCAL x,y,j,k,n,l,s;
RECT_P(#0h);
n:=0;
l:={#FF0000h,#87CEEBh,#FFFF00h,#FF00h};
// main loop
FOR x FROM 1 TO 318 DO
FOR y FROM 1 TO 218 DO
n:=n+1;
s:=1+n MOD 4;
k:=IP((x^2*y)^3+(x*y^2)^3) MOD 318;
j:=IP(e^(x)+e^(y)) MOD 218;
// draw a pixel
PIXON_P(k,j,l(s));
END;
END;
TEXTOUT_P("DONE",0,219,3,#FFFFFFh);
FREEZE;
END;

EXPORT PIX10()
BEGIN
LOCAL x,y,j,k,n,l,s;
RECT_P(#0h);
n:=0;
l:={#1560BDh,#87CEEBh,#FFFF00h,#9E60h};
FOR x FROM 1 TO 318 DO
FOR y FROM 1 TO 218 DO
n:=n+1;
s:=1+n MOD 4;
k:=IP(e^(x)+2*e^(y)) MOD 318;
j:=IP(2*e^(x)+e^(y)) MOD 218;
PIXON_P(k,j,l(s));
END;
END;
TEXTOUT_P("DONE",0,219,3,#FFFFFFh);
FREEZE;
END;

EXPORT PIX11()
BEGIN
LOCAL x,y,j,k,n,l,s;
RECT_P(#0h);
n:=0;
l:={#C0C0C0h,#FFFFFFh,#D4AF37h,#FFFF00h};
FOR x FROM 1 TO 318 DO
FOR y FROM 1 TO 218 DO
n:=n+1;
s:=1+n MOD 4;
k:=IP(x-y) MOD 318;
j:=IP(−2*e^(x)+.5*e^(y)) MOD 218;
PIXON_P(k,j,l(s));
END;
END;
TEXTOUT_P("DONE",0,219,3,#FFFFFFh);
FREEZE;
END;

EXPORT PIX12()
BEGIN
LOCAL x,y,j,k,n,l,s;
RECT_P(#4000h);
n:=0;
l:={#FFFF00h,#FF00h,#964B00h,#0h};
FOR x FROM 1 TO 318 DO
FOR y FROM 1 TO 218 DO
n:=n+1;
s:=1+n MOD 4;
k:=IP(x*y) MOD 318;
j:=IP(x^2+y^2) MOD 218;
PIXON_P(k,j,l(s));
END;
END;
TEXTOUT_P("DONE",0,219,3,#FFFFFFh);
FREEZE;
END;

EXPORT PIX14()
BEGIN
LOCAL x,y,j,k,n,l,s;
RECT_P(#400000h);
n:=0;
l:={#C0C0C0h,#FFFFCCh,#C0C0C0h,#FFFFCCh};
FOR x FROM 1 TO 318 DO
FOR y FROM 1 TO 218 DO
n:=n+1;
s:=1+n MOD 4;
k:=IP(21800*SIN(x)) MOD 318;
j:=IP(31800*√(y)) MOD 218;
PIXON_P(k,j,l(s));
END;
END;
TEXTOUT_P("DONE",0,219,3,#FFFFFFh);
FREEZE;
END;