I wrote a program to generate a gradient between two colors using Celtic's line drawing with 565 colors.

Code:
"|L1 and |L2 contain the two colors"
{0,0,255->|L1
{255,0,0->|L2
For(A,0,240
|L1+(|L2-|L1)*(A/240->|L3
L3(1->R
L3(2->G
L3(3->B
det(59,R,G,B
det(68,Ans,Theta,0,A,320
End
Repeat getKey
End


For anyone wanting to know how to convert RGB colors into High and Low for drawing purposes, Celtic provides: RGBto565: det(59, r, g, b)
Low btye is in Ans, high bye in Theta.

Here's a blue to green:


Here's a black to red:


Here's blue to red as per the code:
Here's that same program about twice as fast:

Code:
{22,63,0->L2
{15,57,31->L1
Ans/8->L1
L2/8-Ans->L2
For([recursiven],0,240
   L1+L2[recursiven]/240
   det(17,32int(8fPart(Ans(2)))+int(8Ans(3)),8int(8Ans(1))+int(Ans(2)),0,[recursiven],320,[recursiven]
End
Repeat getKey
End


Or alternatively:

Code:
{255,0,0->L2
{0,0,255->L1
L2-Ans->L2
For([recursiven],0,240
   L1+L2[recursiven]/240
   det(59,Ans(1),Ans(2),Ans(3
   det(68,Ans,Theta,0,[recursiven],320
End
Repeat getKey
End
Can someone test #FF0000 to #00FF00? I can't at the moment but it shouldn't blend with brown in the middle
I made a dynamic gradient generator that takes into account any number of randomly located, randomly colored points, and generates a full gradient between all of them.

Unfortunately, it’s obscenely slow so only bigger square sizes will actually generate in a reasonable amount of time.

Here are some example renders:



I only ever use 4 random points since that provides enough colors and doing more would take the program longer to render.

Some things to note is that M is the distance of influence, so the color of each pixel being drawn is affected by the distance from it to all other pre-generated points. If the distance is greater than M, then that point will have no effect on the current pixel. M is always calculated as the distance from one corner of the board to the other, and then multiplied by D, which by default is set to 0.5. Increasing D towards 1 will generate a smoother gradient.

I also implemented vividness, which seemed important since the true average of all points (multiplied by influence) ended up being relatively dark. A V of 4 or 5 tends to give a nice, bright image, although depending on what colors get randomly generated it could still be either dark or really bright / washed out.

Here’s the full code:

Code:
Input "Pixel Size:",S
Input "Num Points:",N
Input "Vividness:",V
.5->D
iPart(320/S->Q
iPart(240/S->F
Dsqrt(Q^^2+F^^2->M
5N->dim(L1
For([recursiven],0,N-1
   randInt(0,Q->L1(5[recursiven]+1
   randInt(0,F->L1(5[recursiven]+2
   randInt(0,255->L1(5[recursiven]+3
   randInt(0,255->L1(5[recursiven]+4
   randInt(0,255->L1(5[recursiven]+5
End
For(Y,0,F-1
   For(X,0,Q-1
      {0,0,0
      For([recursiven],0,N-1
         Ans+max(0,1-sqrt((X-L1(5[recursiven]+1))^^2+(Y-L1(5[recursiven]+2))^^2)/M)seq(L1(5[recursiven]+I),I,3,5
      End
      min(255,VAns/N
      det(59,Ans(1),Ans(2),Ans(3
      det(15,Ans,theta,SX,SY,S,S
   End
End
Pause
det(82
I was asked to post the code for this cycling rgb light I made, despite its relative simplicity. Enjoy!

Note that D is the step at which the color changes.

Here:
Code:
{255,0,0->L1
2->C:10->D
Repeat getKey
   det(59,L1(1),L1(2),L1(3
   det(16,Ans,theta
   min(255,max(0,D+L1(C->L1(C
   If Ans>254 or Ans<1:Then
      C-1+3(C=1->C
      ~D->D
   End
End
det(82

Ooh very nice! You should throw this on the first line
"CD480802C9":det(14
To disable the run indicator
Try this:

Code:
Input "Pixel Size:",S
Input "Num Points:",N
Input "Vividness:",V
N^^-1V->L
5N->N
iPart(320/S->Q
iPart(240/S->F
(.5sqrt(Q^^2+F^^2))^^-1->M
{0
For([recursiven],1,N,5
   augment(Ans,{randInt(0,Q),randInt(0,F
   augment(Ans,randInt(0,255,3
End
DeltaList(cumSum(Ans->L1
Q-1->Q
L1(1->|N
L1(2->I%
seq(L1(A),A,3,5->L2
For(Y,0,F-1
   (Y-I%)^^2->PV
   For(X,0,Q
      L2max(0,1-Msqrt((X-|N)^^2+PV
      For([recursiven],6,N,5
         Ans+seq(L1([recursiven]+I),I,2,4)max(0,1-Msqrt((X-L1([recursiven]))^^2+(Y-L1([recursiven]+1))^^2
      End
      min(255,LAns
      det(59,Ans(1),Ans(2),Ans(3
      det(15,Ans,theta,SX,SY,S,S
   End
End
Pause
det(82

Note that PV, I% and |N are finance vars

If we fix the number of points to 3 instead of letting the user enter a value, we can simplify everything dramatically and make it about twice as fast like this:

Code:
Input "Pixel Size:",S
Input "Vividness:",V
3^^-1V->L
iPart(320/S->Q
iPart(240/S->F
(.5sqrt(Q^^2+F^^2))^^-1->M
randInt(0,F->C
randInt(0,F->E
randInt(0,F->H
randInt(0,255,3->L4
randInt(0,255,3->L5
randInt(0,255,3->L6
~1+cumSum(binomcdf(Q-1,0->L1
(Ans-randInt(0,Q))^^2->|LB
(L1-randInt(0,Q))^^2->|LC
(L1-randInt(0,Q))^^2->|LD
Q-1->Q
For(Y,0,F-1
   max(0,1-Msqrt(|LB+(Y-H)^^2->L2
   max(0,1-Msqrt(|LC+(Y-E)^^2->L3
   max(0,1-Msqrt(|LD+(Y-C)^^2->L1
   For([recursiven],0,Q
      min(255,L(L4L1([recursiven]+1)+L5L3([recursiven]+1)+L6L2([recursiven]+1
      det(59,Ans(1),Ans(2),Ans(3
      det(15,Ans,theta,S[recursiven],SY,S,S
   End
End
Pause
det(82
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement