Showing posts with label pixels. Show all posts
Showing posts with label pixels. Show all posts

Saturday, July 20, 2019

TI Nspire CX II and TI Nspire CX II CAS: User Input in Graphics Mode with getKey

TI Nspire CX II  and TI Nspire CX II CAS:  User Input in Graphics Mode with getKey

Introduction

In graphics mode, the TI Nspire CX II cannot use the Text, Request, or RequestStr.  However, with the use of getKey command, we can have the user interact with the program. 

TI Nspire CX II Program keydemo2

This program is a game where the user stops a spinner in hopes to win money or a car.  Good luck!

Define keydemo2()=
Prgm
:Clear 
:Local l,str,k,n
:l:={"$200","$300","$500","$1000","CAR","Nope."}
:While getKey(0)≠"enter"
:  Clear 
:  UseBuffer 
:© get key continous execution
:  n:=randInt(1,6)
:  SetColor 0,0,0
:  DrawText 50,25,"PRESS enter TO STOP"
:  If n≤5 Then
:    SetColor 0,128,128
:  Else
:    SetColor 255,0,0
:  EndIf
:© use square brackets for elements 
:© we can clear only dynamic areas
:© but it does not look good
:  DrawText 50,50,l[n]
:  PaintBuffer 
:© usebuffer and paintbuffer allows all objects to be displayed at once, ensuring a smooth transition, can also use wait
:EndWhile
:EndPrgm



TI Nspire CX II Program enterdemo

With the use of getKey, the user enters a number in graphics mode.  This can be used as a template. 

Define enterdemo()=
Prgm
:© goal: develop input in graphics mode
:© use float mode
:setMode(1,1)
:Local str,num,k
:str:=""
:© use initial text
:Clear 
:  SetColor 0,0,0
:  DrawText 0,50,"Press [enter] to stop."
:
:
:© main loop: enter the numbers
:Loop
:  Clear 
:  UseBuffer 
:  SetColor 0,0,0
:  DrawText 0,50,"Press [enter] to stop."
:
:  k:=getKey(1)
:  If k="." and inString(str,".")=0 Then
:    str:=str&"."
:  ElseIf k="0" Then
:    str:=str&"0"
:  ElseIf k="1" Then
:    str:=str&"1"
:  ElseIf k="2" Then
:    str:=str&"2"
:  ElseIf k="3" Then
:    str:=str&"3"
:  ElseIf k="4" Then
:    str:=str&"4"
:  ElseIf k="5" Then
:    str:=str&"5"
:  ElseIf k="6" Then
:    str:=str&"6"
:  ElseIf k="7" Then
:    str:=str&"7"
:  ElseIf k="8" Then
:    str:=str&"8"
:  ElseIf k="9" Then
:    str:=str&"9"
:  ElseIf k="−" Then
:    str:=string(−1*expr(str))
:  ElseIf k="del" and dim(str)>0 Then
:    str:=left(str,dim(str)-1)
:
:  ElseIf k="enter" Then
:© "lock" the number and leave
:  SetColor 0,0,0
:  DrawText 0,100,str
:  PaintBuffer 
:    Exit
:  EndIf
:
:SetColor 0,0,255
:DrawText 0,100,str
:PaintBuffer 
:
:EndLoop
:© return number to home
:num:=expr(str)
:Disp num
:EndPrgm



There are two ways the getKey command can be used in graphics mode.

Eddie

All original content copyright, © 2011-2019.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Friday, July 19, 2019

TI Nspire CX II and TI Nspire CX II CAS: Drawing Demo

TI Nspire CX II  and TI Nspire CX II CAS:  Drawing Demo

Introduction

The new TI Nspire CX II  and TI Nspire CX II CAS has an expanded library of programming commands.  We are now able to draw and place text anywhere on the screen. 

When a drawing command is used, the Nspire shifts into graphics mode.  The graphics screen is treated as a final output screen.  Graphics mode only executes in one of two places:

*  Running the program in a Calculator page in a document
*  Running the program in the Calculator part of the Sketchpad

When a graphics screen has an initial (and maximum) height of 212 pixels and an initial (and maximum) width of 318 pixels.  The default background is white. 

Shifting a Program to Graphics Mode

The Nspire shifts into graphics mode automatically any time a drawing command is executed.  Followed by their basic syntax, the commands are:

Clear (blank to clear the entire screen),  (x, y, width, height)

DrawArc  x, y, width, height, startAngle, sweepAngle

DrawCircle x, y, radius

DrawLine x1, y1, x2, y2

DrawPoly (see plotdemo2 for further details)

DrawRect upper_x_pixel, upper_y_pixel, width, height

DrawText x, y, string/text/expression

FillArc x, y, width, height, startAngle, sweepAngle

FillCircle x, y, radius

FillPoly (see plotdemo2 for further details)

FillRect upper_x_pixel, upper_y_pixel, width, height

getPlatform() (returns dt for desktop, hh for handheld, ios for the iOS App)

PaintBuffer  (buffers the paint screen)

PlotXY x, y, shape  (13 shapes available: 1 for dot, 5 for cross, 6 for plus, 8, for medium dot)

SetColor  red, green, blue    (sets the Nspire's color pen)

SetPen thickness, style  (1 thin, 2 medium, 3 thick; 1 smooth, 2, dotted, 3 dashed)

SetWidnow xMin, xMax, yMin, yMax  (establishes drawing area - use this command to switch coordinates to Cartesian)

UseBuffer  (tells the Nspire to use an off screen to draw objects, then use
PaintBuffer to call them back up)

Once graphics mode is entered, the following commands cannot be used:

Request
RequestStr
Text

This means if you want the user to able to input during graphics mode, you will need to use Getkey.

When the Graphics Is Displayed

The graphics will be displayed until the user presses [ enter ]. 

Caution:   The drawing commands are only available for the CX II.  The original CX, nor any previous incarnations of the TI Nspire will not have these commands. 

TI NSpire CX II Program plotdemo1

This demo shows all the possible shapes that PlotXY has.  Colors are set randomly. 

Define plotdemo1()=
Prgm
:© graphics uses pixels: 318 * 212
:© Plotxy demo
:Local r,g,b,n,x,y
:For n,1,13
:© set colors
:r:=randInt(0,255)
:g:=randInt(0,255)
:b:=randInt(0,255)
:SetColor r,g,b
:© draw text and points
:DrawText 1+22*n,40,n
:PlotXY 5+22*n,50,n
:EndFor
:EndPrgm



TI NSpire CX II Program plotdemo2

This demo draws filled polygons.  There are two syntax sets for DrawPoly and FillPoly:

Draw/FillPoly  x1, y1, x2, y2, ... ,xn, yn

With this format the polygon stops at the coordinate (xn, yn).  The polygon is not automatically completed under this format.  To complete the polygon, make sure that the coordinate (x1, y1) is the last two coordinates listed.

Draw/FillPoly x_coordinate_list, y_coordinate_list

With this format, the polygon is automatically completed.

Define plotdemo2()=
Prgm
:© draw four triangles, filled
:Clear 
:© draw background box - gray
:© use fill, no draw
:SetColor 128,128,128
:FillRect 0,0,212,212
:© remember: x,y,width,height
:
:© now the triangles
:SetColor 128,0,0
:FillPoly 56,0,106,106,156,0
:FillPoly 56,212,106,106,156,212
:SetColor 127,255,255
:FillPoly 0,56,106,106,0,156
:FillPoly 212,56,106,106,212,156
:EndPrgm



TI Nspire CX II Program plotdemo3

This demo draws the function y = 1.5 cos (x^2).  The angle is set to radians mode.  The coordinates are converted to pixels prior to plotting them.

Define plotdemo3()=
Prgm
:© draw y=1.5cos(x^((2)))
:Clear 
:© radians
:setMode(2,1)
:© denim color
:SetColor 16,36,192
:© main
:Local x,xs,xp,y,ys,yp
:xs:=((4*π)/(319))
:ys:=((4)/(213))
:For x,−2*π,2*π,xs
:  y:=1.5*cos(x^(2))
:  xp:=((x+2*π)/(xs))
:  yp:=((−(y-2))/(ys))
:  DrawText 10,10,xp
:  PlotXY xp,yp,1
:EndFor
:EndPrgm

TI Nspire CX II Program plotdemo5

Like in plotdemo3, this program draws y = 1.5 cos (x^2).  Instead of converting coordinates to pixels, SetWindow is used and adjust the coordinates so that Cartesian coordinates can be used. 

Define plotdemo5()=
Prgm
:© draw y=1.5cos(x^((2)))
:Clear 
:© radians
:setMode(2,1)
:© denim color
:SetColor 16,36,192
:© main
:Local x,xs,y,ys
:© only x scaling is necesary
:xs:=((4*π)/(319))
:SetWindow −2*π,2*π,−2,2
:© changes pixels to Cartesian
:For x,−2*π,2*π,xs
:  y:=1.5*cos(x^(2))
:  PlotXY x,y,1
:EndFor
:
:EndPrgm



This is a basic demonstration of drawing with the TI Nspire CX II.  On the next post, I show how to use getKey in graphics mode.

Happy drawing,

Eddie


All original content copyright, © 2011-2019.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Monday, September 3, 2018

Mathematical Art: TI-84 Plus CE


Mathematical Art:  TI-84 Plus CE


Pixel art generated with the TI-84 Plus CE.  The program is listed below each picture.




Radian:FnOff 

ClrDraw:ZStandard
For(A,­10,10,.1)
For(B,­10,10,.1)

fPart((A^2+B^2)/2)→C
If C=0
Then
Pt-On(A,B,1,BLUE)
Else
Pt-On(A,B,1,RED)
End

End
End


Radian:FnOff 
ClrDraw:ZStandard
For(A,­10,10,.1)
For(B,­10,10,.1)


fPart(sin(A)*cos(B)+cos(A)*sin(B))→C
If 0≤C and C<.25
Then
Pt-On(A,B,1,BLUE)
End
If .25<C and C≤.5
Then
Pt-On(A,B,1,YELLOW)
End

End
End



Radian:FnOff 
ClrDraw:ZStandard
For(A,­10,10,.1)
For(B,­10,10,.1)

e^(sin(A))+10^(cos(B))→C
If C≤2:Pt-On(A,B,1,MAGENTA)
If 2<C and C<5:Pt-On(A,B,1,BLUE)
If C≥5:Pt-On(A,B,1,LTBLUE)

End
End



Radian:FnOff 

ClrDraw:ZStandard
For(A,­10,10,.1)
For(B,­10,10,.1)

iPart(fPart(√(A^2+B^2)/4)*4)→C
If C=1:Pt-On(A,B,1,YELLOW)
If C=2:Pt-On(A,B,1,ORANGE)
If C=3:Pt-On(A,B,1,BROWN)

End
End


Radian:FnOff 
ClrDraw:ZStandard
For(A,­10,10,.1)
For(B,­10,10,.1)

If fPart(A*B/(π/2))≠0 and tan(A*B)<230
Then
e^(tan(A*B))→C
Else
e^(sin(A*B))→C
End
If C≤1:Pt-On(A,B,1,YELLOW)
If 1≤C and C≤2:Pt-On(A,B,1,GREEN)
If C>2:Pt-On(A,B,1,RED)

End
End


Radian:FnOff 
ClrDraw:ZStandard
For(A,­10,10,.1)
For(B,­10,10,.1)

iPart(A*B)/2→C
If fPart(C)=0
Then
sin(A*B)→D
Else
sin(A^3+B^3)→D
End
If D<­0.25:Pt-On(A,B,1,NAVY)
If D>0.25:Pt-On(A,B,1,MEDGRAY)

End
End



Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

Tuesday, February 6, 2018

HP Prime: Pixel Plot, How to Change Cartesian Coordinates to Pixels

HP Prime: Pixel Plot, How to Change Cartesian Coordinates to Pixels


Changing Cartesian Coordinates to Pixels

When running programs on the HP Prime, the screen has a pixel coordinate system of 320 x 220 (to allow room for soft menu keys). 



There are two ways to calculate to translate Cartesian coordinates to pixel coordinates on the HP Prime.  The easy way is to use the C→PX command. 

However, if you are working in custom made apps, C→PX may not work because the command requires that app has the Plot variables Xmin, Xmax, Ymin, and Ymax.  This will require a conversion formula.

Given a desired xmin, xmax, ymin, and ymax, the following formulas I use are:

Scaling: 
xs = (xmax – xmin)/320
ys = (ymax – ymin)/-220 = (ymin – ymax)/220

Conversion to pixels of coordinates (x,y):
xp = (x – xmin)/xs
yp = (y – ymax)/ys

HP Prime Program: PIXELPLOT

EXPORT PIXELPLOT()
BEGIN
// EWS 2014-02-04

LOCAL xm,ym,xp,yp,x,y;
LOCAL xn,yn,xs,ys;
LOCAL ya,ch,flag;
LOCAL fx;

// set color scheme
LOCAL col1,col2;
col1:={#BF00FFh,#7DF9FFh,
#00FF00h,#D4AF37h,#FF0000h};
col2:={#4B0082h,#000080h,
#228B22h,#C3B091h,#800000h};

// Radians
HAngle:=0;

INPUT({{fx,[2]},
xm,xn,ym,yn,
{ch,
{"Purple","Blue","Green",
"Gold","Red"}}},
"Pixel Plot Official",
{"f(x) string:",
"x-min: ","x-max: ",
"y-min: ","y-max: ",
"Color: "});

RECT_P(0);

// calulate the scale
xs:=(xn-xm)/320;
ys:=(yn-ym)/−220;

// drawing

// color choice
LOCAL c1,c2;
c1:=col1[ch];
c2:=col2[ch];

// axis information
LOCAL st1,st2;
st1:="x:["+xm+","+xn+"]";
st2:="y:["+ym+","+yn+"]";
TEXTOUT_P(st1,0,0,2,#C0C0C0h);
TEXTOUT_P(st2,0,20,2,#C0C0C0h);

// function
FOR x FROM xm TO xn STEP xs DO

// skip 0 for now
IF x==0 THEN
CONTINUE;
END;

// function
y:=EXPR(fx);

// point→pixel, plot
// only if y is real
IF TYPE(y)==0 THEN
xp:=(x-xm)/xs;
yp:=(y-yn)/ys;
PIXON_P(xp,yp,c1);
END;

END;

// freeze screen
FREEZE;

END;

Notes: 

1. You should not have to include the string characters for f(x) as they are included in the input.

2. Use the lowercase x.

3. The program errors if a plot reaches point where f(x) is not defined.  I put in a condition when f(x) is complex (for example, the square root of negative number) for the plot to skip that pixel.  However, I have not put error skipping conditions when it comes to ln(x) or 1/p(x) where p(x) is a polynomial.  However, the pixel at x=0 is skipped to hopefully alieve some problems.  Be sure your range is appropriate.

4. The program uses Radians angle mode (HAngle = 0).

5.  I chose to have a black background with five color options (purple, electric blue, green, gold, and red) just for fun. 

Examples

Example 1:  f(x) = 2.5*cos(x^2)



Example 2:  f(x) = √(x^2 – 6)



Example 3:  f(x) = e^(-x^2)



Eddie

This blog is property of Edward Shore, 2018.

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;

Sunday, January 25, 2015

HP Prime: Calculator Art

Programs will follow.  Enjoy!   Eddie  

DRAW3DCUBE:  3D Cube - not as easy as it seems.  
DRAW3DCUBE
DRAW3DCYN:  My first one I did this weekend.  This looks like a tall glass of water.


DRAW3DCYN
DRAW3DSPH:  Sphere.  I like the effect the HP Prime does with ARC in a FOR loop.


DRAW3DSPH

DRAW3DWAVE:  I wanted something to be drawn using a sine wave.  


DRAW3DWAVE

DRAWSUNSET - This is probably my favorite, since I like sunsets.  



DRAWSUNSET



Tip:  The HP Prime screen is 318 pixels wide and 240 pixels deep.  If you want to leave room for custom menus, then the canvas is 318 pixels by 218 pixels.  The x axis increases to the right, but unlike the Cartesian plane, the y axis increases downward instead of upward.  

Eddie

-------------
Programs:

DRAW3DCUBE

EXPORT DRAW3DCUBE()
BEGIN
LOCAL t,a,b,c,d,s;
RECT();
// coord
a:=159-50*COS(45°);
b:=109-50*SIN(45°);
c:=159+50*COS(45°)+1;
d:=159-50*SIN(45°);

// drawing
LINE_P(a+50*COS(45°),b-SIN(45°),a,b);
LINE_P(a,b,159,109);
LINE_P(159,109,c,b);
LINE_P(c,b,a+50*COS(45°),b-SIN(45°));

LINE_P(a,b,a,d);
LINE_P(a,d,159,159);
LINE_P(159,159,159,109);

LINE_P(159,159,c,d);
LINE_P(c,d,c,b);

// left/right side shade
FOR t FROM b TO d DO
LINE_P(a,t,159,t+50*SIN(45°),#FF0000h);
LINE_P(c,t,159,t+50*SIN(45°),#FFh);
END;

// top shade
FOR t FROM 1 TO 50 DO
LINE_P(a+t*COS(45°),b-t*SIN(45°),
a+t*COS(45°),b+t*SIN(45°),#FFFF00h);
END;

FOR t FROM 50 DOWNTO 1 DO
LINE_P(c-t*COS(45°),b-t*SIN(45°),
c-t*COS(45°),b+t*SIN(45°),#FFFF00h);
END;

WAIT(0);   // I prefer WAIT(0) to FREEZE;

END;

DRAW3DCYN

EXPORT DRAW3DCYN()
BEGIN
LOCAL t;
HAngle:=0;
RECT();
// cylinder shell
FOR t FROM 0 TO 100 STEP 1 DO

ARC_P(159,70+t,20,0,π,#7DF9FFh);

ARC_P(159,70+t,20,π,2*π,#1560BDh);
END;
// sides
LINE_P(139,70,139,170,#1560BDh);
LINE_P(179,70,179,170,#1560BDh);
ARC_P(159,70,20,0,2*π,#1560BDh);
WAIT(0);

END;



DRAW3DSPH

EXPORT DRAW3DSPH()
BEGIN
// 2015-01-22
LOCAL t;
RECT();

// sphere loop
FOR t FROM 100 DOWNTO 1 DO
ARC_P(159,109,t,0,2*π,#808080h);
END;

// outside
FOR t FROM 59 TO 259 DO
PIXON_P(t,−.0025*t^2+.795*t+70.975);
END;

WAIT(0);

END;

DRAW3DWAVE

EXPORT DRAW3DWAVE()
BEGIN
LOCAL t,a,b;
RECT();
HAngle:=0;

FOR t FROM 0 TO 318 DO
a:=25*SIN(3.95168887244ᴇ−2*t-π)+100;
b:=a+25;
PIXON_P(t,a,#FFh);
PIXON_P(t,b,#FFh);

LINE_P(t,a+1,t,b-1,#87CEEBh);
LINE_P(t,b+1,t,218,#964B00h);

END;

LINE_P(0,100,0,125,#FFh);
LINE_P(318,100,318,125,#FFh);

LINE_P(0,125,0,218,#D4AF37h);
LINE_P(318,125,318,218,#D4AF37h);
LINE_P(0,218,318,218,#D4AF37h);

WAIT(0);

END;



DRAWSUNSET

EXPORT DRAWSUNSET()
BEGIN

RECT(#87CEEBh);
LOCAL t,a,b;
HAngle:=0;

// sun
FOR t FROM 50 DOWNTO 40 DO
ARC_P(159,109,t,0,2*π,#FFA500h);
END;
FOR t FROM 40 DOWNTO 0 DO
ARC_P(159,109,t,0,2*π,#FFFF00h);
END;

// horizon
LINE_P(0,108,318,108);


// ground and water
FOR t FROM 0 TO 159 DO
a:=1.855525955687ᴇ−4*t^3
-5.05717802449ᴇ−2*t^2
+3.67070350319*t+109;
LINE_P(t,a,t,109,#80h);
LINE_P(t,a+1,t,242,#964B00h);
END;

FOR t FROM 159 TO 318 DO
a:=1.23858063728ᴇ−4*t^3
-9.61799073419ᴇ−2*t^2
+23.6382711212*t
-1664.83052851;
LINE_P(t,a,t,109,#80h);
LINE_P(t,a+1,t,242,#964B00h);
END;

// lines
LINE_P(120,111,188,111,#C0C0C0h);
LINE_P(125,113,183,113,#C0C0C0h);
LINE_P(130,115,178,115,#C0C0C0h);
LINE_P(135,117,173,117,#C0C0C0h);

WAIT(0);
END;


This blog is property of Edward Shore.  2015



Python in Numworks: Duplicating and Grayscale

Python in Numworks: Duplicating and Grayscale All three scripts presented today use the math, random, and the Numworks specific ...